Coverage Report

Created: 2018-09-25 14:53

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