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