Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM HTMLTrackElement.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "HTMLElementBinding.h"
4 : #include "HTMLTrackElementBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/OwningNonNull.h"
7 : #include "mozilla/dom/BindingUtils.h"
8 : #include "mozilla/dom/CustomElementRegistry.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/HTMLTrackElement.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/Nullable.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/TextTrack.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : namespace HTMLTrackElementBinding {
21 :
22 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElementBinding::NativeType>::value,
23 : "Can't inherit from an interface with a different ownership model.");
24 :
25 : static bool
26 0 : get_kind(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
27 : {
28 0 : DOMString result;
29 0 : self->GetKind(result);
30 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
31 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
32 0 : return false;
33 : }
34 0 : return true;
35 : }
36 :
37 : static bool
38 0 : set_kind(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitSetterCallArgs args)
39 : {
40 0 : binding_detail::FakeString arg0;
41 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
42 0 : return false;
43 : }
44 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
45 0 : Maybe<AutoCEReaction> ceReaction;
46 0 : if (reactionsStack) {
47 0 : ceReaction.emplace(reactionsStack);
48 : }
49 0 : binding_detail::FastErrorResult rv;
50 0 : self->SetKind(NonNullHelper(Constify(arg0)), rv);
51 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
52 0 : return false;
53 : }
54 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
55 :
56 0 : return true;
57 : }
58 :
59 : static const JSJitInfo kind_getterinfo = {
60 : { (JSJitGetterOp)get_kind },
61 : { prototypes::id::HTMLTrackElement },
62 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
63 : JSJitInfo::Getter,
64 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
65 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
66 : false, /* isInfallible. False in setters. */
67 : true, /* isMovable. Not relevant for setters. */
68 : true, /* isEliminatable. Not relevant for setters. */
69 : false, /* isAlwaysInSlot. Only relevant for getters. */
70 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
71 : false, /* isTypedMethod. Only relevant for methods. */
72 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
73 : };
74 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
75 : static_assert(0 < 1, "There is no slot for us");
76 : static const JSJitInfo kind_setterinfo = {
77 : { (JSJitGetterOp)set_kind },
78 : { prototypes::id::HTMLTrackElement },
79 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
80 : JSJitInfo::Setter,
81 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
82 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
83 : false, /* isInfallible. False in setters. */
84 : false, /* isMovable. Not relevant for setters. */
85 : false, /* isEliminatable. Not relevant for setters. */
86 : false, /* isAlwaysInSlot. Only relevant for getters. */
87 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
88 : false, /* isTypedMethod. Only relevant for methods. */
89 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
90 : };
91 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
92 : static_assert(0 < 1, "There is no slot for us");
93 :
94 : static bool
95 0 : get_src(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
96 : {
97 0 : DOMString result;
98 0 : self->GetSrc(result);
99 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
100 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
101 0 : return false;
102 : }
103 0 : return true;
104 : }
105 :
106 : static bool
107 0 : set_src(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitSetterCallArgs args)
108 : {
109 0 : binding_detail::FakeString arg0;
110 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
111 0 : return false;
112 : }
113 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
114 0 : Maybe<AutoCEReaction> ceReaction;
115 0 : if (reactionsStack) {
116 0 : ceReaction.emplace(reactionsStack);
117 : }
118 0 : binding_detail::FastErrorResult rv;
119 0 : self->SetSrc(NonNullHelper(Constify(arg0)), rv);
120 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
121 0 : return false;
122 : }
123 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
124 :
125 0 : return true;
126 : }
127 :
128 : static const JSJitInfo src_getterinfo = {
129 : { (JSJitGetterOp)get_src },
130 : { prototypes::id::HTMLTrackElement },
131 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
132 : JSJitInfo::Getter,
133 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
134 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
135 : false, /* isInfallible. False in setters. */
136 : true, /* isMovable. Not relevant for setters. */
137 : true, /* isEliminatable. Not relevant for setters. */
138 : false, /* isAlwaysInSlot. Only relevant for getters. */
139 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
140 : false, /* isTypedMethod. Only relevant for methods. */
141 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
142 : };
143 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
144 : static_assert(0 < 1, "There is no slot for us");
145 : static const JSJitInfo src_setterinfo = {
146 : { (JSJitGetterOp)set_src },
147 : { prototypes::id::HTMLTrackElement },
148 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
149 : JSJitInfo::Setter,
150 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
151 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
152 : false, /* isInfallible. False in setters. */
153 : false, /* isMovable. Not relevant for setters. */
154 : false, /* isEliminatable. Not relevant for setters. */
155 : false, /* isAlwaysInSlot. Only relevant for getters. */
156 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
157 : false, /* isTypedMethod. Only relevant for methods. */
158 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
159 : };
160 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
161 : static_assert(0 < 1, "There is no slot for us");
162 :
163 : static bool
164 0 : get_srclang(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
165 : {
166 0 : DOMString result;
167 0 : self->GetSrclang(result);
168 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
169 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
170 0 : return false;
171 : }
172 0 : return true;
173 : }
174 :
175 : static bool
176 0 : set_srclang(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitSetterCallArgs args)
177 : {
178 0 : binding_detail::FakeString arg0;
179 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
180 0 : return false;
181 : }
182 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
183 0 : Maybe<AutoCEReaction> ceReaction;
184 0 : if (reactionsStack) {
185 0 : ceReaction.emplace(reactionsStack);
186 : }
187 0 : binding_detail::FastErrorResult rv;
188 0 : self->SetSrclang(NonNullHelper(Constify(arg0)), rv);
189 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
190 0 : return false;
191 : }
192 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
193 :
194 0 : return true;
195 : }
196 :
197 : static const JSJitInfo srclang_getterinfo = {
198 : { (JSJitGetterOp)get_srclang },
199 : { prototypes::id::HTMLTrackElement },
200 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
201 : JSJitInfo::Getter,
202 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
203 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
204 : false, /* isInfallible. False in setters. */
205 : true, /* isMovable. Not relevant for setters. */
206 : true, /* isEliminatable. Not relevant for setters. */
207 : false, /* isAlwaysInSlot. Only relevant for getters. */
208 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
209 : false, /* isTypedMethod. Only relevant for methods. */
210 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
211 : };
212 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
213 : static_assert(0 < 1, "There is no slot for us");
214 : static const JSJitInfo srclang_setterinfo = {
215 : { (JSJitGetterOp)set_srclang },
216 : { prototypes::id::HTMLTrackElement },
217 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
218 : JSJitInfo::Setter,
219 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
220 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
221 : false, /* isInfallible. False in setters. */
222 : false, /* isMovable. Not relevant for setters. */
223 : false, /* isEliminatable. Not relevant for setters. */
224 : false, /* isAlwaysInSlot. Only relevant for getters. */
225 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
226 : false, /* isTypedMethod. Only relevant for methods. */
227 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
228 : };
229 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
230 : static_assert(0 < 1, "There is no slot for us");
231 :
232 : static bool
233 0 : get_label(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
234 : {
235 0 : DOMString result;
236 0 : self->GetLabel(result);
237 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
238 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
239 0 : return false;
240 : }
241 0 : return true;
242 : }
243 :
244 : static bool
245 0 : set_label(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitSetterCallArgs args)
246 : {
247 0 : binding_detail::FakeString arg0;
248 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
249 0 : return false;
250 : }
251 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
252 0 : Maybe<AutoCEReaction> ceReaction;
253 0 : if (reactionsStack) {
254 0 : ceReaction.emplace(reactionsStack);
255 : }
256 0 : binding_detail::FastErrorResult rv;
257 0 : self->SetLabel(NonNullHelper(Constify(arg0)), rv);
258 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
259 0 : return false;
260 : }
261 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
262 :
263 0 : return true;
264 : }
265 :
266 : static const JSJitInfo label_getterinfo = {
267 : { (JSJitGetterOp)get_label },
268 : { prototypes::id::HTMLTrackElement },
269 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
270 : JSJitInfo::Getter,
271 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
272 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
273 : false, /* isInfallible. False in setters. */
274 : true, /* isMovable. Not relevant for setters. */
275 : true, /* isEliminatable. Not relevant for setters. */
276 : false, /* isAlwaysInSlot. Only relevant for getters. */
277 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
278 : false, /* isTypedMethod. Only relevant for methods. */
279 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
280 : };
281 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
282 : static_assert(0 < 1, "There is no slot for us");
283 : static const JSJitInfo label_setterinfo = {
284 : { (JSJitGetterOp)set_label },
285 : { prototypes::id::HTMLTrackElement },
286 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
287 : JSJitInfo::Setter,
288 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
289 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
290 : false, /* isInfallible. False in setters. */
291 : false, /* isMovable. Not relevant for setters. */
292 : false, /* isEliminatable. Not relevant for setters. */
293 : false, /* isAlwaysInSlot. Only relevant for getters. */
294 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
295 : false, /* isTypedMethod. Only relevant for methods. */
296 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
297 : };
298 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
299 : static_assert(0 < 1, "There is no slot for us");
300 :
301 : static bool
302 0 : get_default(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
303 : {
304 0 : bool result(self->Default());
305 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
306 0 : args.rval().setBoolean(result);
307 0 : return true;
308 : }
309 :
310 : static bool
311 0 : set_default(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitSetterCallArgs args)
312 : {
313 : bool arg0;
314 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
315 0 : return false;
316 : }
317 0 : CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(obj);
318 0 : Maybe<AutoCEReaction> ceReaction;
319 0 : if (reactionsStack) {
320 0 : ceReaction.emplace(reactionsStack);
321 : }
322 0 : binding_detail::FastErrorResult rv;
323 0 : self->SetDefault(arg0, rv);
324 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
325 0 : return false;
326 : }
327 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
328 :
329 0 : return true;
330 : }
331 :
332 : static const JSJitInfo default_getterinfo = {
333 : { (JSJitGetterOp)get_default },
334 : { prototypes::id::HTMLTrackElement },
335 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
336 : JSJitInfo::Getter,
337 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
338 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
339 : true, /* isInfallible. False in setters. */
340 : true, /* isMovable. Not relevant for setters. */
341 : true, /* isEliminatable. Not relevant for setters. */
342 : false, /* isAlwaysInSlot. Only relevant for getters. */
343 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
344 : false, /* isTypedMethod. Only relevant for methods. */
345 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
346 : };
347 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
348 : static_assert(0 < 1, "There is no slot for us");
349 : static const JSJitInfo default_setterinfo = {
350 : { (JSJitGetterOp)set_default },
351 : { prototypes::id::HTMLTrackElement },
352 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
353 : JSJitInfo::Setter,
354 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
355 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
356 : false, /* isInfallible. False in setters. */
357 : false, /* isMovable. Not relevant for setters. */
358 : false, /* isEliminatable. Not relevant for setters. */
359 : false, /* isAlwaysInSlot. Only relevant for getters. */
360 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
361 : false, /* isTypedMethod. Only relevant for methods. */
362 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
363 : };
364 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
365 : static_assert(0 < 1, "There is no slot for us");
366 :
367 : static bool
368 0 : get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
369 : {
370 0 : uint16_t result(self->ReadyState());
371 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
372 0 : args.rval().setInt32(int32_t(result));
373 0 : return true;
374 : }
375 :
376 : static const JSJitInfo readyState_getterinfo = {
377 : { (JSJitGetterOp)get_readyState },
378 : { prototypes::id::HTMLTrackElement },
379 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
380 : JSJitInfo::Getter,
381 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
382 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
383 : true, /* isInfallible. False in setters. */
384 : false, /* isMovable. Not relevant for setters. */
385 : false, /* isEliminatable. Not relevant for setters. */
386 : false, /* isAlwaysInSlot. Only relevant for getters. */
387 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
388 : false, /* isTypedMethod. Only relevant for methods. */
389 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
390 : };
391 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
392 : static_assert(0 < 1, "There is no slot for us");
393 :
394 : static bool
395 0 : get_track(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLTrackElement* self, JSJitGetterCallArgs args)
396 : {
397 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrack>(self->GetTrack()));
398 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
399 0 : if (!result) {
400 0 : args.rval().setNull();
401 0 : return true;
402 : }
403 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
404 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
405 0 : return false;
406 : }
407 0 : return true;
408 : }
409 :
410 : static const JSJitInfo track_getterinfo = {
411 : { (JSJitGetterOp)get_track },
412 : { prototypes::id::HTMLTrackElement },
413 : { PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth },
414 : JSJitInfo::Getter,
415 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
416 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
417 : false, /* isInfallible. False in setters. */
418 : false, /* isMovable. Not relevant for setters. */
419 : false, /* isEliminatable. Not relevant for setters. */
420 : false, /* isAlwaysInSlot. Only relevant for getters. */
421 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
422 : false, /* isTypedMethod. Only relevant for methods. */
423 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
424 : };
425 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
426 : static_assert(0 < 1, "There is no slot for us");
427 :
428 : static bool
429 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
430 : {
431 0 : mozilla::dom::HTMLTrackElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLTrackElement>(obj);
432 : // We don't want to preserve if we don't have a wrapper, and we
433 : // obviously can't preserve if we're not initialized.
434 0 : if (self && self->GetWrapperPreserveColor()) {
435 0 : PreserveWrapper(self);
436 : }
437 0 : return true;
438 : }
439 :
440 : static void
441 0 : _finalize(js::FreeOp* fop, JSObject* obj)
442 : {
443 0 : mozilla::dom::HTMLTrackElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLTrackElement>(obj);
444 0 : if (self) {
445 0 : ClearWrapper(self, self, obj);
446 0 : AddForDeferredFinalization<mozilla::dom::HTMLTrackElement>(self);
447 : }
448 0 : }
449 :
450 : static void
451 0 : _objectMoved(JSObject* obj, const JSObject* old)
452 : {
453 0 : mozilla::dom::HTMLTrackElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLTrackElement>(obj);
454 0 : if (self) {
455 0 : UpdateWrapper(self, self, obj, old);
456 : }
457 0 : }
458 :
459 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
460 : #if defined(__clang__)
461 : #pragma clang diagnostic push
462 : #pragma clang diagnostic ignored "-Wmissing-braces"
463 : #endif
464 : static const JSPropertySpec sAttributes_specs[] = {
465 : { "kind", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &kind_getterinfo, GenericBindingSetter, &kind_setterinfo },
466 : { "src", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &src_getterinfo, GenericBindingSetter, &src_setterinfo },
467 : { "srclang", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &srclang_getterinfo, GenericBindingSetter, &srclang_setterinfo },
468 : { "label", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &label_getterinfo, GenericBindingSetter, &label_setterinfo },
469 : { "default", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &default_getterinfo, GenericBindingSetter, &default_setterinfo },
470 : { "readyState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &readyState_getterinfo, nullptr, nullptr },
471 : { "track", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &track_getterinfo, nullptr, nullptr },
472 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
473 : };
474 : #if defined(__clang__)
475 : #pragma clang diagnostic pop
476 : #endif
477 :
478 :
479 : // Can't be const because the pref-enabled boolean needs to be writable
480 : static Prefable<const JSPropertySpec> sAttributes[] = {
481 : { nullptr, &sAttributes_specs[0] },
482 : { nullptr, nullptr }
483 : };
484 :
485 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
486 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
487 : static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
488 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
489 :
490 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
491 : #if defined(__clang__)
492 : #pragma clang diagnostic push
493 : #pragma clang diagnostic ignored "-Wmissing-braces"
494 : #endif
495 : static const ConstantSpec sConstants_specs[] = {
496 : { "NONE", JS::Int32Value(0) },
497 : { "LOADING", JS::Int32Value(1) },
498 : { "LOADED", JS::Int32Value(2) },
499 : { "ERROR", JS::Int32Value(3) },
500 : { 0, JS::UndefinedValue() }
501 : };
502 : #if defined(__clang__)
503 : #pragma clang diagnostic pop
504 : #endif
505 :
506 :
507 : // Can't be const because the pref-enabled boolean needs to be writable
508 : static Prefable<const ConstantSpec> sConstants[] = {
509 : { nullptr, &sConstants_specs[0] },
510 : { nullptr, nullptr }
511 : };
512 :
513 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
514 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
515 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
516 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
517 :
518 :
519 : static uint16_t sNativeProperties_sortedPropertyIndices[11];
520 : static PropertyInfo sNativeProperties_propertyInfos[11];
521 :
522 : static const NativePropertiesN<2> sNativeProperties = {
523 : false, 0,
524 : false, 0,
525 : false, 0,
526 : true, 0 /* sAttributes */,
527 : false, 0,
528 : false, 0,
529 : true, 1 /* sConstants */,
530 : -1,
531 : 11,
532 : sNativeProperties_sortedPropertyIndices,
533 : {
534 : { sAttributes, &sNativeProperties_propertyInfos[0] },
535 : { sConstants, &sNativeProperties_propertyInfos[7] }
536 : }
537 : };
538 : static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
539 : "We have a property info count that is oversized");
540 :
541 : static bool
542 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
543 : {
544 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
545 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
546 0 : if (!args.isConstructing()) {
547 : // XXXbz wish I could get the name from the callee instead of
548 : // Adding more relocations
549 0 : return ThrowConstructorWithoutNew(cx, "HTMLTrackElement");
550 : }
551 :
552 0 : GlobalObject global(cx, obj);
553 0 : if (global.Failed()) {
554 0 : return false;
555 : }
556 :
557 : // The newTarget might be a cross-compartment wrapper. Get the underlying object
558 : // so we can do the spec's object-identity checks.
559 0 : JS::Rooted<JSObject*> newTarget(cx, js::CheckedUnwrap(&args.newTarget().toObject()));
560 0 : if (!newTarget) {
561 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
562 : }
563 :
564 : // Step 2 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
565 : // Enter the compartment of our underlying newTarget object, so we end
566 : // up comparing to the constructor object for our interface from that global.
567 : {
568 0 : JSAutoCompartment ac(cx, newTarget);
569 0 : JS::Handle<JSObject*> constructor(GetConstructorObjectHandle(cx));
570 0 : if (!constructor) {
571 0 : return false;
572 : }
573 0 : if (newTarget == constructor) {
574 0 : return ThrowErrorMessage(cx, MSG_ILLEGAL_CONSTRUCTOR);
575 : }
576 : }
577 :
578 0 : JS::Rooted<JSObject*> desiredProto(cx);
579 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
580 0 : return false;
581 : }
582 0 : if (!desiredProto) {
583 : // Step 7 of https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor.
584 : // This fallback behavior is designed to match analogous behavior for the
585 : // JavaScript built-ins. So we enter the compartment of our underlying
586 : // newTarget object and fall back to the prototype object from that global.
587 : // XXX The spec says to use GetFunctionRealm(), which is not actually
588 : // the same thing as what we have here (e.g. in the case of scripted callable proxies
589 : // whose target is not same-compartment with the proxy, or bound functions, etc).
590 : // https://bugzilla.mozilla.org/show_bug.cgi?id=1317658
591 : {
592 0 : JSAutoCompartment ac(cx, newTarget);
593 0 : desiredProto = GetProtoObjectHandle(cx);
594 0 : if (!desiredProto) {
595 0 : return false;
596 : }
597 : }
598 :
599 : // desiredProto is in the compartment of the underlying newTarget object.
600 : // Wrap it into the context compartment.
601 0 : if (!JS_WrapObject(cx, &desiredProto)) {
602 0 : return false;
603 : }
604 : }
605 :
606 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
607 0 : Maybe<JSAutoCompartment> ac;
608 0 : if (objIsXray) {
609 0 : obj = js::CheckedUnwrap(obj);
610 0 : if (!obj) {
611 0 : return false;
612 : }
613 0 : ac.emplace(cx, obj);
614 0 : if (!JS_WrapObject(cx, &desiredProto)) {
615 0 : return false;
616 : }
617 : }
618 0 : binding_detail::FastErrorResult rv;
619 0 : auto result(StrongOrRawPtr<mozilla::dom::HTMLTrackElement>(CreateHTMLElement(global, args, rv)));
620 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
621 0 : return false;
622 : }
623 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
624 : static_assert(!IsPointer<decltype(result)>::value,
625 : "NewObject implies that we need to keep the object alive with a strong reference.");
626 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
627 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
628 0 : return false;
629 : }
630 0 : return true;
631 : }
632 :
633 : static const js::ClassOps sInterfaceObjectClassOps = {
634 : nullptr, /* addProperty */
635 : nullptr, /* delProperty */
636 : nullptr, /* getProperty */
637 : nullptr, /* setProperty */
638 : nullptr, /* enumerate */
639 : nullptr, /* newEnumerate */
640 : nullptr, /* resolve */
641 : nullptr, /* mayResolve */
642 : nullptr, /* finalize */
643 : _constructor, /* call */
644 : nullptr, /* hasInstance */
645 : _constructor, /* construct */
646 : nullptr, /* trace */
647 : };
648 :
649 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
650 : {
651 : "Function",
652 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
653 : &sInterfaceObjectClassOps,
654 : JS_NULL_CLASS_SPEC,
655 : JS_NULL_CLASS_EXT,
656 : &sInterfaceObjectClassObjectOps
657 : },
658 : eInterface,
659 : true,
660 : prototypes::id::HTMLTrackElement,
661 : PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth,
662 : sNativePropertyHooks,
663 : "function HTMLTrackElement() {\n [native code]\n}",
664 : HTMLElementBinding::GetConstructorObject
665 : };
666 :
667 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
668 : {
669 : "HTMLTrackElementPrototype",
670 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
671 : JS_NULL_CLASS_OPS,
672 : JS_NULL_CLASS_SPEC,
673 : JS_NULL_CLASS_EXT,
674 : JS_NULL_OBJECT_OPS
675 : },
676 : eInterfacePrototype,
677 : false,
678 : prototypes::id::HTMLTrackElement,
679 : PrototypeTraits<prototypes::id::HTMLTrackElement>::Depth,
680 : sNativePropertyHooks,
681 : "[object HTMLTrackElementPrototype]",
682 : HTMLElementBinding::GetProtoObject
683 : };
684 :
685 : JSObject*
686 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
687 : {
688 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
689 : }
690 :
691 : static const js::ClassOps sClassOps = {
692 : _addProperty, /* addProperty */
693 : nullptr, /* delProperty */
694 : nullptr, /* getProperty */
695 : nullptr, /* setProperty */
696 : nullptr, /* enumerate */
697 : nullptr, /* newEnumerate */
698 : nullptr, /* resolve */
699 : nullptr, /* mayResolve */
700 : _finalize, /* finalize */
701 : nullptr, /* call */
702 : nullptr, /* hasInstance */
703 : nullptr, /* construct */
704 : nullptr, /* trace */
705 : };
706 :
707 : static const js::ClassExtension sClassExtension = {
708 : nullptr, /* weakmapKeyDelegateOp */
709 : _objectMoved /* objectMovedOp */
710 : };
711 :
712 : static const DOMJSClass sClass = {
713 : { "HTMLTrackElement",
714 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
715 : &sClassOps,
716 : JS_NULL_CLASS_SPEC,
717 : &sClassExtension,
718 : JS_NULL_OBJECT_OPS
719 : },
720 : { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLTrackElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
721 : IsBaseOf<nsISupports, mozilla::dom::HTMLTrackElement >::value,
722 : sNativePropertyHooks,
723 : FindAssociatedGlobalForNative<mozilla::dom::HTMLTrackElement>::Get,
724 : GetProtoObjectHandle,
725 : GetCCParticipant<mozilla::dom::HTMLTrackElement>::Get()
726 : };
727 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
728 : "Must have the right minimal number of reserved slots.");
729 : static_assert(1 >= 1,
730 : "Must have enough reserved slots.");
731 :
732 : const JSClass*
733 0 : GetJSClass()
734 : {
735 0 : return sClass.ToJSClass();
736 : }
737 :
738 : bool
739 0 : Wrap(JSContext* aCx, mozilla::dom::HTMLTrackElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
740 : {
741 : MOZ_ASSERT(static_cast<mozilla::dom::HTMLTrackElement*>(aObject) ==
742 : reinterpret_cast<mozilla::dom::HTMLTrackElement*>(aObject),
743 : "Multiple inheritance for mozilla::dom::HTMLTrackElement is broken.");
744 : MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
745 : reinterpret_cast<nsGenericHTMLElement*>(aObject),
746 : "Multiple inheritance for nsGenericHTMLElement is broken.");
747 : MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
748 : reinterpret_cast<mozilla::dom::Element*>(aObject),
749 : "Multiple inheritance for mozilla::dom::Element is broken.");
750 : MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
751 : reinterpret_cast<nsINode*>(aObject),
752 : "Multiple inheritance for nsINode is broken.");
753 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
754 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
755 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
756 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
757 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
758 0 : MOZ_ASSERT(!aCache->GetWrapper(),
759 : "You should probably not be using Wrap() directly; use "
760 : "GetOrCreateDOMReflector instead");
761 :
762 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
763 : "nsISupports must be on our primary inheritance chain");
764 :
765 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
766 0 : if (!global) {
767 0 : return false;
768 : }
769 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
770 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
771 :
772 : // That might have ended up wrapping us already, due to the wonders
773 : // of XBL. Check for that, and bail out as needed.
774 0 : aReflector.set(aCache->GetWrapper());
775 0 : if (aReflector) {
776 : #ifdef DEBUG
777 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
778 : #endif // DEBUG
779 0 : return true;
780 : }
781 :
782 0 : JSAutoCompartment ac(aCx, global);
783 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
784 0 : if (!canonicalProto) {
785 0 : return false;
786 : }
787 0 : JS::Rooted<JSObject*> proto(aCx);
788 0 : if (aGivenProto) {
789 0 : proto = aGivenProto;
790 : // Unfortunately, while aGivenProto was in the compartment of aCx
791 : // coming in, we changed compartments to that of "parent" so may need
792 : // to wrap the proto here.
793 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
794 0 : if (!JS_WrapObject(aCx, &proto)) {
795 0 : return false;
796 : }
797 : }
798 : } else {
799 0 : proto = canonicalProto;
800 : }
801 :
802 0 : BindingJSObjectCreator<mozilla::dom::HTMLTrackElement> creator(aCx);
803 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
804 0 : if (!aReflector) {
805 0 : return false;
806 : }
807 :
808 0 : aCache->SetWrapper(aReflector);
809 0 : creator.InitializationSucceeded();
810 :
811 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
812 : aCache->GetWrapperPreserveColor() == aReflector);
813 : // If proto != canonicalProto, we have to preserve our wrapper;
814 : // otherwise we won't be able to properly recreate it later, since
815 : // we won't know what proto to use. Note that we don't check
816 : // aGivenProto here, since it's entirely possible (and even
817 : // somewhat common) to have a non-null aGivenProto which is the
818 : // same as canonicalProto.
819 0 : if (proto != canonicalProto) {
820 0 : PreserveWrapper(aObject);
821 : }
822 :
823 0 : return true;
824 : }
825 :
826 : const NativePropertyHooks sNativePropertyHooks[] = { {
827 : nullptr,
828 : nullptr,
829 : nullptr,
830 : { sNativeProperties.Upcast(), nullptr },
831 : prototypes::id::HTMLTrackElement,
832 : constructors::id::HTMLTrackElement,
833 : HTMLElementBinding::sNativePropertyHooks,
834 : &DefaultXrayExpandoObjectClass
835 : } };
836 :
837 : void
838 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
839 : {
840 0 : JS::Handle<JSObject*> parentProto(HTMLElementBinding::GetProtoObjectHandle(aCx));
841 0 : if (!parentProto) {
842 0 : return;
843 : }
844 :
845 0 : JS::Handle<JSObject*> constructorProto(HTMLElementBinding::GetConstructorObjectHandle(aCx));
846 0 : if (!constructorProto) {
847 0 : return;
848 : }
849 :
850 : static bool sIdsInited = false;
851 0 : if (!sIdsInited && NS_IsMainThread()) {
852 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
853 0 : return;
854 : }
855 0 : sIdsInited = true;
856 : }
857 :
858 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLTrackElement);
859 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLTrackElement);
860 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
861 : &sPrototypeClass.mBase, protoCache,
862 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
863 : interfaceCache,
864 : sNativeProperties.Upcast(),
865 : nullptr,
866 : "HTMLTrackElement", aDefineOnGlobal,
867 : nullptr,
868 0 : false);
869 : }
870 :
871 : JS::Handle<JSObject*>
872 0 : GetProtoObjectHandle(JSContext* aCx)
873 : {
874 : /* Get the interface prototype object for this class. This will create the
875 : object as needed. */
876 0 : bool aDefineOnGlobal = true;
877 :
878 : /* Make sure our global is sane. Hopefully we can remove this sometime */
879 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
880 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
881 0 : return nullptr;
882 : }
883 :
884 : /* Check to see whether the interface objects are already installed */
885 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
886 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::HTMLTrackElement)) {
887 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
888 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
889 : }
890 :
891 : /*
892 : * The object might _still_ be null, but that's OK.
893 : *
894 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
895 : * traced by TraceProtoAndIfaceCache() and its contents are never
896 : * changed after they have been set.
897 : *
898 : * Calling address() avoids the read read barrier that does gray
899 : * unmarking, but it's not possible for the object to be gray here.
900 : */
901 :
902 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::HTMLTrackElement);
903 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
904 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
905 : }
906 :
907 : JS::Handle<JSObject*>
908 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
909 : {
910 : /* Get the interface object for this class. This will create the object as
911 : needed. */
912 :
913 : /* Make sure our global is sane. Hopefully we can remove this sometime */
914 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
915 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
916 0 : return nullptr;
917 : }
918 :
919 : /* Check to see whether the interface objects are already installed */
920 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
921 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::HTMLTrackElement)) {
922 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
923 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
924 : }
925 :
926 : /*
927 : * The object might _still_ be null, but that's OK.
928 : *
929 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
930 : * traced by TraceProtoAndIfaceCache() and its contents are never
931 : * changed after they have been set.
932 : *
933 : * Calling address() avoids the read read barrier that does gray
934 : * unmarking, but it's not possible for the object to be gray here.
935 : */
936 :
937 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::HTMLTrackElement);
938 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
939 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
940 : }
941 :
942 : JSObject*
943 0 : GetConstructorObject(JSContext* aCx)
944 : {
945 0 : return GetConstructorObjectHandle(aCx);
946 : }
947 :
948 : } // namespace HTMLTrackElementBinding
949 :
950 :
951 :
952 : } // namespace dom
953 : } // namespace mozilla
|