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