Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/DeviceMotionEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM DeviceMotionEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "DeviceMotionEventBinding.h"
5
#include "EventBinding.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/DeviceMotionEvent.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/Nullable.h"
15
#include "mozilla/dom/PrimitiveConversions.h"
16
#include "mozilla/dom/ScriptSettings.h"
17
#include "mozilla/dom/SimpleGlobalObject.h"
18
#include "mozilla/dom/XrayExpandoClass.h"
19
#include "nsGlobalWindowInner.h"
20
21
namespace mozilla {
22
namespace dom {
23
24
namespace binding_detail {}; // Just to make sure it's known as a namespace
25
using namespace mozilla::dom::binding_detail;
26
27
28
29
DeviceAccelerationInit::DeviceAccelerationInit()
30
0
{
31
0
  // Safe to pass a null context if we pass a null value
32
0
  Init(nullptr, JS::NullHandleValue);
33
0
}
34
35
36
37
bool
38
DeviceAccelerationInit::InitIds(JSContext* cx, DeviceAccelerationInitAtoms* atomsCache)
39
0
{
40
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
41
0
42
0
  // Initialize these in reverse order so that any failure leaves the first one
43
0
  // uninitialized.
44
0
  if (!atomsCache->z_id.init(cx, "z") ||
45
0
      !atomsCache->y_id.init(cx, "y") ||
46
0
      !atomsCache->x_id.init(cx, "x")) {
47
0
    return false;
48
0
  }
49
0
  return true;
50
0
}
51
52
bool
53
DeviceAccelerationInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
54
0
{
55
0
  // Passing a null JSContext is OK only if we're initing from null,
56
0
  // Since in that case we will not have to do any property gets
57
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
58
0
  // checkers by static analysis tools
59
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
60
0
  DeviceAccelerationInitAtoms* atomsCache = nullptr;
61
0
  if (cx) {
62
0
    atomsCache = GetAtomCache<DeviceAccelerationInitAtoms>(cx);
63
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
64
0
      return false;
65
0
    }
66
0
  }
67
0
68
0
  if (!IsConvertibleToDictionary(val)) {
69
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
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->x_id, temp.ptr())) {
83
0
      return false;
84
0
    }
85
0
  }
86
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
87
0
    mX.SetNull();
88
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mX.SetValue())) {
89
0
    return false;
90
0
  } else if (!mozilla::IsFinite(mX.Value())) {
91
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'x' member of DeviceAccelerationInit");
92
0
    return false;
93
0
  }
94
0
  mIsAnyMemberPresent = true;
95
0
96
0
  if (!isNull) {
97
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->y_id, temp.ptr())) {
98
0
      return false;
99
0
    }
100
0
  }
101
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
102
0
    mY.SetNull();
103
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mY.SetValue())) {
104
0
    return false;
105
0
  } else if (!mozilla::IsFinite(mY.Value())) {
106
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'y' member of DeviceAccelerationInit");
107
0
    return false;
108
0
  }
109
0
  mIsAnyMemberPresent = true;
110
0
111
0
  if (!isNull) {
112
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->z_id, temp.ptr())) {
113
0
      return false;
114
0
    }
115
0
  }
116
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
117
0
    mZ.SetNull();
118
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mZ.SetValue())) {
119
0
    return false;
120
0
  } else if (!mozilla::IsFinite(mZ.Value())) {
121
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'z' member of DeviceAccelerationInit");
122
0
    return false;
123
0
  }
124
0
  mIsAnyMemberPresent = true;
125
0
  return true;
126
0
}
127
128
bool
129
DeviceAccelerationInit::Init(const nsAString& aJSON)
130
0
{
131
0
  AutoJSAPI jsapi;
132
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
133
0
  if (!cleanGlobal) {
134
0
    return false;
135
0
  }
136
0
  if (!jsapi.Init(cleanGlobal)) {
137
0
    return false;
138
0
  }
139
0
  JSContext* cx = jsapi.cx();
140
0
  JS::Rooted<JS::Value> json(cx);
141
0
  bool ok = ParseJSON(cx, aJSON, &json);
142
0
  NS_ENSURE_TRUE(ok, false);
143
0
  return Init(cx, json);
144
0
}
145
146
bool
147
DeviceAccelerationInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
148
0
{
149
0
  DeviceAccelerationInitAtoms* atomsCache = GetAtomCache<DeviceAccelerationInitAtoms>(cx);
150
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
151
0
    return false;
152
0
  }
153
0
154
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
155
0
  if (!obj) {
156
0
    return false;
157
0
  }
158
0
  rval.set(JS::ObjectValue(*obj));
159
0
160
0
  do {
161
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
162
0
    JS::Rooted<JS::Value> temp(cx);
163
0
    Nullable<double> const & currentValue = mX;
164
0
    if (currentValue.IsNull()) {
165
0
      temp.setNull();
166
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->x_id, temp, JSPROP_ENUMERATE)) {
167
0
        return false;
168
0
      }
169
0
      break;
170
0
    }
171
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
172
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->x_id, temp, JSPROP_ENUMERATE)) {
173
0
      return false;
174
0
    }
175
0
    break;
176
0
  } while(false);
177
0
178
0
  do {
179
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
180
0
    JS::Rooted<JS::Value> temp(cx);
181
0
    Nullable<double> const & currentValue = mY;
182
0
    if (currentValue.IsNull()) {
183
0
      temp.setNull();
184
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->y_id, temp, JSPROP_ENUMERATE)) {
185
0
        return false;
186
0
      }
187
0
      break;
188
0
    }
189
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
190
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->y_id, temp, JSPROP_ENUMERATE)) {
191
0
      return false;
192
0
    }
193
0
    break;
194
0
  } while(false);
195
0
196
0
  do {
197
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
198
0
    JS::Rooted<JS::Value> temp(cx);
199
0
    Nullable<double> const & currentValue = mZ;
200
0
    if (currentValue.IsNull()) {
201
0
      temp.setNull();
202
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->z_id, temp, JSPROP_ENUMERATE)) {
203
0
        return false;
204
0
      }
205
0
      break;
206
0
    }
207
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
208
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->z_id, temp, JSPROP_ENUMERATE)) {
209
0
      return false;
210
0
    }
211
0
    break;
212
0
  } while(false);
213
0
214
0
  return true;
215
0
}
216
217
bool
218
DeviceAccelerationInit::ToJSON(nsAString& aJSON) const
219
0
{
220
0
  AutoJSAPI jsapi;
221
0
  jsapi.Init();
222
0
  JSContext *cx = jsapi.cx();
223
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
224
0
  // because we'll only be creating objects, in ways that have no
225
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
226
0
  // which likewise guarantees no side-effects for the sorts of
227
0
  // things we will pass it.
228
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
229
0
  JS::Rooted<JS::Value> val(cx);
230
0
  if (!ToObjectInternal(cx, &val)) {
231
0
    return false;
232
0
  }
233
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
234
0
  return StringifyToJSON(cx, obj, aJSON);
235
0
}
236
237
void
238
DeviceAccelerationInit::TraceDictionary(JSTracer* trc)
239
0
{
240
0
}
241
242
DeviceAccelerationInit&
243
DeviceAccelerationInit::operator=(const DeviceAccelerationInit& aOther)
244
0
{
245
0
  DictionaryBase::operator=(aOther);
246
0
  mX = aOther.mX;
247
0
  mY = aOther.mY;
248
0
  mZ = aOther.mZ;
249
0
  return *this;
250
0
}
251
252
namespace binding_detail {
253
} // namespace binding_detail
254
255
256
257
DeviceRotationRateInit::DeviceRotationRateInit()
258
0
{
259
0
  // Safe to pass a null context if we pass a null value
260
0
  Init(nullptr, JS::NullHandleValue);
261
0
}
262
263
264
265
bool
266
DeviceRotationRateInit::InitIds(JSContext* cx, DeviceRotationRateInitAtoms* atomsCache)
267
0
{
268
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
269
0
270
0
  // Initialize these in reverse order so that any failure leaves the first one
271
0
  // uninitialized.
272
0
  if (!atomsCache->gamma_id.init(cx, "gamma") ||
273
0
      !atomsCache->beta_id.init(cx, "beta") ||
274
0
      !atomsCache->alpha_id.init(cx, "alpha")) {
275
0
    return false;
276
0
  }
277
0
  return true;
278
0
}
279
280
bool
281
DeviceRotationRateInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
282
0
{
283
0
  // Passing a null JSContext is OK only if we're initing from null,
284
0
  // Since in that case we will not have to do any property gets
285
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
286
0
  // checkers by static analysis tools
287
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
288
0
  DeviceRotationRateInitAtoms* atomsCache = nullptr;
289
0
  if (cx) {
290
0
    atomsCache = GetAtomCache<DeviceRotationRateInitAtoms>(cx);
291
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
292
0
      return false;
293
0
    }
294
0
  }
295
0
296
0
  if (!IsConvertibleToDictionary(val)) {
297
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
298
0
  }
299
0
300
0
  bool isNull = val.isNullOrUndefined();
301
0
  // We only need these if !isNull, in which case we have |cx|.
302
0
  Maybe<JS::Rooted<JSObject *> > object;
303
0
  Maybe<JS::Rooted<JS::Value> > temp;
304
0
  if (!isNull) {
305
0
    MOZ_ASSERT(cx);
306
0
    object.emplace(cx, &val.toObject());
307
0
    temp.emplace(cx);
308
0
  }
309
0
  if (!isNull) {
310
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->alpha_id, temp.ptr())) {
311
0
      return false;
312
0
    }
313
0
  }
314
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
315
0
    mAlpha.SetNull();
316
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mAlpha.SetValue())) {
317
0
    return false;
318
0
  } else if (!mozilla::IsFinite(mAlpha.Value())) {
319
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'alpha' member of DeviceRotationRateInit");
320
0
    return false;
321
0
  }
322
0
  mIsAnyMemberPresent = true;
323
0
324
0
  if (!isNull) {
325
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->beta_id, temp.ptr())) {
326
0
      return false;
327
0
    }
328
0
  }
329
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
330
0
    mBeta.SetNull();
331
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mBeta.SetValue())) {
332
0
    return false;
333
0
  } else if (!mozilla::IsFinite(mBeta.Value())) {
334
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'beta' member of DeviceRotationRateInit");
335
0
    return false;
336
0
  }
337
0
  mIsAnyMemberPresent = true;
338
0
339
0
  if (!isNull) {
340
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->gamma_id, temp.ptr())) {
341
0
      return false;
342
0
    }
343
0
  }
344
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
345
0
    mGamma.SetNull();
346
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mGamma.SetValue())) {
347
0
    return false;
348
0
  } else if (!mozilla::IsFinite(mGamma.Value())) {
349
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'gamma' member of DeviceRotationRateInit");
350
0
    return false;
351
0
  }
352
0
  mIsAnyMemberPresent = true;
353
0
  return true;
354
0
}
355
356
bool
357
DeviceRotationRateInit::Init(const nsAString& aJSON)
358
0
{
359
0
  AutoJSAPI jsapi;
360
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
361
0
  if (!cleanGlobal) {
362
0
    return false;
363
0
  }
364
0
  if (!jsapi.Init(cleanGlobal)) {
365
0
    return false;
366
0
  }
367
0
  JSContext* cx = jsapi.cx();
368
0
  JS::Rooted<JS::Value> json(cx);
369
0
  bool ok = ParseJSON(cx, aJSON, &json);
370
0
  NS_ENSURE_TRUE(ok, false);
371
0
  return Init(cx, json);
372
0
}
373
374
bool
375
DeviceRotationRateInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
376
0
{
377
0
  DeviceRotationRateInitAtoms* atomsCache = GetAtomCache<DeviceRotationRateInitAtoms>(cx);
378
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
379
0
    return false;
380
0
  }
381
0
382
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
383
0
  if (!obj) {
384
0
    return false;
385
0
  }
386
0
  rval.set(JS::ObjectValue(*obj));
387
0
388
0
  do {
389
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
390
0
    JS::Rooted<JS::Value> temp(cx);
391
0
    Nullable<double> const & currentValue = mAlpha;
392
0
    if (currentValue.IsNull()) {
393
0
      temp.setNull();
394
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->alpha_id, temp, JSPROP_ENUMERATE)) {
395
0
        return false;
396
0
      }
397
0
      break;
398
0
    }
399
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
400
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->alpha_id, temp, JSPROP_ENUMERATE)) {
401
0
      return false;
402
0
    }
403
0
    break;
404
0
  } while(false);
405
0
406
0
  do {
407
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
408
0
    JS::Rooted<JS::Value> temp(cx);
409
0
    Nullable<double> const & currentValue = mBeta;
410
0
    if (currentValue.IsNull()) {
411
0
      temp.setNull();
412
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->beta_id, temp, JSPROP_ENUMERATE)) {
413
0
        return false;
414
0
      }
415
0
      break;
416
0
    }
417
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
418
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->beta_id, temp, JSPROP_ENUMERATE)) {
419
0
      return false;
420
0
    }
421
0
    break;
422
0
  } while(false);
423
0
424
0
  do {
425
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
426
0
    JS::Rooted<JS::Value> temp(cx);
427
0
    Nullable<double> const & currentValue = mGamma;
428
0
    if (currentValue.IsNull()) {
429
0
      temp.setNull();
430
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->gamma_id, temp, JSPROP_ENUMERATE)) {
431
0
        return false;
432
0
      }
433
0
      break;
434
0
    }
435
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
436
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->gamma_id, temp, JSPROP_ENUMERATE)) {
437
0
      return false;
438
0
    }
439
0
    break;
440
0
  } while(false);
441
0
442
0
  return true;
443
0
}
444
445
bool
446
DeviceRotationRateInit::ToJSON(nsAString& aJSON) const
447
0
{
448
0
  AutoJSAPI jsapi;
449
0
  jsapi.Init();
450
0
  JSContext *cx = jsapi.cx();
451
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
452
0
  // because we'll only be creating objects, in ways that have no
453
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
454
0
  // which likewise guarantees no side-effects for the sorts of
455
0
  // things we will pass it.
456
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
457
0
  JS::Rooted<JS::Value> val(cx);
458
0
  if (!ToObjectInternal(cx, &val)) {
459
0
    return false;
460
0
  }
461
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
462
0
  return StringifyToJSON(cx, obj, aJSON);
463
0
}
464
465
void
466
DeviceRotationRateInit::TraceDictionary(JSTracer* trc)
467
0
{
468
0
}
469
470
DeviceRotationRateInit&
471
DeviceRotationRateInit::operator=(const DeviceRotationRateInit& aOther)
472
0
{
473
0
  DictionaryBase::operator=(aOther);
474
0
  mAlpha = aOther.mAlpha;
475
0
  mBeta = aOther.mBeta;
476
0
  mGamma = aOther.mGamma;
477
0
  return *this;
478
0
}
479
480
namespace binding_detail {
481
} // namespace binding_detail
482
483
484
485
DeviceMotionEventInit::DeviceMotionEventInit()
486
  : EventInit(FastDictionaryInitializer()),
487
    mAcceleration(FastDictionaryInitializer()),
488
    mAccelerationIncludingGravity(FastDictionaryInitializer()),
489
    mRotationRate(FastDictionaryInitializer())
490
0
{
491
0
  // Safe to pass a null context if we pass a null value
492
0
  Init(nullptr, JS::NullHandleValue);
493
0
}
494
495
496
497
bool
498
DeviceMotionEventInit::InitIds(JSContext* cx, DeviceMotionEventInitAtoms* atomsCache)
499
0
{
500
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
501
0
502
0
  // Initialize these in reverse order so that any failure leaves the first one
503
0
  // uninitialized.
504
0
  if (!atomsCache->rotationRate_id.init(cx, "rotationRate") ||
505
0
      !atomsCache->interval_id.init(cx, "interval") ||
506
0
      !atomsCache->accelerationIncludingGravity_id.init(cx, "accelerationIncludingGravity") ||
507
0
      !atomsCache->acceleration_id.init(cx, "acceleration")) {
508
0
    return false;
509
0
  }
510
0
  return true;
511
0
}
512
513
bool
514
DeviceMotionEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
515
0
{
516
0
  // Passing a null JSContext is OK only if we're initing from null,
517
0
  // Since in that case we will not have to do any property gets
518
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
519
0
  // checkers by static analysis tools
520
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
521
0
  DeviceMotionEventInitAtoms* atomsCache = nullptr;
522
0
  if (cx) {
523
0
    atomsCache = GetAtomCache<DeviceMotionEventInitAtoms>(cx);
524
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
525
0
      return false;
526
0
    }
527
0
  }
528
0
529
0
  // Per spec, we init the parent's members first
530
0
  if (!EventInit::Init(cx, val)) {
531
0
    return false;
532
0
  }
533
0
534
0
  bool isNull = val.isNullOrUndefined();
535
0
  // We only need these if !isNull, in which case we have |cx|.
536
0
  Maybe<JS::Rooted<JSObject *> > object;
537
0
  Maybe<JS::Rooted<JS::Value> > temp;
538
0
  if (!isNull) {
539
0
    MOZ_ASSERT(cx);
540
0
    object.emplace(cx, &val.toObject());
541
0
    temp.emplace(cx);
542
0
  }
543
0
  if (!isNull) {
544
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->acceleration_id, temp.ptr())) {
545
0
      return false;
546
0
    }
547
0
  }
548
0
  if (!mAcceleration.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'acceleration' member of DeviceMotionEventInit", passedToJSImpl)) {
549
0
    return false;
550
0
  }
551
0
  mIsAnyMemberPresent = true;
552
0
553
0
  if (!isNull) {
554
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->accelerationIncludingGravity_id, temp.ptr())) {
555
0
      return false;
556
0
    }
557
0
  }
558
0
  if (!mAccelerationIncludingGravity.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'accelerationIncludingGravity' member of DeviceMotionEventInit", passedToJSImpl)) {
559
0
    return false;
560
0
  }
561
0
  mIsAnyMemberPresent = true;
562
0
563
0
  if (!isNull) {
564
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->interval_id, temp.ptr())) {
565
0
      return false;
566
0
    }
567
0
  }
568
0
  if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
569
0
    mInterval.SetNull();
570
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mInterval.SetValue())) {
571
0
    return false;
572
0
  } else if (!mozilla::IsFinite(mInterval.Value())) {
573
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "'interval' member of DeviceMotionEventInit");
574
0
    return false;
575
0
  }
576
0
  mIsAnyMemberPresent = true;
577
0
578
0
  if (!isNull) {
579
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->rotationRate_id, temp.ptr())) {
580
0
      return false;
581
0
    }
582
0
  }
583
0
  if (!mRotationRate.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'rotationRate' member of DeviceMotionEventInit", passedToJSImpl)) {
584
0
    return false;
585
0
  }
586
0
  mIsAnyMemberPresent = true;
587
0
  return true;
588
0
}
589
590
bool
591
DeviceMotionEventInit::Init(const nsAString& aJSON)
592
0
{
593
0
  AutoJSAPI jsapi;
594
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
595
0
  if (!cleanGlobal) {
596
0
    return false;
597
0
  }
598
0
  if (!jsapi.Init(cleanGlobal)) {
599
0
    return false;
600
0
  }
601
0
  JSContext* cx = jsapi.cx();
602
0
  JS::Rooted<JS::Value> json(cx);
603
0
  bool ok = ParseJSON(cx, aJSON, &json);
604
0
  NS_ENSURE_TRUE(ok, false);
605
0
  return Init(cx, json);
606
0
}
607
608
bool
609
DeviceMotionEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
610
0
{
611
0
  DeviceMotionEventInitAtoms* atomsCache = GetAtomCache<DeviceMotionEventInitAtoms>(cx);
612
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
613
0
    return false;
614
0
  }
615
0
616
0
  // Per spec, we define the parent's members first
617
0
  if (!EventInit::ToObjectInternal(cx, rval)) {
618
0
    return false;
619
0
  }
620
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
621
0
622
0
  do {
623
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
624
0
    JS::Rooted<JS::Value> temp(cx);
625
0
    DeviceAccelerationInit const & currentValue = mAcceleration;
626
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
627
0
      return false;
628
0
    }
629
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->acceleration_id, temp, JSPROP_ENUMERATE)) {
630
0
      return false;
631
0
    }
632
0
    break;
633
0
  } while(false);
634
0
635
0
  do {
636
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
637
0
    JS::Rooted<JS::Value> temp(cx);
638
0
    DeviceAccelerationInit const & currentValue = mAccelerationIncludingGravity;
639
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
640
0
      return false;
641
0
    }
642
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->accelerationIncludingGravity_id, temp, JSPROP_ENUMERATE)) {
643
0
      return false;
644
0
    }
645
0
    break;
646
0
  } while(false);
647
0
648
0
  do {
649
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
650
0
    JS::Rooted<JS::Value> temp(cx);
651
0
    Nullable<double> const & currentValue = mInterval;
652
0
    if (currentValue.IsNull()) {
653
0
      temp.setNull();
654
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->interval_id, temp, JSPROP_ENUMERATE)) {
655
0
        return false;
656
0
      }
657
0
      break;
658
0
    }
659
0
    temp.set(JS_NumberValue(double(currentValue.Value())));
660
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->interval_id, temp, JSPROP_ENUMERATE)) {
661
0
      return false;
662
0
    }
663
0
    break;
664
0
  } while(false);
665
0
666
0
  do {
667
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
668
0
    JS::Rooted<JS::Value> temp(cx);
669
0
    DeviceRotationRateInit const & currentValue = mRotationRate;
670
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
671
0
      return false;
672
0
    }
673
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->rotationRate_id, temp, JSPROP_ENUMERATE)) {
674
0
      return false;
675
0
    }
676
0
    break;
677
0
  } while(false);
678
0
679
0
  return true;
680
0
}
681
682
bool
683
DeviceMotionEventInit::ToJSON(nsAString& aJSON) const
684
0
{
685
0
  AutoJSAPI jsapi;
686
0
  jsapi.Init();
687
0
  JSContext *cx = jsapi.cx();
688
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
689
0
  // because we'll only be creating objects, in ways that have no
690
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
691
0
  // which likewise guarantees no side-effects for the sorts of
692
0
  // things we will pass it.
693
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
694
0
  JS::Rooted<JS::Value> val(cx);
695
0
  if (!ToObjectInternal(cx, &val)) {
696
0
    return false;
697
0
  }
698
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
699
0
  return StringifyToJSON(cx, obj, aJSON);
700
0
}
701
702
void
703
DeviceMotionEventInit::TraceDictionary(JSTracer* trc)
704
0
{
705
0
  EventInit::TraceDictionary(trc);
706
0
}
707
708
DeviceMotionEventInit&
709
DeviceMotionEventInit::operator=(const DeviceMotionEventInit& aOther)
710
0
{
711
0
  EventInit::operator=(aOther);
712
0
  mAcceleration = aOther.mAcceleration;
713
0
  mAccelerationIncludingGravity = aOther.mAccelerationIncludingGravity;
714
0
  mInterval = aOther.mInterval;
715
0
  mRotationRate = aOther.mRotationRate;
716
0
  return *this;
717
0
}
718
719
namespace binding_detail {
720
} // namespace binding_detail
721
722
723
namespace DeviceAcceleration_Binding {
724
725
MOZ_CAN_RUN_SCRIPT static bool
726
get_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceAcceleration* self, JSJitGetterCallArgs args)
727
0
{
728
0
  AUTO_PROFILER_LABEL_FAST("get DeviceAcceleration.x", DOM, cx);
729
0
730
0
  Nullable<double> result(self->GetX());
731
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
732
0
  if (result.IsNull()) {
733
0
    args.rval().setNull();
734
0
    return true;
735
0
  }
736
0
  args.rval().set(JS_NumberValue(double(result.Value())));
737
0
  return true;
738
0
}
739
740
static const JSJitInfo x_getterinfo = {
741
  { (JSJitGetterOp)get_x },
742
  { prototypes::id::DeviceAcceleration },
743
  { PrototypeTraits<prototypes::id::DeviceAcceleration>::Depth },
744
  JSJitInfo::Getter,
745
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
746
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
747
  true,  /* isInfallible. False in setters. */
748
  false,  /* isMovable.  Not relevant for setters. */
749
  false, /* isEliminatable.  Not relevant for setters. */
750
  false, /* isAlwaysInSlot.  Only relevant for getters. */
751
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
752
  false,  /* isTypedMethod.  Only relevant for methods. */
753
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
754
};
755
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
756
static_assert(0 < 1, "There is no slot for us");
757
758
MOZ_CAN_RUN_SCRIPT static bool
759
get_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceAcceleration* self, JSJitGetterCallArgs args)
760
0
{
761
0
  AUTO_PROFILER_LABEL_FAST("get DeviceAcceleration.y", DOM, cx);
762
0
763
0
  Nullable<double> result(self->GetY());
764
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
765
0
  if (result.IsNull()) {
766
0
    args.rval().setNull();
767
0
    return true;
768
0
  }
769
0
  args.rval().set(JS_NumberValue(double(result.Value())));
770
0
  return true;
771
0
}
772
773
static const JSJitInfo y_getterinfo = {
774
  { (JSJitGetterOp)get_y },
775
  { prototypes::id::DeviceAcceleration },
776
  { PrototypeTraits<prototypes::id::DeviceAcceleration>::Depth },
777
  JSJitInfo::Getter,
778
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
779
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
780
  true,  /* isInfallible. False in setters. */
781
  false,  /* isMovable.  Not relevant for setters. */
782
  false, /* isEliminatable.  Not relevant for setters. */
783
  false, /* isAlwaysInSlot.  Only relevant for getters. */
784
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
785
  false,  /* isTypedMethod.  Only relevant for methods. */
786
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
787
};
788
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
789
static_assert(0 < 1, "There is no slot for us");
790
791
MOZ_CAN_RUN_SCRIPT static bool
792
get_z(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceAcceleration* self, JSJitGetterCallArgs args)
793
0
{
794
0
  AUTO_PROFILER_LABEL_FAST("get DeviceAcceleration.z", DOM, cx);
795
0
796
0
  Nullable<double> result(self->GetZ());
797
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
798
0
  if (result.IsNull()) {
799
0
    args.rval().setNull();
800
0
    return true;
801
0
  }
802
0
  args.rval().set(JS_NumberValue(double(result.Value())));
803
0
  return true;
804
0
}
805
806
static const JSJitInfo z_getterinfo = {
807
  { (JSJitGetterOp)get_z },
808
  { prototypes::id::DeviceAcceleration },
809
  { PrototypeTraits<prototypes::id::DeviceAcceleration>::Depth },
810
  JSJitInfo::Getter,
811
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
812
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
813
  true,  /* isInfallible. False in setters. */
814
  false,  /* isMovable.  Not relevant for setters. */
815
  false, /* isEliminatable.  Not relevant for setters. */
816
  false, /* isAlwaysInSlot.  Only relevant for getters. */
817
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
818
  false,  /* isTypedMethod.  Only relevant for methods. */
819
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
820
};
821
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
822
static_assert(0 < 1, "There is no slot for us");
823
824
static bool
825
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
826
0
{
827
0
  mozilla::dom::DeviceAcceleration* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceAcceleration>(obj);
828
0
  // We don't want to preserve if we don't have a wrapper, and we
829
0
  // obviously can't preserve if we're not initialized.
830
0
  if (self && self->GetWrapperPreserveColor()) {
831
0
    PreserveWrapper(self);
832
0
  }
833
0
  return true;
834
0
}
835
836
static void
837
_finalize(js::FreeOp* fop, JSObject* obj)
838
0
{
839
0
  mozilla::dom::DeviceAcceleration* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceAcceleration>(obj);
840
0
  if (self) {
841
0
    ClearWrapper(self, self, obj);
842
0
    AddForDeferredFinalization<mozilla::dom::DeviceAcceleration>(self);
843
0
  }
844
0
}
845
846
static size_t
847
_objectMoved(JSObject* obj, JSObject* old)
848
0
{
849
0
  mozilla::dom::DeviceAcceleration* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceAcceleration>(obj);
850
0
  if (self) {
851
0
    UpdateWrapper(self, self, obj, old);
852
0
  }
853
0
854
0
  return 0;
855
0
}
856
857
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
858
#if defined(__clang__)
859
#pragma clang diagnostic push
860
#pragma clang diagnostic ignored "-Wmissing-braces"
861
#endif
862
static const JSPropertySpec sAttributes_specs[] = {
863
  { "x", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &x_getterinfo, nullptr, nullptr },
864
  { "y", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &y_getterinfo, nullptr, nullptr },
865
  { "z", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &z_getterinfo, nullptr, nullptr },
866
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
867
};
868
#if defined(__clang__)
869
#pragma clang diagnostic pop
870
#endif
871
872
873
static const Prefable<const JSPropertySpec> sAttributes[] = {
874
  { nullptr, &sAttributes_specs[0] },
875
  { nullptr, nullptr }
876
};
877
878
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
879
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
880
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
881
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
882
883
884
static uint16_t sNativeProperties_sortedPropertyIndices[3];
885
static PropertyInfo sNativeProperties_propertyInfos[3];
886
887
static const NativePropertiesN<1> sNativeProperties = {
888
  false, 0,
889
  false, 0,
890
  false, 0,
891
  true,  0 /* sAttributes */,
892
  false, 0,
893
  false, 0,
894
  false, 0,
895
  -1,
896
  3,
897
  sNativeProperties_sortedPropertyIndices,
898
  {
899
    { sAttributes, &sNativeProperties_propertyInfos[0] }
900
  }
901
};
902
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
903
    "We have a property info count that is oversized");
904
905
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
906
  {
907
    "DeviceAccelerationPrototype",
908
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
909
    JS_NULL_CLASS_OPS,
910
    JS_NULL_CLASS_SPEC,
911
    JS_NULL_CLASS_EXT,
912
    JS_NULL_OBJECT_OPS
913
  },
914
  eInterfacePrototype,
915
  false,
916
  prototypes::id::DeviceAcceleration,
917
  PrototypeTraits<prototypes::id::DeviceAcceleration>::Depth,
918
  sNativePropertyHooks,
919
  "[object DeviceAccelerationPrototype]",
920
  JS::GetRealmObjectPrototype
921
};
922
923
static const js::ClassOps sClassOps = {
924
  _addProperty, /* addProperty */
925
  nullptr,               /* delProperty */
926
  nullptr,               /* enumerate */
927
  nullptr, /* newEnumerate */
928
  nullptr, /* resolve */
929
  nullptr, /* mayResolve */
930
  _finalize, /* finalize */
931
  nullptr, /* call */
932
  nullptr,               /* hasInstance */
933
  nullptr,               /* construct */
934
  nullptr, /* trace */
935
};
936
937
static const js::ClassExtension sClassExtension = {
938
  nullptr, /* weakmapKeyDelegateOp */
939
  _objectMoved /* objectMovedOp */
940
};
941
942
static const DOMJSClass sClass = {
943
  { "DeviceAcceleration",
944
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
945
    &sClassOps,
946
    JS_NULL_CLASS_SPEC,
947
    &sClassExtension,
948
    JS_NULL_OBJECT_OPS
949
  },
950
  { prototypes::id::DeviceAcceleration, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
951
  IsBaseOf<nsISupports, mozilla::dom::DeviceAcceleration >::value,
952
  sNativePropertyHooks,
953
  FindAssociatedGlobalForNative<mozilla::dom::DeviceAcceleration>::Get,
954
  GetProtoObjectHandle,
955
  GetCCParticipant<mozilla::dom::DeviceAcceleration>::Get()
956
};
957
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
958
              "Must have the right minimal number of reserved slots.");
959
static_assert(1 >= 1,
960
              "Must have enough reserved slots.");
961
962
const JSClass*
963
GetJSClass()
964
0
{
965
0
  return sClass.ToJSClass();
966
0
}
967
968
bool
969
Wrap(JSContext* aCx, mozilla::dom::DeviceAcceleration* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
970
0
{
971
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DeviceAcceleration>::value,
972
0
                "Shouldn't have wrappercached things that are not refcounted.");
973
0
  MOZ_ASSERT(static_cast<mozilla::dom::DeviceAcceleration*>(aObject) ==
974
0
             reinterpret_cast<mozilla::dom::DeviceAcceleration*>(aObject),
975
0
             "Multiple inheritance for mozilla::dom::DeviceAcceleration is broken.");
976
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
977
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
978
0
  MOZ_ASSERT(!aCache->GetWrapper(),
979
0
             "You should probably not be using Wrap() directly; use "
980
0
             "GetOrCreateDOMReflector instead");
981
0
982
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
983
0
             "nsISupports must be on our primary inheritance chain");
984
0
985
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
986
0
  if (!global) {
987
0
    return false;
988
0
  }
989
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
990
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
991
0
992
0
  // That might have ended up wrapping us already, due to the wonders
993
0
  // of XBL.  Check for that, and bail out as needed.
994
0
  aReflector.set(aCache->GetWrapper());
995
0
  if (aReflector) {
996
#ifdef DEBUG
997
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
998
#endif // DEBUG
999
    return true;
1000
0
  }
1001
0
1002
0
  JSAutoRealm ar(aCx, global);
1003
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1004
0
  if (!canonicalProto) {
1005
0
    return false;
1006
0
  }
1007
0
  JS::Rooted<JSObject*> proto(aCx);
1008
0
  if (aGivenProto) {
1009
0
    proto = aGivenProto;
1010
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1011
0
    // coming in, we changed compartments to that of "parent" so may need
1012
0
    // to wrap the proto here.
1013
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1014
0
      if (!JS_WrapObject(aCx, &proto)) {
1015
0
        return false;
1016
0
      }
1017
0
    }
1018
0
  } else {
1019
0
    proto = canonicalProto;
1020
0
  }
1021
0
1022
0
  BindingJSObjectCreator<mozilla::dom::DeviceAcceleration> creator(aCx);
1023
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1024
0
  if (!aReflector) {
1025
0
    return false;
1026
0
  }
1027
0
1028
0
  aCache->SetWrapper(aReflector);
1029
0
  creator.InitializationSucceeded();
1030
0
1031
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1032
0
             aCache->GetWrapperPreserveColor() == aReflector);
1033
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1034
0
  // otherwise we won't be able to properly recreate it later, since
1035
0
  // we won't know what proto to use.  Note that we don't check
1036
0
  // aGivenProto here, since it's entirely possible (and even
1037
0
  // somewhat common) to have a non-null aGivenProto which is the
1038
0
  // same as canonicalProto.
1039
0
  if (proto != canonicalProto) {
1040
0
    PreserveWrapper(aObject);
1041
0
  }
1042
0
1043
0
  return true;
1044
0
}
1045
1046
const NativePropertyHooks sNativePropertyHooks[] = { {
1047
  nullptr,
1048
  nullptr,
1049
  nullptr,
1050
  { sNativeProperties.Upcast(), nullptr },
1051
  prototypes::id::DeviceAcceleration,
1052
  constructors::id::_ID_Count,
1053
  nullptr,
1054
  &DefaultXrayExpandoObjectClass
1055
} };
1056
1057
void
1058
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1059
0
{
1060
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1061
0
  if (!parentProto) {
1062
0
    return;
1063
0
  }
1064
0
1065
0
  static bool sIdsInited = false;
1066
0
  if (!sIdsInited && NS_IsMainThread()) {
1067
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1068
0
      return;
1069
0
    }
1070
0
    sIdsInited = true;
1071
0
  }
1072
0
1073
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DeviceAcceleration);
1074
0
  JS::Heap<JSObject*>* interfaceCache = nullptr;
1075
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1076
0
                              &sPrototypeClass.mBase, protoCache,
1077
0
                              nullptr,
1078
0
                              nullptr, nullptr, 0, nullptr,
1079
0
                              interfaceCache,
1080
0
                              sNativeProperties.Upcast(),
1081
0
                              nullptr,
1082
0
                              nullptr, aDefineOnGlobal,
1083
0
                              nullptr,
1084
0
                              false);
1085
0
}
1086
1087
} // namespace DeviceAcceleration_Binding
1088
1089
1090
1091
namespace DeviceMotionEvent_Binding {
1092
1093
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value,
1094
              "Can't inherit from an interface with a different ownership model.");
1095
1096
MOZ_CAN_RUN_SCRIPT static bool
1097
get_acceleration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceMotionEvent* self, JSJitGetterCallArgs args)
1098
0
{
1099
0
  AUTO_PROFILER_LABEL_FAST("get DeviceMotionEvent.acceleration", DOM, cx);
1100
0
1101
0
  auto result(StrongOrRawPtr<mozilla::dom::DeviceAcceleration>(self->GetAcceleration()));
1102
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1103
0
  if (!result) {
1104
0
    args.rval().setNull();
1105
0
    return true;
1106
0
  }
1107
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1108
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1109
0
    return false;
1110
0
  }
1111
0
  return true;
1112
0
}
1113
1114
static const JSJitInfo acceleration_getterinfo = {
1115
  { (JSJitGetterOp)get_acceleration },
1116
  { prototypes::id::DeviceMotionEvent },
1117
  { PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth },
1118
  JSJitInfo::Getter,
1119
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1120
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1121
  false,  /* isInfallible. False in setters. */
1122
  false,  /* isMovable.  Not relevant for setters. */
1123
  false, /* isEliminatable.  Not relevant for setters. */
1124
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1125
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1126
  false,  /* isTypedMethod.  Only relevant for methods. */
1127
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1128
};
1129
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1130
static_assert(0 < 1, "There is no slot for us");
1131
1132
MOZ_CAN_RUN_SCRIPT static bool
1133
get_accelerationIncludingGravity(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceMotionEvent* self, JSJitGetterCallArgs args)
1134
0
{
1135
0
  AUTO_PROFILER_LABEL_FAST("get DeviceMotionEvent.accelerationIncludingGravity", DOM, cx);
1136
0
1137
0
  auto result(StrongOrRawPtr<mozilla::dom::DeviceAcceleration>(self->GetAccelerationIncludingGravity()));
1138
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1139
0
  if (!result) {
1140
0
    args.rval().setNull();
1141
0
    return true;
1142
0
  }
1143
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1144
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1145
0
    return false;
1146
0
  }
1147
0
  return true;
1148
0
}
1149
1150
static const JSJitInfo accelerationIncludingGravity_getterinfo = {
1151
  { (JSJitGetterOp)get_accelerationIncludingGravity },
1152
  { prototypes::id::DeviceMotionEvent },
1153
  { PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth },
1154
  JSJitInfo::Getter,
1155
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1156
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1157
  false,  /* isInfallible. False in setters. */
1158
  false,  /* isMovable.  Not relevant for setters. */
1159
  false, /* isEliminatable.  Not relevant for setters. */
1160
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1161
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1162
  false,  /* isTypedMethod.  Only relevant for methods. */
1163
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1164
};
1165
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1166
static_assert(0 < 1, "There is no slot for us");
1167
1168
MOZ_CAN_RUN_SCRIPT static bool
1169
get_rotationRate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceMotionEvent* self, JSJitGetterCallArgs args)
1170
0
{
1171
0
  AUTO_PROFILER_LABEL_FAST("get DeviceMotionEvent.rotationRate", DOM, cx);
1172
0
1173
0
  auto result(StrongOrRawPtr<mozilla::dom::DeviceRotationRate>(self->GetRotationRate()));
1174
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1175
0
  if (!result) {
1176
0
    args.rval().setNull();
1177
0
    return true;
1178
0
  }
1179
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1180
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1181
0
    return false;
1182
0
  }
1183
0
  return true;
1184
0
}
1185
1186
static const JSJitInfo rotationRate_getterinfo = {
1187
  { (JSJitGetterOp)get_rotationRate },
1188
  { prototypes::id::DeviceMotionEvent },
1189
  { PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth },
1190
  JSJitInfo::Getter,
1191
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1192
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1193
  false,  /* isInfallible. False in setters. */
1194
  false,  /* isMovable.  Not relevant for setters. */
1195
  false, /* isEliminatable.  Not relevant for setters. */
1196
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1197
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1198
  false,  /* isTypedMethod.  Only relevant for methods. */
1199
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1200
};
1201
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1202
static_assert(0 < 1, "There is no slot for us");
1203
1204
MOZ_CAN_RUN_SCRIPT static bool
1205
get_interval(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceMotionEvent* self, JSJitGetterCallArgs args)
1206
0
{
1207
0
  AUTO_PROFILER_LABEL_FAST("get DeviceMotionEvent.interval", DOM, cx);
1208
0
1209
0
  Nullable<double> result(self->GetInterval());
1210
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1211
0
  if (result.IsNull()) {
1212
0
    args.rval().setNull();
1213
0
    return true;
1214
0
  }
1215
0
  args.rval().set(JS_NumberValue(double(result.Value())));
1216
0
  return true;
1217
0
}
1218
1219
static const JSJitInfo interval_getterinfo = {
1220
  { (JSJitGetterOp)get_interval },
1221
  { prototypes::id::DeviceMotionEvent },
1222
  { PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth },
1223
  JSJitInfo::Getter,
1224
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1225
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1226
  true,  /* isInfallible. False in setters. */
1227
  false,  /* isMovable.  Not relevant for setters. */
1228
  false, /* isEliminatable.  Not relevant for setters. */
1229
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1230
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1231
  false,  /* isTypedMethod.  Only relevant for methods. */
1232
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1233
};
1234
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1235
static_assert(0 < 1, "There is no slot for us");
1236
1237
MOZ_CAN_RUN_SCRIPT static bool
1238
initDeviceMotionEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceMotionEvent* self, const JSJitMethodCallArgs& args)
1239
0
{
1240
0
  AUTO_PROFILER_LABEL_FAST("DeviceMotionEvent.initDeviceMotionEvent", DOM, cx);
1241
0
1242
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1243
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DeviceMotionEvent.initDeviceMotionEvent");
1244
0
  }
1245
0
  binding_detail::FakeString arg0;
1246
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1247
0
    return false;
1248
0
  }
1249
0
  bool arg1;
1250
0
  if (args.hasDefined(1)) {
1251
0
    if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
1252
0
      return false;
1253
0
    }
1254
0
  } else {
1255
0
    arg1 = false;
1256
0
  }
1257
0
  bool arg2;
1258
0
  if (args.hasDefined(2)) {
1259
0
    if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
1260
0
      return false;
1261
0
    }
1262
0
  } else {
1263
0
    arg2 = false;
1264
0
  }
1265
0
  binding_detail::FastDeviceAccelerationInit arg3;
1266
0
  if (!arg3.Init(cx, (args.hasDefined(3)) ? args[3] : JS::NullHandleValue,  "Argument 4 of DeviceMotionEvent.initDeviceMotionEvent", false)) {
1267
0
    return false;
1268
0
  }
1269
0
  binding_detail::FastDeviceAccelerationInit arg4;
1270
0
  if (!arg4.Init(cx, (args.hasDefined(4)) ? args[4] : JS::NullHandleValue,  "Argument 5 of DeviceMotionEvent.initDeviceMotionEvent", false)) {
1271
0
    return false;
1272
0
  }
1273
0
  binding_detail::FastDeviceRotationRateInit arg5;
1274
0
  if (!arg5.Init(cx, (args.hasDefined(5)) ? args[5] : JS::NullHandleValue,  "Argument 6 of DeviceMotionEvent.initDeviceMotionEvent", false)) {
1275
0
    return false;
1276
0
  }
1277
0
  Nullable<double> arg6;
1278
0
  if (!(args.hasDefined(6)) || args[6].isNullOrUndefined()) {
1279
0
    arg6.SetNull();
1280
0
  } else if (!ValueToPrimitive<double, eDefault>(cx, args[6], &arg6.SetValue())) {
1281
0
    return false;
1282
0
  } else if (!mozilla::IsFinite(arg6.Value())) {
1283
0
    ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 7 of DeviceMotionEvent.initDeviceMotionEvent");
1284
0
    return false;
1285
0
  }
1286
0
  self->InitDeviceMotionEvent(NonNullHelper(Constify(arg0)), arg1, arg2, Constify(arg3), Constify(arg4), Constify(arg5), Constify(arg6));
1287
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1288
0
  args.rval().setUndefined();
1289
0
  return true;
1290
0
}
1291
1292
static const JSJitInfo initDeviceMotionEvent_methodinfo = {
1293
  { (JSJitGetterOp)initDeviceMotionEvent },
1294
  { prototypes::id::DeviceMotionEvent },
1295
  { PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth },
1296
  JSJitInfo::Method,
1297
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1298
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
1299
  false,  /* isInfallible. False in setters. */
1300
  false,  /* isMovable.  Not relevant for setters. */
1301
  false, /* isEliminatable.  Not relevant for setters. */
1302
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1303
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1304
  false,  /* isTypedMethod.  Only relevant for methods. */
1305
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1306
};
1307
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1308
static_assert(0 < 1, "There is no slot for us");
1309
1310
MOZ_CAN_RUN_SCRIPT static bool
1311
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceMotionEvent* self, JSJitGetterCallArgs args)
1312
0
{
1313
0
  AUTO_PROFILER_LABEL_FAST("get DeviceMotionEvent.isTrusted", DOM, cx);
1314
0
1315
0
  bool result(self->IsTrusted());
1316
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1317
0
  args.rval().setBoolean(result);
1318
0
  return true;
1319
0
}
1320
1321
static const JSJitInfo isTrusted_getterinfo = {
1322
  { (JSJitGetterOp)get_isTrusted },
1323
  { prototypes::id::DeviceMotionEvent },
1324
  { PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth },
1325
  JSJitInfo::Getter,
1326
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
1327
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1328
  true,  /* isInfallible. False in setters. */
1329
  true,  /* isMovable.  Not relevant for setters. */
1330
  true, /* isEliminatable.  Not relevant for setters. */
1331
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1332
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1333
  false,  /* isTypedMethod.  Only relevant for methods. */
1334
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1335
};
1336
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1337
static_assert(0 < 1, "There is no slot for us");
1338
1339
static bool
1340
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1341
0
{
1342
0
  mozilla::dom::DeviceMotionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceMotionEvent>(obj);
1343
0
  // We don't want to preserve if we don't have a wrapper, and we
1344
0
  // obviously can't preserve if we're not initialized.
1345
0
  if (self && self->GetWrapperPreserveColor()) {
1346
0
    PreserveWrapper(self);
1347
0
  }
1348
0
  return true;
1349
0
}
1350
1351
static void
1352
_finalize(js::FreeOp* fop, JSObject* obj)
1353
0
{
1354
0
  mozilla::dom::DeviceMotionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceMotionEvent>(obj);
1355
0
  if (self) {
1356
0
    ClearWrapper(self, self, obj);
1357
0
    AddForDeferredFinalization<mozilla::dom::DeviceMotionEvent>(self);
1358
0
  }
1359
0
}
1360
1361
static size_t
1362
_objectMoved(JSObject* obj, JSObject* old)
1363
0
{
1364
0
  mozilla::dom::DeviceMotionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceMotionEvent>(obj);
1365
0
  if (self) {
1366
0
    UpdateWrapper(self, self, obj, old);
1367
0
  }
1368
0
1369
0
  return 0;
1370
0
}
1371
1372
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1373
#if defined(__clang__)
1374
#pragma clang diagnostic push
1375
#pragma clang diagnostic ignored "-Wmissing-braces"
1376
#endif
1377
static const JSFunctionSpec sMethods_specs[] = {
1378
  JS_FNSPEC("initDeviceMotionEvent", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&initDeviceMotionEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1379
  JS_FS_END
1380
};
1381
#if defined(__clang__)
1382
#pragma clang diagnostic pop
1383
#endif
1384
1385
1386
static const Prefable<const JSFunctionSpec> sMethods[] = {
1387
  { nullptr, &sMethods_specs[0] },
1388
  { nullptr, nullptr }
1389
};
1390
1391
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1392
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1393
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1394
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1395
1396
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1397
#if defined(__clang__)
1398
#pragma clang diagnostic push
1399
#pragma clang diagnostic ignored "-Wmissing-braces"
1400
#endif
1401
static const JSPropertySpec sAttributes_specs[] = {
1402
  { "acceleration", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &acceleration_getterinfo, nullptr, nullptr },
1403
  { "accelerationIncludingGravity", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &accelerationIncludingGravity_getterinfo, nullptr, nullptr },
1404
  { "rotationRate", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &rotationRate_getterinfo, nullptr, nullptr },
1405
  { "interval", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &interval_getterinfo, nullptr, nullptr },
1406
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1407
};
1408
#if defined(__clang__)
1409
#pragma clang diagnostic pop
1410
#endif
1411
1412
1413
static const Prefable<const JSPropertySpec> sAttributes[] = {
1414
  { nullptr, &sAttributes_specs[0] },
1415
  { nullptr, nullptr }
1416
};
1417
1418
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1419
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1420
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1421
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1422
1423
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1424
#if defined(__clang__)
1425
#pragma clang diagnostic push
1426
#pragma clang diagnostic ignored "-Wmissing-braces"
1427
#endif
1428
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
1429
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
1430
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1431
};
1432
#if defined(__clang__)
1433
#pragma clang diagnostic pop
1434
#endif
1435
1436
1437
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
1438
  { nullptr, &sUnforgeableAttributes_specs[0] },
1439
  { nullptr, nullptr }
1440
};
1441
1442
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1443
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1444
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1445
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1446
1447
1448
static uint16_t sNativeProperties_sortedPropertyIndices[6];
1449
static PropertyInfo sNativeProperties_propertyInfos[6];
1450
1451
static const NativePropertiesN<3> sNativeProperties = {
1452
  false, 0,
1453
  false, 0,
1454
  true,  0 /* sMethods */,
1455
  true,  1 /* sAttributes */,
1456
  false, 0,
1457
  true,  2 /* sUnforgeableAttributes */,
1458
  false, 0,
1459
  -1,
1460
  6,
1461
  sNativeProperties_sortedPropertyIndices,
1462
  {
1463
    { sMethods, &sNativeProperties_propertyInfos[0] },
1464
    { sAttributes, &sNativeProperties_propertyInfos[1] },
1465
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[5] }
1466
  }
1467
};
1468
static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1469
    "We have a property info count that is oversized");
1470
1471
static bool
1472
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1473
0
{
1474
0
  AUTO_PROFILER_LABEL_FAST("DeviceMotionEvent constructor", DOM, cx);
1475
0
1476
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1477
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1478
0
  if (!args.isConstructing()) {
1479
0
    // XXXbz wish I could get the name from the callee instead of
1480
0
    // Adding more relocations
1481
0
    return ThrowConstructorWithoutNew(cx, "DeviceMotionEvent");
1482
0
  }
1483
0
1484
0
  JS::Rooted<JSObject*> desiredProto(cx);
1485
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1486
0
    return false;
1487
0
  }
1488
0
1489
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1490
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DeviceMotionEvent");
1491
0
  }
1492
0
  GlobalObject global(cx, obj);
1493
0
  if (global.Failed()) {
1494
0
    return false;
1495
0
  }
1496
0
1497
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1498
0
  binding_detail::FakeString arg0;
1499
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1500
0
    return false;
1501
0
  }
1502
0
  binding_detail::FastDeviceMotionEventInit arg1;
1503
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of DeviceMotionEvent.constructor", false)) {
1504
0
    return false;
1505
0
  }
1506
0
  Maybe<JSAutoRealm> ar;
1507
0
  if (objIsXray) {
1508
0
    obj = js::CheckedUnwrap(obj);
1509
0
    if (!obj) {
1510
0
      return false;
1511
0
    }
1512
0
    ar.emplace(cx, obj);
1513
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1514
0
      return false;
1515
0
    }
1516
0
  }
1517
0
  FastErrorResult rv;
1518
0
  auto result(StrongOrRawPtr<mozilla::dom::DeviceMotionEvent>(mozilla::dom::DeviceMotionEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
1519
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1520
0
    return false;
1521
0
  }
1522
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1523
0
  static_assert(!IsPointer<decltype(result)>::value,
1524
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1525
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1526
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1527
0
    return false;
1528
0
  }
1529
0
  return true;
1530
0
}
1531
1532
static const js::ClassOps sInterfaceObjectClassOps = {
1533
    nullptr,               /* addProperty */
1534
    nullptr,               /* delProperty */
1535
    nullptr,               /* enumerate */
1536
    nullptr,               /* newEnumerate */
1537
    nullptr,               /* resolve */
1538
    nullptr,               /* mayResolve */
1539
    nullptr,               /* finalize */
1540
    _constructor, /* call */
1541
    nullptr,               /* hasInstance */
1542
    _constructor, /* construct */
1543
    nullptr,               /* trace */
1544
};
1545
1546
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1547
  {
1548
    "Function",
1549
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1550
    &sInterfaceObjectClassOps,
1551
    JS_NULL_CLASS_SPEC,
1552
    JS_NULL_CLASS_EXT,
1553
    &sInterfaceObjectClassObjectOps
1554
  },
1555
  eInterface,
1556
  true,
1557
  prototypes::id::DeviceMotionEvent,
1558
  PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth,
1559
  sNativePropertyHooks,
1560
  "function DeviceMotionEvent() {\n    [native code]\n}",
1561
  Event_Binding::GetConstructorObject
1562
};
1563
1564
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1565
  {
1566
    "DeviceMotionEventPrototype",
1567
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
1568
    JS_NULL_CLASS_OPS,
1569
    JS_NULL_CLASS_SPEC,
1570
    JS_NULL_CLASS_EXT,
1571
    JS_NULL_OBJECT_OPS
1572
  },
1573
  eInterfacePrototype,
1574
  false,
1575
  prototypes::id::DeviceMotionEvent,
1576
  PrototypeTraits<prototypes::id::DeviceMotionEvent>::Depth,
1577
  sNativePropertyHooks,
1578
  "[object DeviceMotionEventPrototype]",
1579
  Event_Binding::GetProtoObject
1580
};
1581
1582
bool
1583
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1584
0
{
1585
0
  static bool sPrefValue;
1586
0
  static bool sPrefCacheSetUp = false;
1587
0
  if (!sPrefCacheSetUp) {
1588
0
    sPrefCacheSetUp = true;
1589
0
    Preferences::AddBoolVarCache(&sPrefValue, "device.sensors.motion.enabled");
1590
0
  }
1591
0
1592
0
  return sPrefValue &&
1593
0
         nsGlobalWindowInner::DeviceSensorsEnabled(aCx, aObj);
1594
0
}
1595
1596
static const js::ClassOps sClassOps = {
1597
  _addProperty, /* addProperty */
1598
  nullptr,               /* delProperty */
1599
  nullptr,               /* enumerate */
1600
  nullptr, /* newEnumerate */
1601
  nullptr, /* resolve */
1602
  nullptr, /* mayResolve */
1603
  _finalize, /* finalize */
1604
  nullptr, /* call */
1605
  nullptr,               /* hasInstance */
1606
  nullptr,               /* construct */
1607
  nullptr, /* trace */
1608
};
1609
1610
static const js::ClassExtension sClassExtension = {
1611
  nullptr, /* weakmapKeyDelegateOp */
1612
  _objectMoved /* objectMovedOp */
1613
};
1614
1615
static const DOMJSClass sClass = {
1616
  { "DeviceMotionEvent",
1617
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
1618
    &sClassOps,
1619
    JS_NULL_CLASS_SPEC,
1620
    &sClassExtension,
1621
    JS_NULL_OBJECT_OPS
1622
  },
1623
  { prototypes::id::Event, prototypes::id::DeviceMotionEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1624
  IsBaseOf<nsISupports, mozilla::dom::DeviceMotionEvent >::value,
1625
  sNativePropertyHooks,
1626
  FindAssociatedGlobalForNative<mozilla::dom::DeviceMotionEvent>::Get,
1627
  GetProtoObjectHandle,
1628
  GetCCParticipant<mozilla::dom::DeviceMotionEvent>::Get()
1629
};
1630
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1631
              "Must have the right minimal number of reserved slots.");
1632
static_assert(1 >= 1,
1633
              "Must have enough reserved slots.");
1634
1635
const JSClass*
1636
GetJSClass()
1637
0
{
1638
0
  return sClass.ToJSClass();
1639
0
}
1640
1641
bool
1642
Wrap(JSContext* aCx, mozilla::dom::DeviceMotionEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1643
0
{
1644
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DeviceMotionEvent>::value,
1645
0
                "Shouldn't have wrappercached things that are not refcounted.");
1646
0
  MOZ_ASSERT(static_cast<mozilla::dom::DeviceMotionEvent*>(aObject) ==
1647
0
             reinterpret_cast<mozilla::dom::DeviceMotionEvent*>(aObject),
1648
0
             "Multiple inheritance for mozilla::dom::DeviceMotionEvent is broken.");
1649
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
1650
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
1651
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
1652
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1653
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1654
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1655
0
             "You should probably not be using Wrap() directly; use "
1656
0
             "GetOrCreateDOMReflector instead");
1657
0
1658
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1659
0
             "nsISupports must be on our primary inheritance chain");
1660
0
1661
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1662
0
  if (!global) {
1663
0
    return false;
1664
0
  }
1665
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1666
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1667
0
1668
0
  // That might have ended up wrapping us already, due to the wonders
1669
0
  // of XBL.  Check for that, and bail out as needed.
1670
0
  aReflector.set(aCache->GetWrapper());
1671
0
  if (aReflector) {
1672
#ifdef DEBUG
1673
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1674
#endif // DEBUG
1675
    return true;
1676
0
  }
1677
0
1678
0
  JSAutoRealm ar(aCx, global);
1679
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1680
0
  if (!canonicalProto) {
1681
0
    return false;
1682
0
  }
1683
0
  JS::Rooted<JSObject*> proto(aCx);
1684
0
  if (aGivenProto) {
1685
0
    proto = aGivenProto;
1686
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1687
0
    // coming in, we changed compartments to that of "parent" so may need
1688
0
    // to wrap the proto here.
1689
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1690
0
      if (!JS_WrapObject(aCx, &proto)) {
1691
0
        return false;
1692
0
      }
1693
0
    }
1694
0
  } else {
1695
0
    proto = canonicalProto;
1696
0
  }
1697
0
1698
0
  BindingJSObjectCreator<mozilla::dom::DeviceMotionEvent> creator(aCx);
1699
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1700
0
  if (!aReflector) {
1701
0
    return false;
1702
0
  }
1703
0
1704
0
  aCache->SetWrapper(aReflector);
1705
0
1706
0
  // Important: do unforgeable property setup after we have handed
1707
0
  // over ownership of the C++ object to obj as needed, so that if
1708
0
  // we fail and it ends up GCed it won't have problems in the
1709
0
  // finalizer trying to drop its ownership of the C++ object.
1710
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
1711
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
1712
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
1713
0
    aCache->ReleaseWrapper(aObject);
1714
0
    aCache->ClearWrapper();
1715
0
    return false;
1716
0
  }
1717
0
  creator.InitializationSucceeded();
1718
0
1719
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1720
0
             aCache->GetWrapperPreserveColor() == aReflector);
1721
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1722
0
  // otherwise we won't be able to properly recreate it later, since
1723
0
  // we won't know what proto to use.  Note that we don't check
1724
0
  // aGivenProto here, since it's entirely possible (and even
1725
0
  // somewhat common) to have a non-null aGivenProto which is the
1726
0
  // same as canonicalProto.
1727
0
  if (proto != canonicalProto) {
1728
0
    PreserveWrapper(aObject);
1729
0
  }
1730
0
1731
0
  return true;
1732
0
}
1733
1734
const NativePropertyHooks sNativePropertyHooks[] = { {
1735
  nullptr,
1736
  nullptr,
1737
  nullptr,
1738
  { sNativeProperties.Upcast(), nullptr },
1739
  prototypes::id::DeviceMotionEvent,
1740
  constructors::id::DeviceMotionEvent,
1741
  Event_Binding::sNativePropertyHooks,
1742
  &DefaultXrayExpandoObjectClass
1743
} };
1744
1745
void
1746
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1747
0
{
1748
0
  JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx));
1749
0
  if (!parentProto) {
1750
0
    return;
1751
0
  }
1752
0
1753
0
  JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx));
1754
0
  if (!constructorProto) {
1755
0
    return;
1756
0
  }
1757
0
1758
0
  static bool sIdsInited = false;
1759
0
  if (!sIdsInited && NS_IsMainThread()) {
1760
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1761
0
      return;
1762
0
    }
1763
0
    sIdsInited = true;
1764
0
  }
1765
0
1766
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DeviceMotionEvent);
1767
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DeviceMotionEvent);
1768
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1769
0
                              &sPrototypeClass.mBase, protoCache,
1770
0
                              nullptr,
1771
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1772
0
                              interfaceCache,
1773
0
                              sNativeProperties.Upcast(),
1774
0
                              nullptr,
1775
0
                              "DeviceMotionEvent", aDefineOnGlobal,
1776
0
                              nullptr,
1777
0
                              false);
1778
0
1779
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
1780
0
  {
1781
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1782
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1783
0
    if (!unforgeableHolder) {
1784
0
      *protoCache = nullptr;
1785
0
      if (interfaceCache) {
1786
0
        *interfaceCache = nullptr;
1787
0
      }
1788
0
      return;
1789
0
    }
1790
0
  }
1791
0
1792
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1793
0
    *protoCache = nullptr;
1794
0
    if (interfaceCache) {
1795
0
      *interfaceCache = nullptr;
1796
0
    }
1797
0
    return;
1798
0
  }
1799
0
1800
0
  if (*protoCache) {
1801
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1802
0
                        JS::ObjectValue(*unforgeableHolder));
1803
0
  }
1804
0
}
1805
1806
JSObject*
1807
GetConstructorObject(JSContext* aCx)
1808
0
{
1809
0
  return GetConstructorObjectHandle(aCx);
1810
0
}
1811
1812
} // namespace DeviceMotionEvent_Binding
1813
1814
1815
1816
namespace DeviceRotationRate_Binding {
1817
1818
MOZ_CAN_RUN_SCRIPT static bool
1819
get_alpha(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceRotationRate* self, JSJitGetterCallArgs args)
1820
0
{
1821
0
  AUTO_PROFILER_LABEL_FAST("get DeviceRotationRate.alpha", DOM, cx);
1822
0
1823
0
  Nullable<double> result(self->GetAlpha());
1824
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1825
0
  if (result.IsNull()) {
1826
0
    args.rval().setNull();
1827
0
    return true;
1828
0
  }
1829
0
  args.rval().set(JS_NumberValue(double(result.Value())));
1830
0
  return true;
1831
0
}
1832
1833
static const JSJitInfo alpha_getterinfo = {
1834
  { (JSJitGetterOp)get_alpha },
1835
  { prototypes::id::DeviceRotationRate },
1836
  { PrototypeTraits<prototypes::id::DeviceRotationRate>::Depth },
1837
  JSJitInfo::Getter,
1838
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1839
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1840
  true,  /* isInfallible. False in setters. */
1841
  false,  /* isMovable.  Not relevant for setters. */
1842
  false, /* isEliminatable.  Not relevant for setters. */
1843
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1844
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1845
  false,  /* isTypedMethod.  Only relevant for methods. */
1846
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1847
};
1848
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1849
static_assert(0 < 1, "There is no slot for us");
1850
1851
MOZ_CAN_RUN_SCRIPT static bool
1852
get_beta(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceRotationRate* self, JSJitGetterCallArgs args)
1853
0
{
1854
0
  AUTO_PROFILER_LABEL_FAST("get DeviceRotationRate.beta", DOM, cx);
1855
0
1856
0
  Nullable<double> result(self->GetBeta());
1857
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1858
0
  if (result.IsNull()) {
1859
0
    args.rval().setNull();
1860
0
    return true;
1861
0
  }
1862
0
  args.rval().set(JS_NumberValue(double(result.Value())));
1863
0
  return true;
1864
0
}
1865
1866
static const JSJitInfo beta_getterinfo = {
1867
  { (JSJitGetterOp)get_beta },
1868
  { prototypes::id::DeviceRotationRate },
1869
  { PrototypeTraits<prototypes::id::DeviceRotationRate>::Depth },
1870
  JSJitInfo::Getter,
1871
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1872
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1873
  true,  /* isInfallible. False in setters. */
1874
  false,  /* isMovable.  Not relevant for setters. */
1875
  false, /* isEliminatable.  Not relevant for setters. */
1876
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1877
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1878
  false,  /* isTypedMethod.  Only relevant for methods. */
1879
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1880
};
1881
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1882
static_assert(0 < 1, "There is no slot for us");
1883
1884
MOZ_CAN_RUN_SCRIPT static bool
1885
get_gamma(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceRotationRate* self, JSJitGetterCallArgs args)
1886
0
{
1887
0
  AUTO_PROFILER_LABEL_FAST("get DeviceRotationRate.gamma", DOM, cx);
1888
0
1889
0
  Nullable<double> result(self->GetGamma());
1890
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1891
0
  if (result.IsNull()) {
1892
0
    args.rval().setNull();
1893
0
    return true;
1894
0
  }
1895
0
  args.rval().set(JS_NumberValue(double(result.Value())));
1896
0
  return true;
1897
0
}
1898
1899
static const JSJitInfo gamma_getterinfo = {
1900
  { (JSJitGetterOp)get_gamma },
1901
  { prototypes::id::DeviceRotationRate },
1902
  { PrototypeTraits<prototypes::id::DeviceRotationRate>::Depth },
1903
  JSJitInfo::Getter,
1904
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1905
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1906
  true,  /* isInfallible. False in setters. */
1907
  false,  /* isMovable.  Not relevant for setters. */
1908
  false, /* isEliminatable.  Not relevant for setters. */
1909
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1910
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1911
  false,  /* isTypedMethod.  Only relevant for methods. */
1912
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1913
};
1914
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1915
static_assert(0 < 1, "There is no slot for us");
1916
1917
static bool
1918
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1919
0
{
1920
0
  mozilla::dom::DeviceRotationRate* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceRotationRate>(obj);
1921
0
  // We don't want to preserve if we don't have a wrapper, and we
1922
0
  // obviously can't preserve if we're not initialized.
1923
0
  if (self && self->GetWrapperPreserveColor()) {
1924
0
    PreserveWrapper(self);
1925
0
  }
1926
0
  return true;
1927
0
}
1928
1929
static void
1930
_finalize(js::FreeOp* fop, JSObject* obj)
1931
0
{
1932
0
  mozilla::dom::DeviceRotationRate* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceRotationRate>(obj);
1933
0
  if (self) {
1934
0
    ClearWrapper(self, self, obj);
1935
0
    AddForDeferredFinalization<mozilla::dom::DeviceRotationRate>(self);
1936
0
  }
1937
0
}
1938
1939
static size_t
1940
_objectMoved(JSObject* obj, JSObject* old)
1941
0
{
1942
0
  mozilla::dom::DeviceRotationRate* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceRotationRate>(obj);
1943
0
  if (self) {
1944
0
    UpdateWrapper(self, self, obj, old);
1945
0
  }
1946
0
1947
0
  return 0;
1948
0
}
1949
1950
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1951
#if defined(__clang__)
1952
#pragma clang diagnostic push
1953
#pragma clang diagnostic ignored "-Wmissing-braces"
1954
#endif
1955
static const JSPropertySpec sAttributes_specs[] = {
1956
  { "alpha", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &alpha_getterinfo, nullptr, nullptr },
1957
  { "beta", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &beta_getterinfo, nullptr, nullptr },
1958
  { "gamma", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &gamma_getterinfo, nullptr, nullptr },
1959
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1960
};
1961
#if defined(__clang__)
1962
#pragma clang diagnostic pop
1963
#endif
1964
1965
1966
static const Prefable<const JSPropertySpec> sAttributes[] = {
1967
  { nullptr, &sAttributes_specs[0] },
1968
  { nullptr, nullptr }
1969
};
1970
1971
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1972
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1973
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1974
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1975
1976
1977
static uint16_t sNativeProperties_sortedPropertyIndices[3];
1978
static PropertyInfo sNativeProperties_propertyInfos[3];
1979
1980
static const NativePropertiesN<1> sNativeProperties = {
1981
  false, 0,
1982
  false, 0,
1983
  false, 0,
1984
  true,  0 /* sAttributes */,
1985
  false, 0,
1986
  false, 0,
1987
  false, 0,
1988
  -1,
1989
  3,
1990
  sNativeProperties_sortedPropertyIndices,
1991
  {
1992
    { sAttributes, &sNativeProperties_propertyInfos[0] }
1993
  }
1994
};
1995
static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1996
    "We have a property info count that is oversized");
1997
1998
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1999
  {
2000
    "DeviceRotationRatePrototype",
2001
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
2002
    JS_NULL_CLASS_OPS,
2003
    JS_NULL_CLASS_SPEC,
2004
    JS_NULL_CLASS_EXT,
2005
    JS_NULL_OBJECT_OPS
2006
  },
2007
  eInterfacePrototype,
2008
  false,
2009
  prototypes::id::DeviceRotationRate,
2010
  PrototypeTraits<prototypes::id::DeviceRotationRate>::Depth,
2011
  sNativePropertyHooks,
2012
  "[object DeviceRotationRatePrototype]",
2013
  JS::GetRealmObjectPrototype
2014
};
2015
2016
static const js::ClassOps sClassOps = {
2017
  _addProperty, /* addProperty */
2018
  nullptr,               /* delProperty */
2019
  nullptr,               /* enumerate */
2020
  nullptr, /* newEnumerate */
2021
  nullptr, /* resolve */
2022
  nullptr, /* mayResolve */
2023
  _finalize, /* finalize */
2024
  nullptr, /* call */
2025
  nullptr,               /* hasInstance */
2026
  nullptr,               /* construct */
2027
  nullptr, /* trace */
2028
};
2029
2030
static const js::ClassExtension sClassExtension = {
2031
  nullptr, /* weakmapKeyDelegateOp */
2032
  _objectMoved /* objectMovedOp */
2033
};
2034
2035
static const DOMJSClass sClass = {
2036
  { "DeviceRotationRate",
2037
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
2038
    &sClassOps,
2039
    JS_NULL_CLASS_SPEC,
2040
    &sClassExtension,
2041
    JS_NULL_OBJECT_OPS
2042
  },
2043
  { prototypes::id::DeviceRotationRate, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
2044
  IsBaseOf<nsISupports, mozilla::dom::DeviceRotationRate >::value,
2045
  sNativePropertyHooks,
2046
  FindAssociatedGlobalForNative<mozilla::dom::DeviceRotationRate>::Get,
2047
  GetProtoObjectHandle,
2048
  GetCCParticipant<mozilla::dom::DeviceRotationRate>::Get()
2049
};
2050
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
2051
              "Must have the right minimal number of reserved slots.");
2052
static_assert(1 >= 1,
2053
              "Must have enough reserved slots.");
2054
2055
const JSClass*
2056
GetJSClass()
2057
0
{
2058
0
  return sClass.ToJSClass();
2059
0
}
2060
2061
bool
2062
Wrap(JSContext* aCx, mozilla::dom::DeviceRotationRate* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
2063
0
{
2064
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DeviceRotationRate>::value,
2065
0
                "Shouldn't have wrappercached things that are not refcounted.");
2066
0
  MOZ_ASSERT(static_cast<mozilla::dom::DeviceRotationRate*>(aObject) ==
2067
0
             reinterpret_cast<mozilla::dom::DeviceRotationRate*>(aObject),
2068
0
             "Multiple inheritance for mozilla::dom::DeviceRotationRate is broken.");
2069
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
2070
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
2071
0
  MOZ_ASSERT(!aCache->GetWrapper(),
2072
0
             "You should probably not be using Wrap() directly; use "
2073
0
             "GetOrCreateDOMReflector instead");
2074
0
2075
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
2076
0
             "nsISupports must be on our primary inheritance chain");
2077
0
2078
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
2079
0
  if (!global) {
2080
0
    return false;
2081
0
  }
2082
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
2083
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
2084
0
2085
0
  // That might have ended up wrapping us already, due to the wonders
2086
0
  // of XBL.  Check for that, and bail out as needed.
2087
0
  aReflector.set(aCache->GetWrapper());
2088
0
  if (aReflector) {
2089
#ifdef DEBUG
2090
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
2091
#endif // DEBUG
2092
    return true;
2093
0
  }
2094
0
2095
0
  JSAutoRealm ar(aCx, global);
2096
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
2097
0
  if (!canonicalProto) {
2098
0
    return false;
2099
0
  }
2100
0
  JS::Rooted<JSObject*> proto(aCx);
2101
0
  if (aGivenProto) {
2102
0
    proto = aGivenProto;
2103
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
2104
0
    // coming in, we changed compartments to that of "parent" so may need
2105
0
    // to wrap the proto here.
2106
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
2107
0
      if (!JS_WrapObject(aCx, &proto)) {
2108
0
        return false;
2109
0
      }
2110
0
    }
2111
0
  } else {
2112
0
    proto = canonicalProto;
2113
0
  }
2114
0
2115
0
  BindingJSObjectCreator<mozilla::dom::DeviceRotationRate> creator(aCx);
2116
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
2117
0
  if (!aReflector) {
2118
0
    return false;
2119
0
  }
2120
0
2121
0
  aCache->SetWrapper(aReflector);
2122
0
  creator.InitializationSucceeded();
2123
0
2124
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
2125
0
             aCache->GetWrapperPreserveColor() == aReflector);
2126
0
  // If proto != canonicalProto, we have to preserve our wrapper;
2127
0
  // otherwise we won't be able to properly recreate it later, since
2128
0
  // we won't know what proto to use.  Note that we don't check
2129
0
  // aGivenProto here, since it's entirely possible (and even
2130
0
  // somewhat common) to have a non-null aGivenProto which is the
2131
0
  // same as canonicalProto.
2132
0
  if (proto != canonicalProto) {
2133
0
    PreserveWrapper(aObject);
2134
0
  }
2135
0
2136
0
  return true;
2137
0
}
2138
2139
const NativePropertyHooks sNativePropertyHooks[] = { {
2140
  nullptr,
2141
  nullptr,
2142
  nullptr,
2143
  { sNativeProperties.Upcast(), nullptr },
2144
  prototypes::id::DeviceRotationRate,
2145
  constructors::id::_ID_Count,
2146
  nullptr,
2147
  &DefaultXrayExpandoObjectClass
2148
} };
2149
2150
void
2151
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
2152
0
{
2153
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
2154
0
  if (!parentProto) {
2155
0
    return;
2156
0
  }
2157
0
2158
0
  static bool sIdsInited = false;
2159
0
  if (!sIdsInited && NS_IsMainThread()) {
2160
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
2161
0
      return;
2162
0
    }
2163
0
    sIdsInited = true;
2164
0
  }
2165
0
2166
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DeviceRotationRate);
2167
0
  JS::Heap<JSObject*>* interfaceCache = nullptr;
2168
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
2169
0
                              &sPrototypeClass.mBase, protoCache,
2170
0
                              nullptr,
2171
0
                              nullptr, nullptr, 0, nullptr,
2172
0
                              interfaceCache,
2173
0
                              sNativeProperties.Upcast(),
2174
0
                              nullptr,
2175
0
                              nullptr, aDefineOnGlobal,
2176
0
                              nullptr,
2177
0
                              false);
2178
0
}
2179
2180
} // namespace DeviceRotationRate_Binding
2181
2182
2183
2184
} // namespace dom
2185
} // namespace mozilla