Coverage Report

Created: 2018-09-25 14:53

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