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