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