Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM DeviceOrientationEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "DeviceOrientationEventBinding.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/DeviceOrientationEvent.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 : DeviceOrientationEventInit::DeviceOrientationEventInit()
24 0 : : EventInit(FastDictionaryInitializer())
25 : {
26 : // Safe to pass a null context if we pass a null value
27 0 : Init(nullptr, JS::NullHandleValue);
28 0 : }
29 :
30 :
31 :
32 : bool
33 0 : DeviceOrientationEventInit::InitIds(JSContext* cx, DeviceOrientationEventInitAtoms* atomsCache)
34 : {
35 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
36 :
37 : // Initialize these in reverse order so that any failure leaves the first one
38 : // uninitialized.
39 0 : if (!atomsCache->gamma_id.init(cx, "gamma") ||
40 0 : !atomsCache->beta_id.init(cx, "beta") ||
41 0 : !atomsCache->alpha_id.init(cx, "alpha") ||
42 0 : !atomsCache->absolute_id.init(cx, "absolute")) {
43 0 : return false;
44 : }
45 0 : return true;
46 : }
47 :
48 : bool
49 0 : DeviceOrientationEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
50 : {
51 : // Passing a null JSContext is OK only if we're initing from null,
52 : // Since in that case we will not have to do any property gets
53 : // Also evaluate isNullOrUndefined in order to avoid false-positive
54 : // checkers by static analysis tools
55 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
56 0 : DeviceOrientationEventInitAtoms* atomsCache = nullptr;
57 0 : if (cx) {
58 0 : atomsCache = GetAtomCache<DeviceOrientationEventInitAtoms>(cx);
59 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60 0 : return false;
61 : }
62 : }
63 :
64 : // Per spec, we init the parent's members first
65 0 : if (!EventInit::Init(cx, val)) {
66 0 : return false;
67 : }
68 :
69 0 : bool isNull = val.isNullOrUndefined();
70 : // We only need these if !isNull, in which case we have |cx|.
71 0 : Maybe<JS::Rooted<JSObject *> > object;
72 0 : Maybe<JS::Rooted<JS::Value> > temp;
73 0 : if (!isNull) {
74 0 : MOZ_ASSERT(cx);
75 0 : object.emplace(cx, &val.toObject());
76 0 : temp.emplace(cx);
77 : }
78 0 : if (!isNull) {
79 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->absolute_id, temp.ptr())) {
80 0 : return false;
81 : }
82 : }
83 0 : if (!isNull && !temp->isUndefined()) {
84 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mAbsolute)) {
85 0 : return false;
86 : }
87 : } else {
88 0 : mAbsolute = false;
89 : }
90 0 : mIsAnyMemberPresent = true;
91 :
92 0 : if (!isNull) {
93 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->alpha_id, temp.ptr())) {
94 0 : return false;
95 : }
96 : }
97 0 : if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
98 0 : mAlpha.SetNull();
99 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mAlpha.SetValue())) {
100 0 : return false;
101 0 : } else if (!mozilla::IsFinite(mAlpha.Value())) {
102 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'alpha' member of DeviceOrientationEventInit");
103 0 : return false;
104 : }
105 0 : mIsAnyMemberPresent = true;
106 :
107 0 : if (!isNull) {
108 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->beta_id, temp.ptr())) {
109 0 : return false;
110 : }
111 : }
112 0 : if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
113 0 : mBeta.SetNull();
114 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mBeta.SetValue())) {
115 0 : return false;
116 0 : } else if (!mozilla::IsFinite(mBeta.Value())) {
117 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'beta' member of DeviceOrientationEventInit");
118 0 : return false;
119 : }
120 0 : mIsAnyMemberPresent = true;
121 :
122 0 : if (!isNull) {
123 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->gamma_id, temp.ptr())) {
124 0 : return false;
125 : }
126 : }
127 0 : if (!(!isNull && !temp->isUndefined()) || temp.ref().isNullOrUndefined()) {
128 0 : mGamma.SetNull();
129 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mGamma.SetValue())) {
130 0 : return false;
131 0 : } else if (!mozilla::IsFinite(mGamma.Value())) {
132 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'gamma' member of DeviceOrientationEventInit");
133 0 : return false;
134 : }
135 0 : mIsAnyMemberPresent = true;
136 0 : return true;
137 : }
138 :
139 : bool
140 0 : DeviceOrientationEventInit::Init(const nsAString& aJSON)
141 : {
142 0 : AutoJSAPI jsapi;
143 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
144 0 : if (!cleanGlobal) {
145 0 : return false;
146 : }
147 0 : if (!jsapi.Init(cleanGlobal)) {
148 0 : return false;
149 : }
150 0 : JSContext* cx = jsapi.cx();
151 0 : JS::Rooted<JS::Value> json(cx);
152 0 : bool ok = ParseJSON(cx, aJSON, &json);
153 0 : NS_ENSURE_TRUE(ok, false);
154 0 : return Init(cx, json);
155 : }
156 :
157 : bool
158 0 : DeviceOrientationEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
159 : {
160 0 : DeviceOrientationEventInitAtoms* atomsCache = GetAtomCache<DeviceOrientationEventInitAtoms>(cx);
161 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
162 0 : return false;
163 : }
164 :
165 : // Per spec, we define the parent's members first
166 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
167 0 : return false;
168 : }
169 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
170 :
171 : do {
172 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
173 0 : JS::Rooted<JS::Value> temp(cx);
174 0 : bool const & currentValue = mAbsolute;
175 0 : temp.setBoolean(currentValue);
176 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->absolute_id, temp, JSPROP_ENUMERATE)) {
177 0 : return false;
178 : }
179 0 : break;
180 : } while(0);
181 :
182 : do {
183 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
184 0 : JS::Rooted<JS::Value> temp(cx);
185 0 : Nullable<double> const & currentValue = mAlpha;
186 0 : if (currentValue.IsNull()) {
187 0 : temp.setNull();
188 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->alpha_id, temp, JSPROP_ENUMERATE)) {
189 0 : return false;
190 : }
191 0 : break;
192 : }
193 0 : temp.set(JS_NumberValue(double(currentValue.Value())));
194 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->alpha_id, temp, JSPROP_ENUMERATE)) {
195 0 : return false;
196 : }
197 0 : break;
198 : } while(0);
199 :
200 : do {
201 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
202 0 : JS::Rooted<JS::Value> temp(cx);
203 0 : Nullable<double> const & currentValue = mBeta;
204 0 : if (currentValue.IsNull()) {
205 0 : temp.setNull();
206 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->beta_id, temp, JSPROP_ENUMERATE)) {
207 0 : return false;
208 : }
209 0 : break;
210 : }
211 0 : temp.set(JS_NumberValue(double(currentValue.Value())));
212 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->beta_id, temp, JSPROP_ENUMERATE)) {
213 0 : return false;
214 : }
215 0 : break;
216 : } while(0);
217 :
218 : do {
219 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
220 0 : JS::Rooted<JS::Value> temp(cx);
221 0 : Nullable<double> const & currentValue = mGamma;
222 0 : if (currentValue.IsNull()) {
223 0 : temp.setNull();
224 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->gamma_id, temp, JSPROP_ENUMERATE)) {
225 0 : return false;
226 : }
227 0 : break;
228 : }
229 0 : temp.set(JS_NumberValue(double(currentValue.Value())));
230 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->gamma_id, temp, JSPROP_ENUMERATE)) {
231 0 : return false;
232 : }
233 0 : break;
234 : } while(0);
235 :
236 0 : return true;
237 : }
238 :
239 : bool
240 0 : DeviceOrientationEventInit::ToJSON(nsAString& aJSON) const
241 : {
242 0 : AutoJSAPI jsapi;
243 0 : jsapi.Init();
244 0 : JSContext *cx = jsapi.cx();
245 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
246 : // because we'll only be creating objects, in ways that have no
247 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
248 : // which likewise guarantees no side-effects for the sorts of
249 : // things we will pass it.
250 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
251 0 : JS::Rooted<JS::Value> val(cx);
252 0 : if (!ToObjectInternal(cx, &val)) {
253 0 : return false;
254 : }
255 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
256 0 : return StringifyToJSON(cx, obj, aJSON);
257 : }
258 :
259 : void
260 0 : DeviceOrientationEventInit::TraceDictionary(JSTracer* trc)
261 : {
262 0 : EventInit::TraceDictionary(trc);
263 0 : }
264 :
265 : DeviceOrientationEventInit&
266 0 : DeviceOrientationEventInit::operator=(const DeviceOrientationEventInit& aOther)
267 : {
268 0 : EventInit::operator=(aOther);
269 0 : mAbsolute = aOther.mAbsolute;
270 0 : mAlpha = aOther.mAlpha;
271 0 : mBeta = aOther.mBeta;
272 0 : mGamma = aOther.mGamma;
273 0 : return *this;
274 : }
275 :
276 : namespace binding_detail {
277 : } // namespace binding_detail
278 :
279 :
280 : namespace DeviceOrientationEventBinding {
281 :
282 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
283 : "Can't inherit from an interface with a different ownership model.");
284 :
285 : static bool
286 0 : get_alpha(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceOrientationEvent* self, JSJitGetterCallArgs args)
287 : {
288 0 : Nullable<double> result(self->GetAlpha());
289 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
290 0 : if (result.IsNull()) {
291 0 : args.rval().setNull();
292 0 : return true;
293 : }
294 0 : args.rval().set(JS_NumberValue(double(result.Value())));
295 0 : return true;
296 : }
297 :
298 : static const JSJitInfo alpha_getterinfo = {
299 : { (JSJitGetterOp)get_alpha },
300 : { prototypes::id::DeviceOrientationEvent },
301 : { PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth },
302 : JSJitInfo::Getter,
303 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
304 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
305 : true, /* isInfallible. False in setters. */
306 : false, /* isMovable. Not relevant for setters. */
307 : false, /* isEliminatable. Not relevant for setters. */
308 : false, /* isAlwaysInSlot. Only relevant for getters. */
309 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
310 : false, /* isTypedMethod. Only relevant for methods. */
311 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
312 : };
313 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
314 : static_assert(0 < 1, "There is no slot for us");
315 :
316 : static bool
317 0 : get_beta(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceOrientationEvent* self, JSJitGetterCallArgs args)
318 : {
319 0 : Nullable<double> result(self->GetBeta());
320 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
321 0 : if (result.IsNull()) {
322 0 : args.rval().setNull();
323 0 : return true;
324 : }
325 0 : args.rval().set(JS_NumberValue(double(result.Value())));
326 0 : return true;
327 : }
328 :
329 : static const JSJitInfo beta_getterinfo = {
330 : { (JSJitGetterOp)get_beta },
331 : { prototypes::id::DeviceOrientationEvent },
332 : { PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth },
333 : JSJitInfo::Getter,
334 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
335 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
336 : true, /* isInfallible. False in setters. */
337 : false, /* isMovable. Not relevant for setters. */
338 : false, /* isEliminatable. Not relevant for setters. */
339 : false, /* isAlwaysInSlot. Only relevant for getters. */
340 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
341 : false, /* isTypedMethod. Only relevant for methods. */
342 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
343 : };
344 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
345 : static_assert(0 < 1, "There is no slot for us");
346 :
347 : static bool
348 0 : get_gamma(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceOrientationEvent* self, JSJitGetterCallArgs args)
349 : {
350 0 : Nullable<double> result(self->GetGamma());
351 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
352 0 : if (result.IsNull()) {
353 0 : args.rval().setNull();
354 0 : return true;
355 : }
356 0 : args.rval().set(JS_NumberValue(double(result.Value())));
357 0 : return true;
358 : }
359 :
360 : static const JSJitInfo gamma_getterinfo = {
361 : { (JSJitGetterOp)get_gamma },
362 : { prototypes::id::DeviceOrientationEvent },
363 : { PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth },
364 : JSJitInfo::Getter,
365 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
366 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
367 : true, /* isInfallible. False in setters. */
368 : false, /* isMovable. Not relevant for setters. */
369 : false, /* isEliminatable. Not relevant for setters. */
370 : false, /* isAlwaysInSlot. Only relevant for getters. */
371 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
372 : false, /* isTypedMethod. Only relevant for methods. */
373 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
374 : };
375 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
376 : static_assert(0 < 1, "There is no slot for us");
377 :
378 : static bool
379 0 : get_absolute(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceOrientationEvent* self, JSJitGetterCallArgs args)
380 : {
381 0 : bool result(self->Absolute());
382 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
383 0 : args.rval().setBoolean(result);
384 0 : return true;
385 : }
386 :
387 : static const JSJitInfo absolute_getterinfo = {
388 : { (JSJitGetterOp)get_absolute },
389 : { prototypes::id::DeviceOrientationEvent },
390 : { PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth },
391 : JSJitInfo::Getter,
392 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
393 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
394 : true, /* isInfallible. False in setters. */
395 : false, /* isMovable. Not relevant for setters. */
396 : false, /* isEliminatable. Not relevant for setters. */
397 : false, /* isAlwaysInSlot. Only relevant for getters. */
398 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
399 : false, /* isTypedMethod. Only relevant for methods. */
400 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
401 : };
402 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
403 : static_assert(0 < 1, "There is no slot for us");
404 :
405 : static bool
406 0 : initDeviceOrientationEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceOrientationEvent* self, const JSJitMethodCallArgs& args)
407 : {
408 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
409 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DeviceOrientationEvent.initDeviceOrientationEvent");
410 : }
411 0 : binding_detail::FakeString arg0;
412 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
413 0 : return false;
414 : }
415 : bool arg1;
416 0 : if (args.hasDefined(1)) {
417 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
418 0 : return false;
419 : }
420 : } else {
421 0 : arg1 = false;
422 : }
423 : bool arg2;
424 0 : if (args.hasDefined(2)) {
425 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
426 0 : return false;
427 : }
428 : } else {
429 0 : arg2 = false;
430 : }
431 0 : Nullable<double> arg3;
432 0 : if (!(args.hasDefined(3)) || args[3].isNullOrUndefined()) {
433 0 : arg3.SetNull();
434 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, args[3], &arg3.SetValue())) {
435 0 : return false;
436 0 : } else if (!mozilla::IsFinite(arg3.Value())) {
437 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 4 of DeviceOrientationEvent.initDeviceOrientationEvent");
438 0 : return false;
439 : }
440 0 : Nullable<double> arg4;
441 0 : if (!(args.hasDefined(4)) || args[4].isNullOrUndefined()) {
442 0 : arg4.SetNull();
443 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, args[4], &arg4.SetValue())) {
444 0 : return false;
445 0 : } else if (!mozilla::IsFinite(arg4.Value())) {
446 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 5 of DeviceOrientationEvent.initDeviceOrientationEvent");
447 0 : return false;
448 : }
449 0 : Nullable<double> arg5;
450 0 : if (!(args.hasDefined(5)) || args[5].isNullOrUndefined()) {
451 0 : arg5.SetNull();
452 0 : } else if (!ValueToPrimitive<double, eDefault>(cx, args[5], &arg5.SetValue())) {
453 0 : return false;
454 0 : } else if (!mozilla::IsFinite(arg5.Value())) {
455 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 6 of DeviceOrientationEvent.initDeviceOrientationEvent");
456 0 : return false;
457 : }
458 : bool arg6;
459 0 : if (args.hasDefined(6)) {
460 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[6], &arg6)) {
461 0 : return false;
462 : }
463 : } else {
464 0 : arg6 = false;
465 : }
466 0 : self->InitDeviceOrientationEvent(NonNullHelper(Constify(arg0)), arg1, arg2, Constify(arg3), Constify(arg4), Constify(arg5), arg6);
467 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
468 0 : args.rval().setUndefined();
469 0 : return true;
470 : }
471 :
472 : static const JSJitInfo initDeviceOrientationEvent_methodinfo = {
473 : { (JSJitGetterOp)initDeviceOrientationEvent },
474 : { prototypes::id::DeviceOrientationEvent },
475 : { PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth },
476 : JSJitInfo::Method,
477 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
478 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
479 : false, /* isInfallible. False in setters. */
480 : false, /* isMovable. Not relevant for setters. */
481 : false, /* isEliminatable. Not relevant for setters. */
482 : false, /* isAlwaysInSlot. Only relevant for getters. */
483 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
484 : false, /* isTypedMethod. Only relevant for methods. */
485 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
486 : };
487 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
488 : static_assert(0 < 1, "There is no slot for us");
489 :
490 : static bool
491 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DeviceOrientationEvent* self, JSJitGetterCallArgs args)
492 : {
493 0 : bool result(self->IsTrusted());
494 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
495 0 : args.rval().setBoolean(result);
496 0 : return true;
497 : }
498 :
499 : static const JSJitInfo isTrusted_getterinfo = {
500 : { (JSJitGetterOp)get_isTrusted },
501 : { prototypes::id::DeviceOrientationEvent },
502 : { PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth },
503 : JSJitInfo::Getter,
504 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
505 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
506 : true, /* isInfallible. False in setters. */
507 : true, /* isMovable. Not relevant for setters. */
508 : true, /* isEliminatable. Not relevant for setters. */
509 : false, /* isAlwaysInSlot. Only relevant for getters. */
510 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
511 : false, /* isTypedMethod. Only relevant for methods. */
512 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
513 : };
514 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
515 : static_assert(0 < 1, "There is no slot for us");
516 :
517 : static bool
518 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
519 : {
520 0 : mozilla::dom::DeviceOrientationEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceOrientationEvent>(obj);
521 : // We don't want to preserve if we don't have a wrapper, and we
522 : // obviously can't preserve if we're not initialized.
523 0 : if (self && self->GetWrapperPreserveColor()) {
524 0 : PreserveWrapper(self);
525 : }
526 0 : return true;
527 : }
528 :
529 : static void
530 0 : _finalize(js::FreeOp* fop, JSObject* obj)
531 : {
532 0 : mozilla::dom::DeviceOrientationEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceOrientationEvent>(obj);
533 0 : if (self) {
534 0 : ClearWrapper(self, self, obj);
535 0 : AddForDeferredFinalization<mozilla::dom::DeviceOrientationEvent>(self);
536 : }
537 0 : }
538 :
539 : static void
540 0 : _objectMoved(JSObject* obj, const JSObject* old)
541 : {
542 0 : mozilla::dom::DeviceOrientationEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DeviceOrientationEvent>(obj);
543 0 : if (self) {
544 0 : UpdateWrapper(self, self, obj, old);
545 : }
546 0 : }
547 :
548 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
549 : #if defined(__clang__)
550 : #pragma clang diagnostic push
551 : #pragma clang diagnostic ignored "-Wmissing-braces"
552 : #endif
553 : static const JSFunctionSpec sMethods_specs[] = {
554 : JS_FNSPEC("initDeviceOrientationEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&initDeviceOrientationEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
555 : JS_FS_END
556 : };
557 : #if defined(__clang__)
558 : #pragma clang diagnostic pop
559 : #endif
560 :
561 :
562 : // Can't be const because the pref-enabled boolean needs to be writable
563 : static Prefable<const JSFunctionSpec> sMethods[] = {
564 : { nullptr, &sMethods_specs[0] },
565 : { nullptr, nullptr }
566 : };
567 :
568 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
569 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
570 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
571 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
572 :
573 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
574 : #if defined(__clang__)
575 : #pragma clang diagnostic push
576 : #pragma clang diagnostic ignored "-Wmissing-braces"
577 : #endif
578 : static const JSPropertySpec sAttributes_specs[] = {
579 : { "alpha", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &alpha_getterinfo, nullptr, nullptr },
580 : { "beta", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &beta_getterinfo, nullptr, nullptr },
581 : { "gamma", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &gamma_getterinfo, nullptr, nullptr },
582 : { "absolute", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &absolute_getterinfo, nullptr, nullptr },
583 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
584 : };
585 : #if defined(__clang__)
586 : #pragma clang diagnostic pop
587 : #endif
588 :
589 :
590 : // Can't be const because the pref-enabled boolean needs to be writable
591 : static Prefable<const JSPropertySpec> sAttributes[] = {
592 : { nullptr, &sAttributes_specs[0] },
593 : { nullptr, nullptr }
594 : };
595 :
596 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
597 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
598 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
599 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
600 :
601 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
602 : #if defined(__clang__)
603 : #pragma clang diagnostic push
604 : #pragma clang diagnostic ignored "-Wmissing-braces"
605 : #endif
606 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
607 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
608 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
609 : };
610 : #if defined(__clang__)
611 : #pragma clang diagnostic pop
612 : #endif
613 :
614 :
615 : // Can't be const because the pref-enabled boolean needs to be writable
616 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
617 : { nullptr, &sUnforgeableAttributes_specs[0] },
618 : { nullptr, nullptr }
619 : };
620 :
621 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
622 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
623 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
624 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
625 :
626 :
627 : static uint16_t sNativeProperties_sortedPropertyIndices[6];
628 : static PropertyInfo sNativeProperties_propertyInfos[6];
629 :
630 : static const NativePropertiesN<3> sNativeProperties = {
631 : false, 0,
632 : false, 0,
633 : true, 0 /* sMethods */,
634 : true, 1 /* sAttributes */,
635 : false, 0,
636 : true, 2 /* sUnforgeableAttributes */,
637 : false, 0,
638 : -1,
639 : 6,
640 : sNativeProperties_sortedPropertyIndices,
641 : {
642 : { sMethods, &sNativeProperties_propertyInfos[0] },
643 : { sAttributes, &sNativeProperties_propertyInfos[1] },
644 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[5] }
645 : }
646 : };
647 : static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
648 : "We have a property info count that is oversized");
649 :
650 : static bool
651 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
652 : {
653 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
654 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
655 0 : if (!args.isConstructing()) {
656 : // XXXbz wish I could get the name from the callee instead of
657 : // Adding more relocations
658 0 : return ThrowConstructorWithoutNew(cx, "DeviceOrientationEvent");
659 : }
660 :
661 0 : GlobalObject global(cx, obj);
662 0 : if (global.Failed()) {
663 0 : return false;
664 : }
665 :
666 0 : JS::Rooted<JSObject*> desiredProto(cx);
667 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
668 0 : return false;
669 : }
670 :
671 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
672 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DeviceOrientationEvent");
673 : }
674 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
675 0 : binding_detail::FakeString arg0;
676 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
677 0 : return false;
678 : }
679 0 : binding_detail::FastDeviceOrientationEventInit arg1;
680 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of DeviceOrientationEvent.constructor", false)) {
681 0 : return false;
682 : }
683 0 : Maybe<JSAutoCompartment> ac;
684 0 : if (objIsXray) {
685 0 : obj = js::CheckedUnwrap(obj);
686 0 : if (!obj) {
687 0 : return false;
688 : }
689 0 : ac.emplace(cx, obj);
690 0 : if (!JS_WrapObject(cx, &desiredProto)) {
691 0 : return false;
692 : }
693 : }
694 0 : binding_detail::FastErrorResult rv;
695 0 : auto result(StrongOrRawPtr<mozilla::dom::DeviceOrientationEvent>(mozilla::dom::DeviceOrientationEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
696 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
697 0 : return false;
698 : }
699 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
700 : static_assert(!IsPointer<decltype(result)>::value,
701 : "NewObject implies that we need to keep the object alive with a strong reference.");
702 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
703 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
704 0 : return false;
705 : }
706 0 : return true;
707 : }
708 :
709 : static const js::ClassOps sInterfaceObjectClassOps = {
710 : nullptr, /* addProperty */
711 : nullptr, /* delProperty */
712 : nullptr, /* getProperty */
713 : nullptr, /* setProperty */
714 : nullptr, /* enumerate */
715 : nullptr, /* newEnumerate */
716 : nullptr, /* resolve */
717 : nullptr, /* mayResolve */
718 : nullptr, /* finalize */
719 : _constructor, /* call */
720 : nullptr, /* hasInstance */
721 : _constructor, /* construct */
722 : nullptr, /* trace */
723 : };
724 :
725 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
726 : {
727 : "Function",
728 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
729 : &sInterfaceObjectClassOps,
730 : JS_NULL_CLASS_SPEC,
731 : JS_NULL_CLASS_EXT,
732 : &sInterfaceObjectClassObjectOps
733 : },
734 : eInterface,
735 : true,
736 : prototypes::id::DeviceOrientationEvent,
737 : PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth,
738 : sNativePropertyHooks,
739 : "function DeviceOrientationEvent() {\n [native code]\n}",
740 : EventBinding::GetConstructorObject
741 : };
742 :
743 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
744 : {
745 : "DeviceOrientationEventPrototype",
746 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
747 : JS_NULL_CLASS_OPS,
748 : JS_NULL_CLASS_SPEC,
749 : JS_NULL_CLASS_EXT,
750 : JS_NULL_OBJECT_OPS
751 : },
752 : eInterfacePrototype,
753 : false,
754 : prototypes::id::DeviceOrientationEvent,
755 : PrototypeTraits<prototypes::id::DeviceOrientationEvent>::Depth,
756 : sNativePropertyHooks,
757 : "[object DeviceOrientationEventPrototype]",
758 : EventBinding::GetProtoObject
759 : };
760 :
761 : JSObject*
762 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
763 : {
764 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
765 : }
766 :
767 : static const js::ClassOps sClassOps = {
768 : _addProperty, /* addProperty */
769 : nullptr, /* delProperty */
770 : nullptr, /* getProperty */
771 : nullptr, /* setProperty */
772 : nullptr, /* enumerate */
773 : nullptr, /* newEnumerate */
774 : nullptr, /* resolve */
775 : nullptr, /* mayResolve */
776 : _finalize, /* finalize */
777 : nullptr, /* call */
778 : nullptr, /* hasInstance */
779 : nullptr, /* construct */
780 : nullptr, /* trace */
781 : };
782 :
783 : static const js::ClassExtension sClassExtension = {
784 : nullptr, /* weakmapKeyDelegateOp */
785 : _objectMoved /* objectMovedOp */
786 : };
787 :
788 : static const DOMJSClass sClass = {
789 : { "DeviceOrientationEvent",
790 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
791 : &sClassOps,
792 : JS_NULL_CLASS_SPEC,
793 : &sClassExtension,
794 : JS_NULL_OBJECT_OPS
795 : },
796 : { prototypes::id::Event, prototypes::id::DeviceOrientationEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
797 : IsBaseOf<nsISupports, mozilla::dom::DeviceOrientationEvent >::value,
798 : sNativePropertyHooks,
799 : FindAssociatedGlobalForNative<mozilla::dom::DeviceOrientationEvent>::Get,
800 : GetProtoObjectHandle,
801 : GetCCParticipant<mozilla::dom::DeviceOrientationEvent>::Get()
802 : };
803 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
804 : "Must have the right minimal number of reserved slots.");
805 : static_assert(1 >= 1,
806 : "Must have enough reserved slots.");
807 :
808 : const JSClass*
809 0 : GetJSClass()
810 : {
811 0 : return sClass.ToJSClass();
812 : }
813 :
814 : bool
815 0 : Wrap(JSContext* aCx, mozilla::dom::DeviceOrientationEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
816 : {
817 : MOZ_ASSERT(static_cast<mozilla::dom::DeviceOrientationEvent*>(aObject) ==
818 : reinterpret_cast<mozilla::dom::DeviceOrientationEvent*>(aObject),
819 : "Multiple inheritance for mozilla::dom::DeviceOrientationEvent is broken.");
820 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
821 : reinterpret_cast<mozilla::dom::Event*>(aObject),
822 : "Multiple inheritance for mozilla::dom::Event is broken.");
823 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
824 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
825 0 : MOZ_ASSERT(!aCache->GetWrapper(),
826 : "You should probably not be using Wrap() directly; use "
827 : "GetOrCreateDOMReflector instead");
828 :
829 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
830 : "nsISupports must be on our primary inheritance chain");
831 :
832 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
833 0 : if (!global) {
834 0 : return false;
835 : }
836 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
837 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
838 :
839 : // That might have ended up wrapping us already, due to the wonders
840 : // of XBL. Check for that, and bail out as needed.
841 0 : aReflector.set(aCache->GetWrapper());
842 0 : if (aReflector) {
843 : #ifdef DEBUG
844 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
845 : #endif // DEBUG
846 0 : return true;
847 : }
848 :
849 0 : JSAutoCompartment ac(aCx, global);
850 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
851 0 : if (!canonicalProto) {
852 0 : return false;
853 : }
854 0 : JS::Rooted<JSObject*> proto(aCx);
855 0 : if (aGivenProto) {
856 0 : proto = aGivenProto;
857 : // Unfortunately, while aGivenProto was in the compartment of aCx
858 : // coming in, we changed compartments to that of "parent" so may need
859 : // to wrap the proto here.
860 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
861 0 : if (!JS_WrapObject(aCx, &proto)) {
862 0 : return false;
863 : }
864 : }
865 : } else {
866 0 : proto = canonicalProto;
867 : }
868 :
869 0 : BindingJSObjectCreator<mozilla::dom::DeviceOrientationEvent> creator(aCx);
870 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
871 0 : if (!aReflector) {
872 0 : return false;
873 : }
874 :
875 0 : aCache->SetWrapper(aReflector);
876 :
877 : // Important: do unforgeable property setup after we have handed
878 : // over ownership of the C++ object to obj as needed, so that if
879 : // we fail and it ends up GCed it won't have problems in the
880 : // finalizer trying to drop its ownership of the C++ object.
881 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
882 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
883 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
884 0 : aCache->ReleaseWrapper(aObject);
885 0 : aCache->ClearWrapper();
886 0 : return false;
887 : }
888 0 : creator.InitializationSucceeded();
889 :
890 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
891 : aCache->GetWrapperPreserveColor() == aReflector);
892 : // If proto != canonicalProto, we have to preserve our wrapper;
893 : // otherwise we won't be able to properly recreate it later, since
894 : // we won't know what proto to use. Note that we don't check
895 : // aGivenProto here, since it's entirely possible (and even
896 : // somewhat common) to have a non-null aGivenProto which is the
897 : // same as canonicalProto.
898 0 : if (proto != canonicalProto) {
899 0 : PreserveWrapper(aObject);
900 : }
901 :
902 0 : return true;
903 : }
904 :
905 : const NativePropertyHooks sNativePropertyHooks[] = { {
906 : nullptr,
907 : nullptr,
908 : nullptr,
909 : { sNativeProperties.Upcast(), nullptr },
910 : prototypes::id::DeviceOrientationEvent,
911 : constructors::id::DeviceOrientationEvent,
912 : EventBinding::sNativePropertyHooks,
913 : &DefaultXrayExpandoObjectClass
914 : } };
915 :
916 : void
917 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
918 : {
919 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
920 0 : if (!parentProto) {
921 0 : return;
922 : }
923 :
924 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
925 0 : if (!constructorProto) {
926 0 : return;
927 : }
928 :
929 : static bool sIdsInited = false;
930 0 : if (!sIdsInited && NS_IsMainThread()) {
931 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
932 0 : return;
933 : }
934 0 : sIdsInited = true;
935 : }
936 :
937 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DeviceOrientationEvent);
938 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DeviceOrientationEvent);
939 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
940 : &sPrototypeClass.mBase, protoCache,
941 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
942 : interfaceCache,
943 : sNativeProperties.Upcast(),
944 : nullptr,
945 : "DeviceOrientationEvent", aDefineOnGlobal,
946 : nullptr,
947 0 : false);
948 :
949 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
950 : {
951 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
952 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
953 0 : if (!unforgeableHolder) {
954 0 : *protoCache = nullptr;
955 0 : if (interfaceCache) {
956 0 : *interfaceCache = nullptr;
957 : }
958 0 : return;
959 : }
960 : }
961 :
962 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
963 0 : *protoCache = nullptr;
964 0 : if (interfaceCache) {
965 0 : *interfaceCache = nullptr;
966 : }
967 0 : return;
968 : }
969 :
970 0 : if (*protoCache) {
971 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
972 0 : JS::ObjectValue(*unforgeableHolder));
973 : }
974 : }
975 :
976 : JS::Handle<JSObject*>
977 0 : GetProtoObjectHandle(JSContext* aCx)
978 : {
979 : /* Get the interface prototype object for this class. This will create the
980 : object as needed. */
981 0 : bool aDefineOnGlobal = true;
982 :
983 : /* Make sure our global is sane. Hopefully we can remove this sometime */
984 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
985 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
986 0 : return nullptr;
987 : }
988 :
989 : /* Check to see whether the interface objects are already installed */
990 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
991 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::DeviceOrientationEvent)) {
992 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
993 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
994 : }
995 :
996 : /*
997 : * The object might _still_ be null, but that's OK.
998 : *
999 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1000 : * traced by TraceProtoAndIfaceCache() and its contents are never
1001 : * changed after they have been set.
1002 : *
1003 : * Calling address() avoids the read read barrier that does gray
1004 : * unmarking, but it's not possible for the object to be gray here.
1005 : */
1006 :
1007 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::DeviceOrientationEvent);
1008 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1009 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1010 : }
1011 :
1012 : JS::Handle<JSObject*>
1013 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1014 : {
1015 : /* Get the interface object for this class. This will create the object as
1016 : needed. */
1017 :
1018 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1019 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1020 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1021 0 : return nullptr;
1022 : }
1023 :
1024 : /* Check to see whether the interface objects are already installed */
1025 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1026 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::DeviceOrientationEvent)) {
1027 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1028 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1029 : }
1030 :
1031 : /*
1032 : * The object might _still_ be null, but that's OK.
1033 : *
1034 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1035 : * traced by TraceProtoAndIfaceCache() and its contents are never
1036 : * changed after they have been set.
1037 : *
1038 : * Calling address() avoids the read read barrier that does gray
1039 : * unmarking, but it's not possible for the object to be gray here.
1040 : */
1041 :
1042 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::DeviceOrientationEvent);
1043 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1044 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1045 : }
1046 :
1047 : JSObject*
1048 0 : GetConstructorObject(JSContext* aCx)
1049 : {
1050 0 : return GetConstructorObjectHandle(aCx);
1051 : }
1052 :
1053 : } // namespace DeviceOrientationEventBinding
1054 :
1055 :
1056 :
1057 : } // namespace dom
1058 : } // namespace mozilla
|