Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM TextTrackCueList.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "TextTrackCueListBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/DOMJSClass.h"
8 : #include "mozilla/dom/DOMJSProxyHandler.h"
9 : #include "mozilla/dom/NonRefcountedDOMObject.h"
10 : #include "mozilla/dom/Nullable.h"
11 : #include "mozilla/dom/PrimitiveConversions.h"
12 : #include "mozilla/dom/TextTrackCue.h"
13 : #include "mozilla/dom/TextTrackCueList.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : namespace TextTrackCueListBinding {
20 :
21 : static bool
22 0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TextTrackCueList* self, JSJitGetterCallArgs args)
23 : {
24 0 : uint32_t result(self->Length());
25 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
26 0 : args.rval().setNumber(result);
27 0 : return true;
28 : }
29 :
30 : static const JSJitInfo length_getterinfo = {
31 : { (JSJitGetterOp)get_length },
32 : { prototypes::id::TextTrackCueList },
33 : { PrototypeTraits<prototypes::id::TextTrackCueList>::Depth },
34 : JSJitInfo::Getter,
35 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
36 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
37 : true, /* isInfallible. False in setters. */
38 : false, /* isMovable. Not relevant for setters. */
39 : false, /* isEliminatable. Not relevant for setters. */
40 : false, /* isAlwaysInSlot. Only relevant for getters. */
41 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
42 : false, /* isTypedMethod. Only relevant for methods. */
43 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
44 : };
45 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
46 : static_assert(0 < 1, "There is no slot for us");
47 :
48 : static bool
49 0 : getCueById(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TextTrackCueList* self, const JSJitMethodCallArgs& args)
50 : {
51 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
52 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TextTrackCueList.getCueById");
53 : }
54 0 : binding_detail::FakeString arg0;
55 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
56 0 : return false;
57 : }
58 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrackCue>(self->GetCueById(NonNullHelper(Constify(arg0)))));
59 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
60 0 : if (!result) {
61 0 : args.rval().setNull();
62 0 : return true;
63 : }
64 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
65 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
66 0 : return false;
67 : }
68 0 : return true;
69 : }
70 :
71 : static const JSJitInfo getCueById_methodinfo = {
72 : { (JSJitGetterOp)getCueById },
73 : { prototypes::id::TextTrackCueList },
74 : { PrototypeTraits<prototypes::id::TextTrackCueList>::Depth },
75 : JSJitInfo::Method,
76 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
77 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
78 : false, /* isInfallible. False in setters. */
79 : false, /* isMovable. Not relevant for setters. */
80 : false, /* isEliminatable. Not relevant for setters. */
81 : false, /* isAlwaysInSlot. Only relevant for getters. */
82 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
83 : false, /* isTypedMethod. Only relevant for methods. */
84 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
85 : };
86 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
87 : static_assert(0 < 1, "There is no slot for us");
88 :
89 : static void
90 0 : _objectMoved(JSObject* obj, const JSObject* old)
91 : {
92 0 : mozilla::dom::TextTrackCueList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TextTrackCueList>(obj);
93 0 : if (self) {
94 0 : UpdateWrapper(self, self, obj, old);
95 : }
96 0 : }
97 :
98 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
99 : #if defined(__clang__)
100 : #pragma clang diagnostic push
101 : #pragma clang diagnostic ignored "-Wmissing-braces"
102 : #endif
103 : static const JSFunctionSpec sMethods_specs[] = {
104 : JS_FNSPEC("getCueById", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getCueById_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
105 : JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
106 : JS_FS_END
107 : };
108 : #if defined(__clang__)
109 : #pragma clang diagnostic pop
110 : #endif
111 :
112 :
113 : // Can't be const because the pref-enabled boolean needs to be writable
114 : static Prefable<const JSFunctionSpec> sMethods[] = {
115 : { nullptr, &sMethods_specs[0] },
116 : { nullptr, nullptr }
117 : };
118 :
119 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
120 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
121 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
122 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
123 :
124 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
125 : #if defined(__clang__)
126 : #pragma clang diagnostic push
127 : #pragma clang diagnostic ignored "-Wmissing-braces"
128 : #endif
129 : static const JSPropertySpec sAttributes_specs[] = {
130 : { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
131 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
132 : };
133 : #if defined(__clang__)
134 : #pragma clang diagnostic pop
135 : #endif
136 :
137 :
138 : // Can't be const because the pref-enabled boolean needs to be writable
139 : static Prefable<const JSPropertySpec> sAttributes[] = {
140 : { nullptr, &sAttributes_specs[0] },
141 : { nullptr, nullptr }
142 : };
143 :
144 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
145 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
146 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
147 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
148 :
149 :
150 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
151 : static PropertyInfo sNativeProperties_propertyInfos[3];
152 :
153 : static const NativePropertiesN<2> sNativeProperties = {
154 : false, 0,
155 : false, 0,
156 : true, 0 /* sMethods */,
157 : true, 1 /* sAttributes */,
158 : false, 0,
159 : false, 0,
160 : false, 0,
161 : -1,
162 : 3,
163 : sNativeProperties_sortedPropertyIndices,
164 : {
165 : { sMethods, &sNativeProperties_propertyInfos[0] },
166 : { sAttributes, &sNativeProperties_propertyInfos[2] }
167 : }
168 : };
169 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
170 : "We have a property info count that is oversized");
171 :
172 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
173 : {
174 : "Function",
175 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
176 : &sBoringInterfaceObjectClassClassOps,
177 : JS_NULL_CLASS_SPEC,
178 : JS_NULL_CLASS_EXT,
179 : &sInterfaceObjectClassObjectOps
180 : },
181 : eInterface,
182 : true,
183 : prototypes::id::TextTrackCueList,
184 : PrototypeTraits<prototypes::id::TextTrackCueList>::Depth,
185 : sNativePropertyHooks,
186 : "function TextTrackCueList() {\n [native code]\n}",
187 : JS::GetRealmFunctionPrototype
188 : };
189 :
190 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
191 : {
192 : "TextTrackCueListPrototype",
193 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
194 : JS_NULL_CLASS_OPS,
195 : JS_NULL_CLASS_SPEC,
196 : JS_NULL_CLASS_EXT,
197 : JS_NULL_OBJECT_OPS
198 : },
199 : eInterfacePrototype,
200 : false,
201 : prototypes::id::TextTrackCueList,
202 : PrototypeTraits<prototypes::id::TextTrackCueList>::Depth,
203 : sNativePropertyHooks,
204 : "[object TextTrackCueListPrototype]",
205 : JS::GetRealmObjectPrototype
206 : };
207 :
208 : JSObject*
209 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
210 : {
211 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
212 : }
213 :
214 : static_assert(IsBaseOf<nsISupports, mozilla::dom::TextTrackCueList >::value,
215 : "We don't support non-nsISupports native classes for "
216 : "proxy-based bindings yet");
217 :
218 :
219 : class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
220 : {
221 : public:
222 : explicit constexpr DOMProxyHandler()
223 : {
224 : }
225 :
226 : virtual bool
227 : getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
228 :
229 : virtual bool
230 : defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
231 :
232 : using mozilla::dom::DOMProxyHandler::defineProperty;
233 :
234 : virtual bool
235 : ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
236 :
237 : virtual bool
238 : hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
239 :
240 : virtual bool
241 : get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
242 :
243 : virtual const char*
244 : className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
245 :
246 : virtual bool
247 : finalizeInBackground(const JS::Value& priv) const override;
248 :
249 : virtual void
250 : finalize(JSFreeOp* fop, JSObject* proxy) const override;
251 :
252 : static const DOMProxyHandler*
253 : getInstance();
254 :
255 : virtual bool
256 : delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
257 :
258 : virtual bool
259 : getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
260 : };
261 :
262 : MOZ_ALWAYS_INLINE bool
263 0 : IsProxy(JSObject* obj)
264 : {
265 0 : return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
266 : }
267 :
268 : MOZ_ALWAYS_INLINE mozilla::dom::TextTrackCueList*
269 0 : UnwrapProxy(JSObject* obj)
270 : {
271 0 : MOZ_ASSERT(js::IsProxy(obj));
272 0 : if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
273 0 : MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
274 0 : obj = js::UncheckedUnwrap(obj);
275 : }
276 0 : MOZ_ASSERT(IsProxy(obj));
277 0 : return static_cast<mozilla::dom::TextTrackCueList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
278 : }
279 :
280 : bool
281 0 : DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
282 : {
283 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
284 0 : uint32_t index = GetArrayIndexFromId(cx, id);
285 0 : if (IsArrayIndex(index)) {
286 0 : mozilla::dom::TextTrackCueList* self = UnwrapProxy(proxy);
287 0 : bool found = false;
288 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrackCue>(self->IndexedGetter(index, found)));
289 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
290 :
291 0 : if (found) {
292 0 : if (!GetOrCreateDOMReflector(cx, result, desc.value())) {
293 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
294 0 : return false;
295 : }
296 0 : FillPropertyDescriptor(desc, proxy, true);
297 0 : return true;
298 : }
299 : }
300 :
301 0 : JS::Rooted<JSObject*> expando(cx);
302 0 : if (!isXray && (expando = GetExpandoObject(proxy))) {
303 0 : if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
304 0 : return false;
305 : }
306 0 : if (desc.object()) {
307 : // Pretend the property lives on the wrapper.
308 0 : desc.object().set(proxy);
309 0 : return true;
310 : }
311 : }
312 :
313 0 : desc.object().set(nullptr);
314 0 : return true;
315 : }
316 :
317 : bool
318 0 : DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
319 : {
320 0 : if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
321 0 : *defined = true;
322 0 : return opresult.failNoIndexedSetter();
323 : }
324 0 : return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
325 : }
326 :
327 :
328 : bool
329 0 : DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
330 : {
331 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
332 :
333 0 : uint32_t length = UnwrapProxy(proxy)->Length();
334 0 : MOZ_ASSERT(int32_t(length) >= 0);
335 0 : for (int32_t i = 0; i < int32_t(length); ++i) {
336 0 : if (!props.append(INT_TO_JSID(i))) {
337 0 : return false;
338 : }
339 : }
340 :
341 0 : JS::Rooted<JSObject*> expando(cx);
342 0 : if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
343 0 : !js::GetPropertyKeys(cx, expando, flags, &props)) {
344 0 : return false;
345 : }
346 :
347 0 : return true;
348 : }
349 :
350 : bool
351 0 : DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
352 : {
353 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
354 : "Should not have a XrayWrapper here");
355 :
356 0 : uint32_t index = GetArrayIndexFromId(cx, id);
357 0 : if (IsArrayIndex(index)) {
358 0 : bool found = false;
359 0 : mozilla::dom::TextTrackCueList* self = UnwrapProxy(proxy);
360 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrackCue>(self->IndexedGetter(index, found)));
361 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
362 : (void)result;
363 :
364 0 : *bp = found;
365 0 : return true;
366 : }
367 :
368 :
369 0 : JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
370 0 : if (expando) {
371 0 : bool b = true;
372 0 : bool ok = JS_HasPropertyById(cx, expando, id, &b);
373 0 : *bp = !!b;
374 0 : if (!ok || *bp) {
375 0 : return ok;
376 : }
377 : }
378 :
379 0 : *bp = false;
380 0 : return true;
381 : }
382 :
383 : bool
384 0 : DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
385 : {
386 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
387 : "Should not have a XrayWrapper here");
388 :
389 0 : uint32_t index = GetArrayIndexFromId(cx, id);
390 0 : if (IsArrayIndex(index)) {
391 0 : mozilla::dom::TextTrackCueList* self = UnwrapProxy(proxy);
392 0 : bool found = false;
393 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrackCue>(self->IndexedGetter(index, found)));
394 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
395 :
396 0 : if (found) {
397 0 : if (!GetOrCreateDOMReflector(cx, result, vp)) {
398 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
399 0 : return false;
400 : }
401 0 : return true;
402 : }
403 : // Even if we don't have this index, we don't forward the
404 : // get on to our expando object.
405 : } else {
406 : { // Scope for expando
407 0 : JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
408 0 : if (expando) {
409 : bool hasProp;
410 0 : if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
411 0 : return false;
412 : }
413 :
414 0 : if (hasProp) {
415 : // Forward the get to the expando object, but our receiver is whatever our
416 : // receiver is.
417 0 : return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
418 : }
419 : }
420 : }
421 : }
422 :
423 : bool foundOnPrototype;
424 0 : if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
425 0 : return false;
426 : }
427 :
428 0 : if (foundOnPrototype) {
429 0 : return true;
430 : }
431 :
432 0 : vp.setUndefined();
433 0 : return true;
434 : }
435 :
436 : const char*
437 0 : DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
438 : {
439 0 : return "TextTrackCueList";
440 : }
441 :
442 : bool
443 0 : DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
444 : {
445 0 : return false;
446 : }
447 :
448 : void
449 0 : DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
450 : {
451 0 : mozilla::dom::TextTrackCueList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TextTrackCueList>(proxy);
452 0 : if (self) {
453 0 : ClearWrapper(self, self, proxy);
454 0 : AddForDeferredFinalization<mozilla::dom::TextTrackCueList>(self);
455 : }
456 0 : }
457 :
458 : const DOMProxyHandler*
459 0 : DOMProxyHandler::getInstance()
460 : {
461 : static const DOMProxyHandler instance;
462 0 : return &instance;
463 : }
464 :
465 : bool
466 0 : DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
467 : {
468 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
469 : "Should not have a XrayWrapper here");
470 :
471 0 : uint32_t index = GetArrayIndexFromId(cx, id);
472 0 : if (IsArrayIndex(index)) {
473 : bool deleteSucceeded;
474 0 : bool found = false;
475 0 : mozilla::dom::TextTrackCueList* self = UnwrapProxy(proxy);
476 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrackCue>(self->IndexedGetter(index, found)));
477 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
478 : (void)result;
479 0 : deleteSucceeded = !found;
480 0 : return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
481 : }
482 :
483 0 : return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
484 : }
485 :
486 : bool
487 0 : DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
488 : {
489 0 : JS::Rooted<JS::Value> temp(cx);
490 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
491 : "Should not have a XrayWrapper here");
492 :
493 0 : mozilla::dom::TextTrackCueList* self = UnwrapProxy(proxy);
494 0 : uint32_t length = self->Length();
495 : // Compute the end of the indices we'll get ourselves
496 0 : uint32_t ourEnd = std::max(begin, std::min(end, length));
497 :
498 0 : for (uint32_t index = begin; index < ourEnd; ++index) {
499 0 : bool found = false;
500 0 : auto result(StrongOrRawPtr<mozilla::dom::TextTrackCue>(self->IndexedGetter(index, found)));
501 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
502 :
503 0 : MOZ_ASSERT(found);
504 0 : if (!GetOrCreateDOMReflector(cx, result, &temp)) {
505 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
506 0 : return false;
507 : }
508 0 : if (!adder->append(cx, temp)) return false;
509 0 : continue;
510 : }
511 :
512 0 : if (end > ourEnd) {
513 0 : JS::Rooted<JSObject*> proto(cx);
514 0 : if (!js::GetObjectProto(cx, proxy, &proto)) {
515 0 : return false;
516 : }
517 0 : return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
518 : }
519 :
520 0 : return true;
521 : }
522 :
523 : static const js::ClassExtension sClassExtension = PROXY_MAKE_EXT(
524 : _objectMoved
525 : );
526 :
527 : static const DOMJSClass sClass = {
528 : PROXY_CLASS_WITH_EXT("TextTrackCueList",
529 : JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
530 : &sClassExtension),
531 : { prototypes::id::TextTrackCueList, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
532 : IsBaseOf<nsISupports, mozilla::dom::TextTrackCueList >::value,
533 : sNativePropertyHooks,
534 : FindAssociatedGlobalForNative<mozilla::dom::TextTrackCueList>::Get,
535 : GetProtoObjectHandle,
536 : GetCCParticipant<mozilla::dom::TextTrackCueList>::Get()
537 : };
538 :
539 : bool
540 0 : Wrap(JSContext* aCx, mozilla::dom::TextTrackCueList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
541 : {
542 : MOZ_ASSERT(static_cast<mozilla::dom::TextTrackCueList*>(aObject) ==
543 : reinterpret_cast<mozilla::dom::TextTrackCueList*>(aObject),
544 : "Multiple inheritance for mozilla::dom::TextTrackCueList is broken.");
545 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
546 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
547 0 : MOZ_ASSERT(!aCache->GetWrapper(),
548 : "You should probably not be using Wrap() directly; use "
549 : "GetOrCreateDOMReflector instead");
550 :
551 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
552 : "nsISupports must be on our primary inheritance chain");
553 :
554 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
555 0 : if (!global) {
556 0 : return false;
557 : }
558 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
559 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
560 :
561 : // That might have ended up wrapping us already, due to the wonders
562 : // of XBL. Check for that, and bail out as needed.
563 0 : aReflector.set(aCache->GetWrapper());
564 0 : if (aReflector) {
565 : #ifdef DEBUG
566 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
567 : #endif // DEBUG
568 0 : return true;
569 : }
570 :
571 0 : JSAutoCompartment ac(aCx, global);
572 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
573 0 : if (!canonicalProto) {
574 0 : return false;
575 : }
576 0 : JS::Rooted<JSObject*> proto(aCx);
577 0 : if (aGivenProto) {
578 0 : proto = aGivenProto;
579 : // Unfortunately, while aGivenProto was in the compartment of aCx
580 : // coming in, we changed compartments to that of "parent" so may need
581 : // to wrap the proto here.
582 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
583 0 : if (!JS_WrapObject(aCx, &proto)) {
584 0 : return false;
585 : }
586 : }
587 : } else {
588 0 : proto = canonicalProto;
589 : }
590 :
591 0 : BindingJSObjectCreator<mozilla::dom::TextTrackCueList> creator(aCx);
592 0 : JS::Rooted<JS::Value> expandoValue(aCx, JS::UndefinedValue());
593 0 : creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
594 0 : proto, aObject, expandoValue, aReflector);
595 0 : if (!aReflector) {
596 0 : return false;
597 : }
598 :
599 :
600 0 : aCache->SetWrapper(aReflector);
601 0 : creator.InitializationSucceeded();
602 :
603 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
604 : aCache->GetWrapperPreserveColor() == aReflector);
605 : // If proto != canonicalProto, we have to preserve our wrapper;
606 : // otherwise we won't be able to properly recreate it later, since
607 : // we won't know what proto to use. Note that we don't check
608 : // aGivenProto here, since it's entirely possible (and even
609 : // somewhat common) to have a non-null aGivenProto which is the
610 : // same as canonicalProto.
611 0 : if (proto != canonicalProto) {
612 0 : PreserveWrapper(aObject);
613 : }
614 :
615 0 : return true;
616 : }
617 :
618 : static bool
619 0 : ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
620 : {
621 0 : return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
622 : }
623 :
624 : static bool
625 0 : EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
626 : {
627 0 : return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
628 : }
629 :
630 : const NativePropertyHooks sNativePropertyHooks[] = { {
631 : ResolveOwnProperty,
632 : EnumerateOwnProperties,
633 : nullptr,
634 : { sNativeProperties.Upcast(), nullptr },
635 : prototypes::id::TextTrackCueList,
636 : constructors::id::TextTrackCueList,
637 : nullptr,
638 : &DefaultXrayExpandoObjectClass
639 : } };
640 :
641 : void
642 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
643 : {
644 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
645 0 : if (!parentProto) {
646 0 : return;
647 : }
648 :
649 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
650 0 : if (!constructorProto) {
651 0 : return;
652 : }
653 :
654 : static bool sIdsInited = false;
655 0 : if (!sIdsInited && NS_IsMainThread()) {
656 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
657 0 : return;
658 : }
659 0 : sIdsInited = true;
660 : }
661 :
662 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TextTrackCueList);
663 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TextTrackCueList);
664 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
665 : &sPrototypeClass.mBase, protoCache,
666 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
667 : interfaceCache,
668 : sNativeProperties.Upcast(),
669 : nullptr,
670 : "TextTrackCueList", aDefineOnGlobal,
671 : nullptr,
672 0 : false);
673 : }
674 :
675 : JS::Handle<JSObject*>
676 0 : GetProtoObjectHandle(JSContext* aCx)
677 : {
678 : /* Get the interface prototype object for this class. This will create the
679 : object as needed. */
680 0 : bool aDefineOnGlobal = true;
681 :
682 : /* Make sure our global is sane. Hopefully we can remove this sometime */
683 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
684 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
685 0 : return nullptr;
686 : }
687 :
688 : /* Check to see whether the interface objects are already installed */
689 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
690 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::TextTrackCueList)) {
691 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
692 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
693 : }
694 :
695 : /*
696 : * The object might _still_ be null, but that's OK.
697 : *
698 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
699 : * traced by TraceProtoAndIfaceCache() and its contents are never
700 : * changed after they have been set.
701 : *
702 : * Calling address() avoids the read read barrier that does gray
703 : * unmarking, but it's not possible for the object to be gray here.
704 : */
705 :
706 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::TextTrackCueList);
707 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
708 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
709 : }
710 :
711 : JS::Handle<JSObject*>
712 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
713 : {
714 : /* Get the interface object for this class. This will create the object as
715 : needed. */
716 :
717 : /* Make sure our global is sane. Hopefully we can remove this sometime */
718 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
719 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
720 0 : return nullptr;
721 : }
722 :
723 : /* Check to see whether the interface objects are already installed */
724 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
725 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::TextTrackCueList)) {
726 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
727 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
728 : }
729 :
730 : /*
731 : * The object might _still_ be null, but that's OK.
732 : *
733 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
734 : * traced by TraceProtoAndIfaceCache() and its contents are never
735 : * changed after they have been set.
736 : *
737 : * Calling address() avoids the read read barrier that does gray
738 : * unmarking, but it's not possible for the object to be gray here.
739 : */
740 :
741 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::TextTrackCueList);
742 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
743 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
744 : }
745 :
746 : JSObject*
747 0 : GetConstructorObject(JSContext* aCx)
748 : {
749 0 : return GetConstructorObjectHandle(aCx);
750 : }
751 :
752 : } // namespace TextTrackCueListBinding
753 :
754 :
755 :
756 : } // namespace dom
757 : } // namespace mozilla
|