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