Coverage Report

Created: 2018-09-25 14:53

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