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