Coverage Report

Created: 2018-09-25 14:53

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