Coverage Report

Created: 2018-09-25 14:53

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