Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MediaQueryListEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "MediaQueryListEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/MediaQueryListEvent.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ScriptSettings.h"
14 : #include "mozilla/dom/SimpleGlobalObject.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 :
21 0 : MediaQueryListEventInit::MediaQueryListEventInit()
22 0 : : EventInit(FastDictionaryInitializer())
23 : {
24 : // Safe to pass a null context if we pass a null value
25 0 : Init(nullptr, JS::NullHandleValue);
26 0 : }
27 :
28 :
29 :
30 : bool
31 0 : MediaQueryListEventInit::InitIds(JSContext* cx, MediaQueryListEventInitAtoms* atomsCache)
32 : {
33 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
34 :
35 : // Initialize these in reverse order so that any failure leaves the first one
36 : // uninitialized.
37 0 : if (!atomsCache->media_id.init(cx, "media") ||
38 0 : !atomsCache->matches_id.init(cx, "matches")) {
39 0 : return false;
40 : }
41 0 : return true;
42 : }
43 :
44 : bool
45 0 : MediaQueryListEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
46 : {
47 : // Passing a null JSContext is OK only if we're initing from null,
48 : // Since in that case we will not have to do any property gets
49 : // Also evaluate isNullOrUndefined in order to avoid false-positive
50 : // checkers by static analysis tools
51 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
52 0 : MediaQueryListEventInitAtoms* atomsCache = nullptr;
53 0 : if (cx) {
54 0 : atomsCache = GetAtomCache<MediaQueryListEventInitAtoms>(cx);
55 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
56 0 : return false;
57 : }
58 : }
59 :
60 : // Per spec, we init the parent's members first
61 0 : if (!EventInit::Init(cx, val)) {
62 0 : return false;
63 : }
64 :
65 0 : bool isNull = val.isNullOrUndefined();
66 : // We only need these if !isNull, in which case we have |cx|.
67 0 : Maybe<JS::Rooted<JSObject *> > object;
68 0 : Maybe<JS::Rooted<JS::Value> > temp;
69 0 : if (!isNull) {
70 0 : MOZ_ASSERT(cx);
71 0 : object.emplace(cx, &val.toObject());
72 0 : temp.emplace(cx);
73 : }
74 0 : if (!isNull) {
75 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->matches_id, temp.ptr())) {
76 0 : return false;
77 : }
78 : }
79 0 : if (!isNull && !temp->isUndefined()) {
80 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mMatches)) {
81 0 : return false;
82 : }
83 : } else {
84 0 : mMatches = false;
85 : }
86 0 : mIsAnyMemberPresent = true;
87 :
88 0 : if (!isNull) {
89 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->media_id, temp.ptr())) {
90 0 : return false;
91 : }
92 : }
93 0 : if (!isNull && !temp->isUndefined()) {
94 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mMedia)) {
95 0 : return false;
96 : }
97 : } else {
98 : static const char16_t data[] = { 0 };
99 0 : mMedia.Rebind(data, ArrayLength(data) - 1);
100 : }
101 0 : mIsAnyMemberPresent = true;
102 0 : return true;
103 : }
104 :
105 : bool
106 0 : MediaQueryListEventInit::Init(const nsAString& aJSON)
107 : {
108 0 : AutoJSAPI jsapi;
109 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
110 0 : if (!cleanGlobal) {
111 0 : return false;
112 : }
113 0 : if (!jsapi.Init(cleanGlobal)) {
114 0 : return false;
115 : }
116 0 : JSContext* cx = jsapi.cx();
117 0 : JS::Rooted<JS::Value> json(cx);
118 0 : bool ok = ParseJSON(cx, aJSON, &json);
119 0 : NS_ENSURE_TRUE(ok, false);
120 0 : return Init(cx, json);
121 : }
122 :
123 : bool
124 0 : MediaQueryListEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
125 : {
126 0 : MediaQueryListEventInitAtoms* atomsCache = GetAtomCache<MediaQueryListEventInitAtoms>(cx);
127 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
128 0 : return false;
129 : }
130 :
131 : // Per spec, we define the parent's members first
132 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
133 0 : return false;
134 : }
135 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
136 :
137 : do {
138 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
139 0 : JS::Rooted<JS::Value> temp(cx);
140 0 : bool const & currentValue = mMatches;
141 0 : temp.setBoolean(currentValue);
142 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->matches_id, temp, JSPROP_ENUMERATE)) {
143 0 : return false;
144 : }
145 0 : break;
146 : } while(0);
147 :
148 : do {
149 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
150 0 : JS::Rooted<JS::Value> temp(cx);
151 0 : nsString const & currentValue = mMedia;
152 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
153 0 : return false;
154 : }
155 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->media_id, temp, JSPROP_ENUMERATE)) {
156 0 : return false;
157 : }
158 0 : break;
159 : } while(0);
160 :
161 0 : return true;
162 : }
163 :
164 : bool
165 0 : MediaQueryListEventInit::ToJSON(nsAString& aJSON) const
166 : {
167 0 : AutoJSAPI jsapi;
168 0 : jsapi.Init();
169 0 : JSContext *cx = jsapi.cx();
170 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
171 : // because we'll only be creating objects, in ways that have no
172 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
173 : // which likewise guarantees no side-effects for the sorts of
174 : // things we will pass it.
175 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
176 0 : JS::Rooted<JS::Value> val(cx);
177 0 : if (!ToObjectInternal(cx, &val)) {
178 0 : return false;
179 : }
180 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
181 0 : return StringifyToJSON(cx, obj, aJSON);
182 : }
183 :
184 : void
185 0 : MediaQueryListEventInit::TraceDictionary(JSTracer* trc)
186 : {
187 0 : EventInit::TraceDictionary(trc);
188 0 : }
189 :
190 : MediaQueryListEventInit&
191 0 : MediaQueryListEventInit::operator=(const MediaQueryListEventInit& aOther)
192 : {
193 0 : EventInit::operator=(aOther);
194 0 : mMatches = aOther.mMatches;
195 0 : mMedia = aOther.mMedia;
196 0 : return *this;
197 : }
198 :
199 : namespace binding_detail {
200 : } // namespace binding_detail
201 :
202 :
203 : namespace MediaQueryListEventBinding {
204 :
205 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
206 : "Can't inherit from an interface with a different ownership model.");
207 :
208 : static bool
209 0 : get_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryListEvent* self, JSJitGetterCallArgs args)
210 : {
211 0 : DOMString result;
212 0 : self->GetMedia(result);
213 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
214 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
215 0 : return false;
216 : }
217 0 : return true;
218 : }
219 :
220 : static const JSJitInfo media_getterinfo = {
221 : { (JSJitGetterOp)get_media },
222 : { prototypes::id::MediaQueryListEvent },
223 : { PrototypeTraits<prototypes::id::MediaQueryListEvent>::Depth },
224 : JSJitInfo::Getter,
225 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
226 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
227 : false, /* isInfallible. False in setters. */
228 : false, /* isMovable. Not relevant for setters. */
229 : false, /* isEliminatable. Not relevant for setters. */
230 : false, /* isAlwaysInSlot. Only relevant for getters. */
231 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
232 : false, /* isTypedMethod. Only relevant for methods. */
233 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
234 : };
235 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
236 : static_assert(0 < 1, "There is no slot for us");
237 :
238 : static bool
239 0 : get_matches(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryListEvent* self, JSJitGetterCallArgs args)
240 : {
241 0 : bool result(self->Matches());
242 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
243 0 : args.rval().setBoolean(result);
244 0 : return true;
245 : }
246 :
247 : static const JSJitInfo matches_getterinfo = {
248 : { (JSJitGetterOp)get_matches },
249 : { prototypes::id::MediaQueryListEvent },
250 : { PrototypeTraits<prototypes::id::MediaQueryListEvent>::Depth },
251 : JSJitInfo::Getter,
252 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
253 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
254 : true, /* isInfallible. False in setters. */
255 : false, /* isMovable. Not relevant for setters. */
256 : false, /* isEliminatable. Not relevant for setters. */
257 : false, /* isAlwaysInSlot. Only relevant for getters. */
258 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
259 : false, /* isTypedMethod. Only relevant for methods. */
260 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
261 : };
262 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
263 : static_assert(0 < 1, "There is no slot for us");
264 :
265 : static bool
266 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaQueryListEvent* self, JSJitGetterCallArgs args)
267 : {
268 0 : bool result(self->IsTrusted());
269 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
270 0 : args.rval().setBoolean(result);
271 0 : return true;
272 : }
273 :
274 : static const JSJitInfo isTrusted_getterinfo = {
275 : { (JSJitGetterOp)get_isTrusted },
276 : { prototypes::id::MediaQueryListEvent },
277 : { PrototypeTraits<prototypes::id::MediaQueryListEvent>::Depth },
278 : JSJitInfo::Getter,
279 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
280 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
281 : true, /* isInfallible. False in setters. */
282 : true, /* isMovable. Not relevant for setters. */
283 : true, /* isEliminatable. Not relevant for setters. */
284 : false, /* isAlwaysInSlot. Only relevant for getters. */
285 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
286 : false, /* isTypedMethod. Only relevant for methods. */
287 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
288 : };
289 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
290 : static_assert(0 < 1, "There is no slot for us");
291 :
292 : static bool
293 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
294 : {
295 0 : mozilla::dom::MediaQueryListEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaQueryListEvent>(obj);
296 : // We don't want to preserve if we don't have a wrapper, and we
297 : // obviously can't preserve if we're not initialized.
298 0 : if (self && self->GetWrapperPreserveColor()) {
299 0 : PreserveWrapper(self);
300 : }
301 0 : return true;
302 : }
303 :
304 : static void
305 0 : _finalize(js::FreeOp* fop, JSObject* obj)
306 : {
307 0 : mozilla::dom::MediaQueryListEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaQueryListEvent>(obj);
308 0 : if (self) {
309 0 : ClearWrapper(self, self, obj);
310 0 : AddForDeferredFinalization<mozilla::dom::MediaQueryListEvent>(self);
311 : }
312 0 : }
313 :
314 : static void
315 0 : _objectMoved(JSObject* obj, const JSObject* old)
316 : {
317 0 : mozilla::dom::MediaQueryListEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaQueryListEvent>(obj);
318 0 : if (self) {
319 0 : UpdateWrapper(self, self, obj, old);
320 : }
321 0 : }
322 :
323 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
324 : #if defined(__clang__)
325 : #pragma clang diagnostic push
326 : #pragma clang diagnostic ignored "-Wmissing-braces"
327 : #endif
328 : static const JSPropertySpec sAttributes_specs[] = {
329 : { "media", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &media_getterinfo, nullptr, nullptr },
330 : { "matches", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &matches_getterinfo, nullptr, nullptr },
331 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
332 : };
333 : #if defined(__clang__)
334 : #pragma clang diagnostic pop
335 : #endif
336 :
337 :
338 : // Can't be const because the pref-enabled boolean needs to be writable
339 : static Prefable<const JSPropertySpec> sAttributes[] = {
340 : { nullptr, &sAttributes_specs[0] },
341 : { nullptr, nullptr }
342 : };
343 :
344 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
345 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
346 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
347 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
348 :
349 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
350 : #if defined(__clang__)
351 : #pragma clang diagnostic push
352 : #pragma clang diagnostic ignored "-Wmissing-braces"
353 : #endif
354 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
355 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
356 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
357 : };
358 : #if defined(__clang__)
359 : #pragma clang diagnostic pop
360 : #endif
361 :
362 :
363 : // Can't be const because the pref-enabled boolean needs to be writable
364 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
365 : { nullptr, &sUnforgeableAttributes_specs[0] },
366 : { nullptr, nullptr }
367 : };
368 :
369 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
370 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
371 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
372 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
373 :
374 :
375 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
376 : static PropertyInfo sNativeProperties_propertyInfos[3];
377 :
378 : static const NativePropertiesN<2> sNativeProperties = {
379 : false, 0,
380 : false, 0,
381 : false, 0,
382 : true, 0 /* sAttributes */,
383 : false, 0,
384 : true, 1 /* sUnforgeableAttributes */,
385 : false, 0,
386 : -1,
387 : 3,
388 : sNativeProperties_sortedPropertyIndices,
389 : {
390 : { sAttributes, &sNativeProperties_propertyInfos[0] },
391 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[2] }
392 : }
393 : };
394 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
395 : "We have a property info count that is oversized");
396 :
397 : static bool
398 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
399 : {
400 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
401 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
402 0 : if (!args.isConstructing()) {
403 : // XXXbz wish I could get the name from the callee instead of
404 : // Adding more relocations
405 0 : return ThrowConstructorWithoutNew(cx, "MediaQueryListEvent");
406 : }
407 :
408 0 : GlobalObject global(cx, obj);
409 0 : if (global.Failed()) {
410 0 : return false;
411 : }
412 :
413 0 : JS::Rooted<JSObject*> desiredProto(cx);
414 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
415 0 : return false;
416 : }
417 :
418 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
419 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaQueryListEvent");
420 : }
421 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
422 0 : binding_detail::FakeString arg0;
423 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
424 0 : return false;
425 : }
426 0 : binding_detail::FastMediaQueryListEventInit arg1;
427 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of MediaQueryListEvent.constructor", false)) {
428 0 : return false;
429 : }
430 0 : Maybe<JSAutoCompartment> ac;
431 0 : if (objIsXray) {
432 0 : obj = js::CheckedUnwrap(obj);
433 0 : if (!obj) {
434 0 : return false;
435 : }
436 0 : ac.emplace(cx, obj);
437 0 : if (!JS_WrapObject(cx, &desiredProto)) {
438 0 : return false;
439 : }
440 : }
441 0 : binding_detail::FastErrorResult rv;
442 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaQueryListEvent>(mozilla::dom::MediaQueryListEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
443 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
444 0 : return false;
445 : }
446 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
447 : static_assert(!IsPointer<decltype(result)>::value,
448 : "NewObject implies that we need to keep the object alive with a strong reference.");
449 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
450 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
451 0 : return false;
452 : }
453 0 : return true;
454 : }
455 :
456 : static const js::ClassOps sInterfaceObjectClassOps = {
457 : nullptr, /* addProperty */
458 : nullptr, /* delProperty */
459 : nullptr, /* getProperty */
460 : nullptr, /* setProperty */
461 : nullptr, /* enumerate */
462 : nullptr, /* newEnumerate */
463 : nullptr, /* resolve */
464 : nullptr, /* mayResolve */
465 : nullptr, /* finalize */
466 : _constructor, /* call */
467 : nullptr, /* hasInstance */
468 : _constructor, /* construct */
469 : nullptr, /* trace */
470 : };
471 :
472 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
473 : {
474 : "Function",
475 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
476 : &sInterfaceObjectClassOps,
477 : JS_NULL_CLASS_SPEC,
478 : JS_NULL_CLASS_EXT,
479 : &sInterfaceObjectClassObjectOps
480 : },
481 : eInterface,
482 : true,
483 : prototypes::id::MediaQueryListEvent,
484 : PrototypeTraits<prototypes::id::MediaQueryListEvent>::Depth,
485 : sNativePropertyHooks,
486 : "function MediaQueryListEvent() {\n [native code]\n}",
487 : EventBinding::GetConstructorObject
488 : };
489 :
490 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
491 : {
492 : "MediaQueryListEventPrototype",
493 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
494 : JS_NULL_CLASS_OPS,
495 : JS_NULL_CLASS_SPEC,
496 : JS_NULL_CLASS_EXT,
497 : JS_NULL_OBJECT_OPS
498 : },
499 : eInterfacePrototype,
500 : false,
501 : prototypes::id::MediaQueryListEvent,
502 : PrototypeTraits<prototypes::id::MediaQueryListEvent>::Depth,
503 : sNativePropertyHooks,
504 : "[object MediaQueryListEventPrototype]",
505 : EventBinding::GetProtoObject
506 : };
507 :
508 : JSObject*
509 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
510 : {
511 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
512 : }
513 :
514 : static const js::ClassOps sClassOps = {
515 : _addProperty, /* addProperty */
516 : nullptr, /* delProperty */
517 : nullptr, /* getProperty */
518 : nullptr, /* setProperty */
519 : nullptr, /* enumerate */
520 : nullptr, /* newEnumerate */
521 : nullptr, /* resolve */
522 : nullptr, /* mayResolve */
523 : _finalize, /* finalize */
524 : nullptr, /* call */
525 : nullptr, /* hasInstance */
526 : nullptr, /* construct */
527 : nullptr, /* trace */
528 : };
529 :
530 : static const js::ClassExtension sClassExtension = {
531 : nullptr, /* weakmapKeyDelegateOp */
532 : _objectMoved /* objectMovedOp */
533 : };
534 :
535 : static const DOMJSClass sClass = {
536 : { "MediaQueryListEvent",
537 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
538 : &sClassOps,
539 : JS_NULL_CLASS_SPEC,
540 : &sClassExtension,
541 : JS_NULL_OBJECT_OPS
542 : },
543 : { prototypes::id::Event, prototypes::id::MediaQueryListEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
544 : IsBaseOf<nsISupports, mozilla::dom::MediaQueryListEvent >::value,
545 : sNativePropertyHooks,
546 : FindAssociatedGlobalForNative<mozilla::dom::MediaQueryListEvent>::Get,
547 : GetProtoObjectHandle,
548 : GetCCParticipant<mozilla::dom::MediaQueryListEvent>::Get()
549 : };
550 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
551 : "Must have the right minimal number of reserved slots.");
552 : static_assert(1 >= 1,
553 : "Must have enough reserved slots.");
554 :
555 : const JSClass*
556 0 : GetJSClass()
557 : {
558 0 : return sClass.ToJSClass();
559 : }
560 :
561 : bool
562 0 : Wrap(JSContext* aCx, mozilla::dom::MediaQueryListEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
563 : {
564 : MOZ_ASSERT(static_cast<mozilla::dom::MediaQueryListEvent*>(aObject) ==
565 : reinterpret_cast<mozilla::dom::MediaQueryListEvent*>(aObject),
566 : "Multiple inheritance for mozilla::dom::MediaQueryListEvent is broken.");
567 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
568 : reinterpret_cast<mozilla::dom::Event*>(aObject),
569 : "Multiple inheritance for mozilla::dom::Event is broken.");
570 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
571 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
572 0 : MOZ_ASSERT(!aCache->GetWrapper(),
573 : "You should probably not be using Wrap() directly; use "
574 : "GetOrCreateDOMReflector instead");
575 :
576 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
577 : "nsISupports must be on our primary inheritance chain");
578 :
579 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
580 0 : if (!global) {
581 0 : return false;
582 : }
583 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
584 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
585 :
586 : // That might have ended up wrapping us already, due to the wonders
587 : // of XBL. Check for that, and bail out as needed.
588 0 : aReflector.set(aCache->GetWrapper());
589 0 : if (aReflector) {
590 : #ifdef DEBUG
591 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
592 : #endif // DEBUG
593 0 : return true;
594 : }
595 :
596 0 : JSAutoCompartment ac(aCx, global);
597 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
598 0 : if (!canonicalProto) {
599 0 : return false;
600 : }
601 0 : JS::Rooted<JSObject*> proto(aCx);
602 0 : if (aGivenProto) {
603 0 : proto = aGivenProto;
604 : // Unfortunately, while aGivenProto was in the compartment of aCx
605 : // coming in, we changed compartments to that of "parent" so may need
606 : // to wrap the proto here.
607 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
608 0 : if (!JS_WrapObject(aCx, &proto)) {
609 0 : return false;
610 : }
611 : }
612 : } else {
613 0 : proto = canonicalProto;
614 : }
615 :
616 0 : BindingJSObjectCreator<mozilla::dom::MediaQueryListEvent> creator(aCx);
617 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
618 0 : if (!aReflector) {
619 0 : return false;
620 : }
621 :
622 0 : aCache->SetWrapper(aReflector);
623 :
624 : // Important: do unforgeable property setup after we have handed
625 : // over ownership of the C++ object to obj as needed, so that if
626 : // we fail and it ends up GCed it won't have problems in the
627 : // finalizer trying to drop its ownership of the C++ object.
628 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
629 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
630 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
631 0 : aCache->ReleaseWrapper(aObject);
632 0 : aCache->ClearWrapper();
633 0 : return false;
634 : }
635 0 : creator.InitializationSucceeded();
636 :
637 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
638 : aCache->GetWrapperPreserveColor() == aReflector);
639 : // If proto != canonicalProto, we have to preserve our wrapper;
640 : // otherwise we won't be able to properly recreate it later, since
641 : // we won't know what proto to use. Note that we don't check
642 : // aGivenProto here, since it's entirely possible (and even
643 : // somewhat common) to have a non-null aGivenProto which is the
644 : // same as canonicalProto.
645 0 : if (proto != canonicalProto) {
646 0 : PreserveWrapper(aObject);
647 : }
648 :
649 0 : return true;
650 : }
651 :
652 : const NativePropertyHooks sNativePropertyHooks[] = { {
653 : nullptr,
654 : nullptr,
655 : nullptr,
656 : { sNativeProperties.Upcast(), nullptr },
657 : prototypes::id::MediaQueryListEvent,
658 : constructors::id::MediaQueryListEvent,
659 : EventBinding::sNativePropertyHooks,
660 : &DefaultXrayExpandoObjectClass
661 : } };
662 :
663 : void
664 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
665 : {
666 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
667 0 : if (!parentProto) {
668 0 : return;
669 : }
670 :
671 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
672 0 : if (!constructorProto) {
673 0 : return;
674 : }
675 :
676 : static bool sIdsInited = false;
677 0 : if (!sIdsInited && NS_IsMainThread()) {
678 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
679 0 : return;
680 : }
681 0 : sIdsInited = true;
682 : }
683 :
684 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaQueryListEvent);
685 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaQueryListEvent);
686 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
687 : &sPrototypeClass.mBase, protoCache,
688 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
689 : interfaceCache,
690 : sNativeProperties.Upcast(),
691 : nullptr,
692 : "MediaQueryListEvent", aDefineOnGlobal,
693 : nullptr,
694 0 : false);
695 :
696 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
697 : {
698 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
699 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
700 0 : if (!unforgeableHolder) {
701 0 : *protoCache = nullptr;
702 0 : if (interfaceCache) {
703 0 : *interfaceCache = nullptr;
704 : }
705 0 : return;
706 : }
707 : }
708 :
709 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
710 0 : *protoCache = nullptr;
711 0 : if (interfaceCache) {
712 0 : *interfaceCache = nullptr;
713 : }
714 0 : return;
715 : }
716 :
717 0 : if (*protoCache) {
718 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
719 0 : JS::ObjectValue(*unforgeableHolder));
720 : }
721 : }
722 :
723 : JS::Handle<JSObject*>
724 0 : GetProtoObjectHandle(JSContext* aCx)
725 : {
726 : /* Get the interface prototype object for this class. This will create the
727 : object as needed. */
728 0 : bool aDefineOnGlobal = true;
729 :
730 : /* Make sure our global is sane. Hopefully we can remove this sometime */
731 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
732 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
733 0 : return nullptr;
734 : }
735 :
736 : /* Check to see whether the interface objects are already installed */
737 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
738 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MediaQueryListEvent)) {
739 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
740 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
741 : }
742 :
743 : /*
744 : * The object might _still_ be null, but that's OK.
745 : *
746 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
747 : * traced by TraceProtoAndIfaceCache() and its contents are never
748 : * changed after they have been set.
749 : *
750 : * Calling address() avoids the read read barrier that does gray
751 : * unmarking, but it's not possible for the object to be gray here.
752 : */
753 :
754 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MediaQueryListEvent);
755 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
756 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
757 : }
758 :
759 : JS::Handle<JSObject*>
760 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
761 : {
762 : /* Get the interface object for this class. This will create the object as
763 : needed. */
764 :
765 : /* Make sure our global is sane. Hopefully we can remove this sometime */
766 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
767 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
768 0 : return nullptr;
769 : }
770 :
771 : /* Check to see whether the interface objects are already installed */
772 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
773 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MediaQueryListEvent)) {
774 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
775 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
776 : }
777 :
778 : /*
779 : * The object might _still_ be null, but that's OK.
780 : *
781 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
782 : * traced by TraceProtoAndIfaceCache() and its contents are never
783 : * changed after they have been set.
784 : *
785 : * Calling address() avoids the read read barrier that does gray
786 : * unmarking, but it's not possible for the object to be gray here.
787 : */
788 :
789 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MediaQueryListEvent);
790 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
791 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
792 : }
793 :
794 : JSObject*
795 0 : GetConstructorObject(JSContext* aCx)
796 : {
797 0 : return GetConstructorObjectHandle(aCx);
798 : }
799 :
800 : } // namespace MediaQueryListEventBinding
801 :
802 :
803 :
804 : } // namespace dom
805 : } // namespace mozilla
|