Coverage Report

Created: 2018-09-25 14:53

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