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