Coverage Report

Created: 2018-09-25 14:53

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