Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MediaQueryList.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "EventHandlerBinding.h"
4 : #include "EventListenerBinding.h"
5 : #include "EventTargetBinding.h"
6 : #include "MediaQueryListBinding.h"
7 : #include "WrapperFactory.h"
8 : #include "mozilla/OwningNonNull.h"
9 : #include "mozilla/dom/BindingUtils.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/MediaQueryList.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/Nullable.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : namespace MediaQueryListBinding {
21 :
22 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
23 : "Can't inherit from an interface with a different ownership model.");
24 :
25 : static bool
26 0 : get_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryList* self, JSJitGetterCallArgs args)
27 : {
28 0 : DOMString result;
29 0 : self->GetMedia(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 const JSJitInfo media_getterinfo = {
38 : { (JSJitGetterOp)get_media },
39 : { prototypes::id::MediaQueryList },
40 : { PrototypeTraits<prototypes::id::MediaQueryList>::Depth },
41 : JSJitInfo::Getter,
42 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
43 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
44 : false, /* isInfallible. False in setters. */
45 : false, /* isMovable. Not relevant for setters. */
46 : false, /* isEliminatable. Not relevant for setters. */
47 : false, /* isAlwaysInSlot. Only relevant for getters. */
48 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
49 : false, /* isTypedMethod. Only relevant for methods. */
50 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
51 : };
52 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
53 : static_assert(0 < 1, "There is no slot for us");
54 :
55 : static bool
56 2 : get_matches(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryList* self, JSJitGetterCallArgs args)
57 : {
58 2 : bool result(self->Matches());
59 2 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
60 2 : args.rval().setBoolean(result);
61 2 : return true;
62 : }
63 :
64 : static const JSJitInfo matches_getterinfo = {
65 : { (JSJitGetterOp)get_matches },
66 : { prototypes::id::MediaQueryList },
67 : { PrototypeTraits<prototypes::id::MediaQueryList>::Depth },
68 : JSJitInfo::Getter,
69 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
70 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
71 : true, /* isInfallible. False in setters. */
72 : false, /* isMovable. Not relevant for setters. */
73 : false, /* isEliminatable. Not relevant for setters. */
74 : false, /* isAlwaysInSlot. Only relevant for getters. */
75 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
76 : false, /* isTypedMethod. Only relevant for methods. */
77 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
78 : };
79 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
80 : static_assert(0 < 1, "There is no slot for us");
81 :
82 : static bool
83 1 : addListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryList* self, const JSJitMethodCallArgs& args)
84 : {
85 1 : if (MOZ_UNLIKELY(args.length() < 1)) {
86 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaQueryList.addListener");
87 : }
88 2 : RootedCallback<RefPtr<binding_detail::FastEventListener>> arg0(cx);
89 1 : if (args[0].isObject()) {
90 : { // scope for tempRoot
91 2 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
92 2 : arg0 = new binding_detail::FastEventListener(tempRoot);
93 : }
94 0 : } else if (args[0].isNullOrUndefined()) {
95 0 : arg0 = nullptr;
96 : } else {
97 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of MediaQueryList.addListener");
98 0 : return false;
99 : }
100 2 : binding_detail::FastErrorResult rv;
101 1 : self->AddListener(Constify(arg0), rv);
102 1 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
103 0 : return false;
104 : }
105 1 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
106 1 : args.rval().setUndefined();
107 1 : return true;
108 : }
109 :
110 : static const JSJitInfo addListener_methodinfo = {
111 : { (JSJitGetterOp)addListener },
112 : { prototypes::id::MediaQueryList },
113 : { PrototypeTraits<prototypes::id::MediaQueryList>::Depth },
114 : JSJitInfo::Method,
115 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
116 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
117 : false, /* isInfallible. False in setters. */
118 : false, /* isMovable. Not relevant for setters. */
119 : false, /* isEliminatable. Not relevant for setters. */
120 : false, /* isAlwaysInSlot. Only relevant for getters. */
121 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
122 : false, /* isTypedMethod. Only relevant for methods. */
123 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
124 : };
125 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
126 : static_assert(0 < 1, "There is no slot for us");
127 :
128 : static bool
129 0 : removeListener(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryList* self, const JSJitMethodCallArgs& args)
130 : {
131 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
132 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaQueryList.removeListener");
133 : }
134 0 : RootedCallback<RefPtr<binding_detail::FastEventListener>> arg0(cx);
135 0 : if (args[0].isObject()) {
136 : { // scope for tempRoot
137 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
138 0 : arg0 = new binding_detail::FastEventListener(tempRoot);
139 : }
140 0 : } else if (args[0].isNullOrUndefined()) {
141 0 : arg0 = nullptr;
142 : } else {
143 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of MediaQueryList.removeListener");
144 0 : return false;
145 : }
146 0 : binding_detail::FastErrorResult rv;
147 0 : self->RemoveListener(Constify(arg0), rv);
148 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
149 0 : return false;
150 : }
151 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
152 0 : args.rval().setUndefined();
153 0 : return true;
154 : }
155 :
156 : static const JSJitInfo removeListener_methodinfo = {
157 : { (JSJitGetterOp)removeListener },
158 : { prototypes::id::MediaQueryList },
159 : { PrototypeTraits<prototypes::id::MediaQueryList>::Depth },
160 : JSJitInfo::Method,
161 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
162 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
163 : false, /* isInfallible. False in setters. */
164 : false, /* isMovable. Not relevant for setters. */
165 : false, /* isEliminatable. Not relevant for setters. */
166 : false, /* isAlwaysInSlot. Only relevant for getters. */
167 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
168 : false, /* isTypedMethod. Only relevant for methods. */
169 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
170 : };
171 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
172 : static_assert(0 < 1, "There is no slot for us");
173 :
174 : static bool
175 0 : get_onchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryList* self, JSJitGetterCallArgs args)
176 : {
177 0 : RefPtr<EventHandlerNonNull> result(self->GetOnchange());
178 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
179 0 : if (result) {
180 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
181 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
182 0 : return false;
183 : }
184 0 : return true;
185 : } else {
186 0 : args.rval().setNull();
187 0 : return true;
188 : }
189 : }
190 :
191 : static bool
192 0 : set_onchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryList* self, JSJitSetterCallArgs args)
193 : {
194 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
195 0 : if (args[0].isObject()) {
196 : { // scope for tempRoot
197 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
198 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
199 : }
200 : } else {
201 0 : arg0 = nullptr;
202 : }
203 0 : self->SetOnchange(Constify(arg0));
204 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
205 :
206 0 : return true;
207 : }
208 :
209 : static const JSJitInfo onchange_getterinfo = {
210 : { (JSJitGetterOp)get_onchange },
211 : { prototypes::id::MediaQueryList },
212 : { PrototypeTraits<prototypes::id::MediaQueryList>::Depth },
213 : JSJitInfo::Getter,
214 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
215 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
216 : false, /* isInfallible. False in setters. */
217 : false, /* isMovable. Not relevant for setters. */
218 : false, /* isEliminatable. Not relevant for setters. */
219 : false, /* isAlwaysInSlot. Only relevant for getters. */
220 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
221 : false, /* isTypedMethod. Only relevant for methods. */
222 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
223 : };
224 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
225 : static_assert(0 < 1, "There is no slot for us");
226 : static const JSJitInfo onchange_setterinfo = {
227 : { (JSJitGetterOp)set_onchange },
228 : { prototypes::id::MediaQueryList },
229 : { PrototypeTraits<prototypes::id::MediaQueryList>::Depth },
230 : JSJitInfo::Setter,
231 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
232 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
233 : false, /* isInfallible. False in setters. */
234 : false, /* isMovable. Not relevant for setters. */
235 : false, /* isEliminatable. Not relevant for setters. */
236 : false, /* isAlwaysInSlot. Only relevant for getters. */
237 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
238 : false, /* isTypedMethod. Only relevant for methods. */
239 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
240 : };
241 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
242 : static_assert(0 < 1, "There is no slot for us");
243 :
244 : static bool
245 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
246 : {
247 0 : mozilla::dom::MediaQueryList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaQueryList>(obj);
248 : // We don't want to preserve if we don't have a wrapper, and we
249 : // obviously can't preserve if we're not initialized.
250 0 : if (self && self->GetWrapperPreserveColor()) {
251 0 : PreserveWrapper(self);
252 : }
253 0 : return true;
254 : }
255 :
256 : static void
257 0 : _finalize(js::FreeOp* fop, JSObject* obj)
258 : {
259 0 : mozilla::dom::MediaQueryList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaQueryList>(obj);
260 0 : if (self) {
261 0 : ClearWrapper(self, self, obj);
262 0 : AddForDeferredFinalization<mozilla::dom::MediaQueryList>(self);
263 : }
264 0 : }
265 :
266 : static void
267 0 : _objectMoved(JSObject* obj, const JSObject* old)
268 : {
269 0 : mozilla::dom::MediaQueryList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaQueryList>(obj);
270 0 : if (self) {
271 0 : UpdateWrapper(self, self, obj, old);
272 : }
273 0 : }
274 :
275 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
276 : #if defined(__clang__)
277 : #pragma clang diagnostic push
278 : #pragma clang diagnostic ignored "-Wmissing-braces"
279 : #endif
280 : static const JSFunctionSpec sMethods_specs[] = {
281 : JS_FNSPEC("addListener", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&addListener_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
282 : JS_FNSPEC("removeListener", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&removeListener_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
283 : JS_FS_END
284 : };
285 : #if defined(__clang__)
286 : #pragma clang diagnostic pop
287 : #endif
288 :
289 :
290 : // Can't be const because the pref-enabled boolean needs to be writable
291 : static Prefable<const JSFunctionSpec> sMethods[] = {
292 : { nullptr, &sMethods_specs[0] },
293 : { nullptr, nullptr }
294 : };
295 :
296 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
297 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
298 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
299 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
300 :
301 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
302 : #if defined(__clang__)
303 : #pragma clang diagnostic push
304 : #pragma clang diagnostic ignored "-Wmissing-braces"
305 : #endif
306 : static const JSPropertySpec sAttributes_specs[] = {
307 : { "media", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &media_getterinfo, nullptr, nullptr },
308 : { "matches", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &matches_getterinfo, nullptr, nullptr },
309 : { "onchange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onchange_getterinfo, GenericBindingSetter, &onchange_setterinfo },
310 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
311 : };
312 : #if defined(__clang__)
313 : #pragma clang diagnostic pop
314 : #endif
315 :
316 :
317 : // Can't be const because the pref-enabled boolean needs to be writable
318 : static Prefable<const JSPropertySpec> sAttributes[] = {
319 : { nullptr, &sAttributes_specs[0] },
320 : { nullptr, nullptr }
321 : };
322 :
323 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
324 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
325 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
326 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
327 :
328 :
329 : static uint16_t sNativeProperties_sortedPropertyIndices[5];
330 : static PropertyInfo sNativeProperties_propertyInfos[5];
331 :
332 : static const NativePropertiesN<2> sNativeProperties = {
333 : false, 0,
334 : false, 0,
335 : true, 0 /* sMethods */,
336 : true, 1 /* sAttributes */,
337 : false, 0,
338 : false, 0,
339 : false, 0,
340 : -1,
341 : 5,
342 : sNativeProperties_sortedPropertyIndices,
343 : {
344 : { sMethods, &sNativeProperties_propertyInfos[0] },
345 : { sAttributes, &sNativeProperties_propertyInfos[2] }
346 : }
347 : };
348 : static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
349 : "We have a property info count that is oversized");
350 :
351 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
352 : {
353 : "Function",
354 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
355 : &sBoringInterfaceObjectClassClassOps,
356 : JS_NULL_CLASS_SPEC,
357 : JS_NULL_CLASS_EXT,
358 : &sInterfaceObjectClassObjectOps
359 : },
360 : eInterface,
361 : true,
362 : prototypes::id::MediaQueryList,
363 : PrototypeTraits<prototypes::id::MediaQueryList>::Depth,
364 : sNativePropertyHooks,
365 : "function MediaQueryList() {\n [native code]\n}",
366 : EventTargetBinding::GetConstructorObject
367 : };
368 :
369 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
370 : {
371 : "MediaQueryListPrototype",
372 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
373 : JS_NULL_CLASS_OPS,
374 : JS_NULL_CLASS_SPEC,
375 : JS_NULL_CLASS_EXT,
376 : JS_NULL_OBJECT_OPS
377 : },
378 : eInterfacePrototype,
379 : false,
380 : prototypes::id::MediaQueryList,
381 : PrototypeTraits<prototypes::id::MediaQueryList>::Depth,
382 : sNativePropertyHooks,
383 : "[object MediaQueryListPrototype]",
384 : EventTargetBinding::GetProtoObject
385 : };
386 :
387 : JSObject*
388 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
389 : {
390 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
391 : }
392 :
393 : static const js::ClassOps sClassOps = {
394 : _addProperty, /* addProperty */
395 : nullptr, /* delProperty */
396 : nullptr, /* getProperty */
397 : nullptr, /* setProperty */
398 : nullptr, /* enumerate */
399 : nullptr, /* newEnumerate */
400 : nullptr, /* resolve */
401 : nullptr, /* mayResolve */
402 : _finalize, /* finalize */
403 : nullptr, /* call */
404 : nullptr, /* hasInstance */
405 : nullptr, /* construct */
406 : nullptr, /* trace */
407 : };
408 :
409 : static const js::ClassExtension sClassExtension = {
410 : nullptr, /* weakmapKeyDelegateOp */
411 : _objectMoved /* objectMovedOp */
412 : };
413 :
414 : static const DOMJSClass sClass = {
415 : { "MediaQueryList",
416 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
417 : &sClassOps,
418 : JS_NULL_CLASS_SPEC,
419 : &sClassExtension,
420 : JS_NULL_OBJECT_OPS
421 : },
422 : { prototypes::id::EventTarget, prototypes::id::MediaQueryList, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
423 : IsBaseOf<nsISupports, mozilla::dom::MediaQueryList >::value,
424 : sNativePropertyHooks,
425 : FindAssociatedGlobalForNative<mozilla::dom::MediaQueryList>::Get,
426 : GetProtoObjectHandle,
427 : GetCCParticipant<mozilla::dom::MediaQueryList>::Get()
428 : };
429 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
430 : "Must have the right minimal number of reserved slots.");
431 : static_assert(1 >= 1,
432 : "Must have enough reserved slots.");
433 :
434 : const JSClass*
435 0 : GetJSClass()
436 : {
437 0 : return sClass.ToJSClass();
438 : }
439 :
440 : bool
441 3 : Wrap(JSContext* aCx, mozilla::dom::MediaQueryList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
442 : {
443 : MOZ_ASSERT(static_cast<mozilla::dom::MediaQueryList*>(aObject) ==
444 : reinterpret_cast<mozilla::dom::MediaQueryList*>(aObject),
445 : "Multiple inheritance for mozilla::dom::MediaQueryList is broken.");
446 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
447 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
448 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
449 3 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
450 3 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
451 3 : MOZ_ASSERT(!aCache->GetWrapper(),
452 : "You should probably not be using Wrap() directly; use "
453 : "GetOrCreateDOMReflector instead");
454 :
455 3 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
456 : "nsISupports must be on our primary inheritance chain");
457 :
458 6 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
459 3 : if (!global) {
460 0 : return false;
461 : }
462 3 : MOZ_ASSERT(JS_IsGlobalObject(global));
463 3 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
464 :
465 : // That might have ended up wrapping us already, due to the wonders
466 : // of XBL. Check for that, and bail out as needed.
467 3 : aReflector.set(aCache->GetWrapper());
468 3 : if (aReflector) {
469 : #ifdef DEBUG
470 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
471 : #endif // DEBUG
472 0 : return true;
473 : }
474 :
475 6 : JSAutoCompartment ac(aCx, global);
476 3 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
477 3 : if (!canonicalProto) {
478 0 : return false;
479 : }
480 6 : JS::Rooted<JSObject*> proto(aCx);
481 3 : if (aGivenProto) {
482 0 : proto = aGivenProto;
483 : // Unfortunately, while aGivenProto was in the compartment of aCx
484 : // coming in, we changed compartments to that of "parent" so may need
485 : // to wrap the proto here.
486 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
487 0 : if (!JS_WrapObject(aCx, &proto)) {
488 0 : return false;
489 : }
490 : }
491 : } else {
492 3 : proto = canonicalProto;
493 : }
494 :
495 6 : BindingJSObjectCreator<mozilla::dom::MediaQueryList> creator(aCx);
496 3 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
497 3 : if (!aReflector) {
498 0 : return false;
499 : }
500 :
501 3 : aCache->SetWrapper(aReflector);
502 3 : creator.InitializationSucceeded();
503 :
504 3 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
505 : aCache->GetWrapperPreserveColor() == aReflector);
506 : // If proto != canonicalProto, we have to preserve our wrapper;
507 : // otherwise we won't be able to properly recreate it later, since
508 : // we won't know what proto to use. Note that we don't check
509 : // aGivenProto here, since it's entirely possible (and even
510 : // somewhat common) to have a non-null aGivenProto which is the
511 : // same as canonicalProto.
512 3 : if (proto != canonicalProto) {
513 0 : PreserveWrapper(aObject);
514 : }
515 :
516 3 : return true;
517 : }
518 :
519 : const NativePropertyHooks sNativePropertyHooks[] = { {
520 : nullptr,
521 : nullptr,
522 : nullptr,
523 : { sNativeProperties.Upcast(), nullptr },
524 : prototypes::id::MediaQueryList,
525 : constructors::id::MediaQueryList,
526 : EventTargetBinding::sNativePropertyHooks,
527 : &DefaultXrayExpandoObjectClass
528 : } };
529 :
530 : void
531 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
532 : {
533 1 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
534 1 : if (!parentProto) {
535 0 : return;
536 : }
537 :
538 1 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
539 1 : if (!constructorProto) {
540 0 : return;
541 : }
542 :
543 : static bool sIdsInited = false;
544 1 : if (!sIdsInited && NS_IsMainThread()) {
545 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
546 0 : return;
547 : }
548 1 : sIdsInited = true;
549 : }
550 :
551 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaQueryList);
552 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaQueryList);
553 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
554 : &sPrototypeClass.mBase, protoCache,
555 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
556 : interfaceCache,
557 : sNativeProperties.Upcast(),
558 : nullptr,
559 : "MediaQueryList", aDefineOnGlobal,
560 : nullptr,
561 1 : false);
562 : }
563 :
564 : JS::Handle<JSObject*>
565 3 : GetProtoObjectHandle(JSContext* aCx)
566 : {
567 : /* Get the interface prototype object for this class. This will create the
568 : object as needed. */
569 3 : bool aDefineOnGlobal = true;
570 :
571 : /* Make sure our global is sane. Hopefully we can remove this sometime */
572 3 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
573 3 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
574 0 : return nullptr;
575 : }
576 :
577 : /* Check to see whether the interface objects are already installed */
578 3 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
579 3 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MediaQueryList)) {
580 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
581 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
582 : }
583 :
584 : /*
585 : * The object might _still_ be null, but that's OK.
586 : *
587 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
588 : * traced by TraceProtoAndIfaceCache() and its contents are never
589 : * changed after they have been set.
590 : *
591 : * Calling address() avoids the read read barrier that does gray
592 : * unmarking, but it's not possible for the object to be gray here.
593 : */
594 :
595 3 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MediaQueryList);
596 3 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
597 3 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
598 : }
599 :
600 : JS::Handle<JSObject*>
601 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
602 : {
603 : /* Get the interface object for this class. This will create the object as
604 : needed. */
605 :
606 : /* Make sure our global is sane. Hopefully we can remove this sometime */
607 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
608 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
609 0 : return nullptr;
610 : }
611 :
612 : /* Check to see whether the interface objects are already installed */
613 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
614 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MediaQueryList)) {
615 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
616 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
617 : }
618 :
619 : /*
620 : * The object might _still_ be null, but that's OK.
621 : *
622 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
623 : * traced by TraceProtoAndIfaceCache() and its contents are never
624 : * changed after they have been set.
625 : *
626 : * Calling address() avoids the read read barrier that does gray
627 : * unmarking, but it's not possible for the object to be gray here.
628 : */
629 :
630 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MediaQueryList);
631 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
632 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
633 : }
634 :
635 : JSObject*
636 0 : GetConstructorObject(JSContext* aCx)
637 : {
638 0 : return GetConstructorObjectHandle(aCx);
639 : }
640 :
641 : } // namespace MediaQueryListBinding
642 :
643 :
644 :
645 : } // namespace dom
646 : } // namespace mozilla
|