Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM VRServiceTest.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "VRServiceTestBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "jsfriendapi.h"
6 : #include "mozilla/FloatingPoint.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/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/Nullable.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/Promise.h"
15 : #include "mozilla/dom/ToJSValue.h"
16 : #include "mozilla/dom/TypedArray.h"
17 : #include "mozilla/dom/VRServiceTest.h"
18 : #include "mozilla/dom/XrayExpandoClass.h"
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 : namespace VRMockControllerBinding {
24 :
25 : static bool
26 0 : newButtonEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockController* self, const JSJitMethodCallArgs& args)
27 : {
28 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
29 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockController.newButtonEvent");
30 : }
31 : uint32_t arg0;
32 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
33 0 : return false;
34 : }
35 : bool arg1;
36 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
37 0 : return false;
38 : }
39 0 : self->NewButtonEvent(arg0, arg1);
40 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
41 0 : args.rval().setUndefined();
42 0 : return true;
43 : }
44 :
45 : static const JSJitInfo newButtonEvent_methodinfo = {
46 : { (JSJitGetterOp)newButtonEvent },
47 : { prototypes::id::VRMockController },
48 : { PrototypeTraits<prototypes::id::VRMockController>::Depth },
49 : JSJitInfo::Method,
50 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
51 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
52 : false, /* isInfallible. False in setters. */
53 : false, /* isMovable. Not relevant for setters. */
54 : false, /* isEliminatable. Not relevant for setters. */
55 : false, /* isAlwaysInSlot. Only relevant for getters. */
56 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
57 : false, /* isTypedMethod. Only relevant for methods. */
58 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
59 : };
60 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
61 : static_assert(0 < 1, "There is no slot for us");
62 :
63 : static bool
64 0 : newAxisMoveEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockController* self, const JSJitMethodCallArgs& args)
65 : {
66 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
67 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockController.newAxisMoveEvent");
68 : }
69 : uint32_t arg0;
70 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
71 0 : return false;
72 : }
73 : double arg1;
74 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) {
75 0 : return false;
76 0 : } else if (!mozilla::IsFinite(arg1)) {
77 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of VRMockController.newAxisMoveEvent");
78 0 : return false;
79 : }
80 0 : self->NewAxisMoveEvent(arg0, arg1);
81 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
82 0 : args.rval().setUndefined();
83 0 : return true;
84 : }
85 :
86 : static const JSJitInfo newAxisMoveEvent_methodinfo = {
87 : { (JSJitGetterOp)newAxisMoveEvent },
88 : { prototypes::id::VRMockController },
89 : { PrototypeTraits<prototypes::id::VRMockController>::Depth },
90 : JSJitInfo::Method,
91 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
92 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
93 : false, /* isInfallible. False in setters. */
94 : false, /* isMovable. Not relevant for setters. */
95 : false, /* isEliminatable. Not relevant for setters. */
96 : false, /* isAlwaysInSlot. Only relevant for getters. */
97 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
98 : false, /* isTypedMethod. Only relevant for methods. */
99 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
100 : };
101 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
102 : static_assert(0 < 1, "There is no slot for us");
103 :
104 : static bool
105 0 : newPoseMove(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockController* self, const JSJitMethodCallArgs& args)
106 : {
107 0 : if (MOZ_UNLIKELY(args.length() < 6)) {
108 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockController.newPoseMove");
109 : }
110 0 : RootedTypedArray<Nullable<Float32Array>> arg0(cx);
111 0 : if (args[0].isObject()) {
112 0 : if (!arg0.SetValue().Init(&args[0].toObject())) {
113 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of VRMockController.newPoseMove", "Float32ArrayOrNull");
114 0 : return false;
115 : }
116 0 : } else if (args[0].isNullOrUndefined()) {
117 0 : arg0.SetNull();
118 : } else {
119 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of VRMockController.newPoseMove");
120 0 : return false;
121 : }
122 0 : RootedTypedArray<Nullable<Float32Array>> arg1(cx);
123 0 : if (args[1].isObject()) {
124 0 : if (!arg1.SetValue().Init(&args[1].toObject())) {
125 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of VRMockController.newPoseMove", "Float32ArrayOrNull");
126 0 : return false;
127 : }
128 0 : } else if (args[1].isNullOrUndefined()) {
129 0 : arg1.SetNull();
130 : } else {
131 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of VRMockController.newPoseMove");
132 0 : return false;
133 : }
134 0 : RootedTypedArray<Nullable<Float32Array>> arg2(cx);
135 0 : if (args[2].isObject()) {
136 0 : if (!arg2.SetValue().Init(&args[2].toObject())) {
137 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 3 of VRMockController.newPoseMove", "Float32ArrayOrNull");
138 0 : return false;
139 : }
140 0 : } else if (args[2].isNullOrUndefined()) {
141 0 : arg2.SetNull();
142 : } else {
143 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of VRMockController.newPoseMove");
144 0 : return false;
145 : }
146 0 : RootedTypedArray<Nullable<Float32Array>> arg3(cx);
147 0 : if (args[3].isObject()) {
148 0 : if (!arg3.SetValue().Init(&args[3].toObject())) {
149 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of VRMockController.newPoseMove", "Float32ArrayOrNull");
150 0 : return false;
151 : }
152 0 : } else if (args[3].isNullOrUndefined()) {
153 0 : arg3.SetNull();
154 : } else {
155 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of VRMockController.newPoseMove");
156 0 : return false;
157 : }
158 0 : RootedTypedArray<Nullable<Float32Array>> arg4(cx);
159 0 : if (args[4].isObject()) {
160 0 : if (!arg4.SetValue().Init(&args[4].toObject())) {
161 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 5 of VRMockController.newPoseMove", "Float32ArrayOrNull");
162 0 : return false;
163 : }
164 0 : } else if (args[4].isNullOrUndefined()) {
165 0 : arg4.SetNull();
166 : } else {
167 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 5 of VRMockController.newPoseMove");
168 0 : return false;
169 : }
170 0 : RootedTypedArray<Nullable<Float32Array>> arg5(cx);
171 0 : if (args[5].isObject()) {
172 0 : if (!arg5.SetValue().Init(&args[5].toObject())) {
173 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 6 of VRMockController.newPoseMove", "Float32ArrayOrNull");
174 0 : return false;
175 : }
176 0 : } else if (args[5].isNullOrUndefined()) {
177 0 : arg5.SetNull();
178 : } else {
179 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 6 of VRMockController.newPoseMove");
180 0 : return false;
181 : }
182 0 : self->NewPoseMove(Constify(arg0), Constify(arg1), Constify(arg2), Constify(arg3), Constify(arg4), Constify(arg5));
183 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
184 0 : args.rval().setUndefined();
185 0 : return true;
186 : }
187 :
188 : static const JSJitInfo newPoseMove_methodinfo = {
189 : { (JSJitGetterOp)newPoseMove },
190 : { prototypes::id::VRMockController },
191 : { PrototypeTraits<prototypes::id::VRMockController>::Depth },
192 : JSJitInfo::Method,
193 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
194 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
195 : false, /* 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 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
208 : {
209 0 : mozilla::dom::VRMockController* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRMockController>(obj);
210 : // We don't want to preserve if we don't have a wrapper, and we
211 : // obviously can't preserve if we're not initialized.
212 0 : if (self && self->GetWrapperPreserveColor()) {
213 0 : PreserveWrapper(self);
214 : }
215 0 : return true;
216 : }
217 :
218 : static void
219 0 : _finalize(js::FreeOp* fop, JSObject* obj)
220 : {
221 0 : mozilla::dom::VRMockController* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRMockController>(obj);
222 0 : if (self) {
223 0 : ClearWrapper(self, self, obj);
224 0 : AddForDeferredFinalization<mozilla::dom::VRMockController>(self);
225 : }
226 0 : }
227 :
228 : static void
229 0 : _objectMoved(JSObject* obj, const JSObject* old)
230 : {
231 0 : mozilla::dom::VRMockController* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRMockController>(obj);
232 0 : if (self) {
233 0 : UpdateWrapper(self, self, obj, old);
234 : }
235 0 : }
236 :
237 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
238 : #if defined(__clang__)
239 : #pragma clang diagnostic push
240 : #pragma clang diagnostic ignored "-Wmissing-braces"
241 : #endif
242 : static const JSFunctionSpec sMethods_specs[] = {
243 : JS_FNSPEC("newButtonEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&newButtonEvent_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
244 : JS_FNSPEC("newAxisMoveEvent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&newAxisMoveEvent_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
245 : JS_FNSPEC("newPoseMove", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&newPoseMove_methodinfo), 6, JSPROP_ENUMERATE, nullptr),
246 : JS_FS_END
247 : };
248 : #if defined(__clang__)
249 : #pragma clang diagnostic pop
250 : #endif
251 :
252 :
253 : // Can't be const because the pref-enabled boolean needs to be writable
254 : static Prefable<const JSFunctionSpec> sMethods[] = {
255 : { nullptr, &sMethods_specs[0] },
256 : { nullptr, nullptr }
257 : };
258 :
259 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
260 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
261 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
262 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
263 :
264 :
265 : static uint16_t sNativeProperties_sortedPropertyIndices[3];
266 : static PropertyInfo sNativeProperties_propertyInfos[3];
267 :
268 : static const NativePropertiesN<1> sNativeProperties = {
269 : false, 0,
270 : false, 0,
271 : true, 0 /* sMethods */,
272 : false, 0,
273 : false, 0,
274 : false, 0,
275 : false, 0,
276 : -1,
277 : 3,
278 : sNativeProperties_sortedPropertyIndices,
279 : {
280 : { sMethods, &sNativeProperties_propertyInfos[0] }
281 : }
282 : };
283 : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
284 : "We have a property info count that is oversized");
285 :
286 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
287 : {
288 : "Function",
289 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
290 : &sBoringInterfaceObjectClassClassOps,
291 : JS_NULL_CLASS_SPEC,
292 : JS_NULL_CLASS_EXT,
293 : &sInterfaceObjectClassObjectOps
294 : },
295 : eInterface,
296 : true,
297 : prototypes::id::VRMockController,
298 : PrototypeTraits<prototypes::id::VRMockController>::Depth,
299 : sNativePropertyHooks,
300 : "function VRMockController() {\n [native code]\n}",
301 : JS::GetRealmFunctionPrototype
302 : };
303 :
304 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
305 : {
306 : "VRMockControllerPrototype",
307 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
308 : JS_NULL_CLASS_OPS,
309 : JS_NULL_CLASS_SPEC,
310 : JS_NULL_CLASS_EXT,
311 : JS_NULL_OBJECT_OPS
312 : },
313 : eInterfacePrototype,
314 : false,
315 : prototypes::id::VRMockController,
316 : PrototypeTraits<prototypes::id::VRMockController>::Depth,
317 : sNativePropertyHooks,
318 : "[object VRMockControllerPrototype]",
319 : JS::GetRealmObjectPrototype
320 : };
321 :
322 : bool
323 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
324 : {
325 : static bool sPrefValue;
326 : static bool sPrefCacheSetUp = false;
327 0 : if (!sPrefCacheSetUp) {
328 0 : sPrefCacheSetUp = true;
329 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.vr.test.enabled");
330 : }
331 :
332 0 : return sPrefValue;
333 : }
334 :
335 : JSObject*
336 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
337 : {
338 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
339 : }
340 :
341 : static const js::ClassOps sClassOps = {
342 : _addProperty, /* addProperty */
343 : nullptr, /* delProperty */
344 : nullptr, /* getProperty */
345 : nullptr, /* setProperty */
346 : nullptr, /* enumerate */
347 : nullptr, /* newEnumerate */
348 : nullptr, /* resolve */
349 : nullptr, /* mayResolve */
350 : _finalize, /* finalize */
351 : nullptr, /* call */
352 : nullptr, /* hasInstance */
353 : nullptr, /* construct */
354 : nullptr, /* trace */
355 : };
356 :
357 : static const js::ClassExtension sClassExtension = {
358 : nullptr, /* weakmapKeyDelegateOp */
359 : _objectMoved /* objectMovedOp */
360 : };
361 :
362 : static const DOMJSClass sClass = {
363 : { "VRMockController",
364 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
365 : &sClassOps,
366 : JS_NULL_CLASS_SPEC,
367 : &sClassExtension,
368 : JS_NULL_OBJECT_OPS
369 : },
370 : { prototypes::id::VRMockController, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
371 : IsBaseOf<nsISupports, mozilla::dom::VRMockController >::value,
372 : sNativePropertyHooks,
373 : FindAssociatedGlobalForNative<mozilla::dom::VRMockController>::Get,
374 : GetProtoObjectHandle,
375 : GetCCParticipant<mozilla::dom::VRMockController>::Get()
376 : };
377 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
378 : "Must have the right minimal number of reserved slots.");
379 : static_assert(1 >= 1,
380 : "Must have enough reserved slots.");
381 :
382 : const JSClass*
383 0 : GetJSClass()
384 : {
385 0 : return sClass.ToJSClass();
386 : }
387 :
388 : bool
389 0 : Wrap(JSContext* aCx, mozilla::dom::VRMockController* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
390 : {
391 : MOZ_ASSERT(static_cast<mozilla::dom::VRMockController*>(aObject) ==
392 : reinterpret_cast<mozilla::dom::VRMockController*>(aObject),
393 : "Multiple inheritance for mozilla::dom::VRMockController is broken.");
394 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
395 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
396 0 : MOZ_ASSERT(!aCache->GetWrapper(),
397 : "You should probably not be using Wrap() directly; use "
398 : "GetOrCreateDOMReflector instead");
399 :
400 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
401 : "nsISupports must be on our primary inheritance chain");
402 :
403 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
404 0 : if (!global) {
405 0 : return false;
406 : }
407 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
408 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
409 :
410 : // That might have ended up wrapping us already, due to the wonders
411 : // of XBL. Check for that, and bail out as needed.
412 0 : aReflector.set(aCache->GetWrapper());
413 0 : if (aReflector) {
414 : #ifdef DEBUG
415 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
416 : #endif // DEBUG
417 0 : return true;
418 : }
419 :
420 0 : JSAutoCompartment ac(aCx, global);
421 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
422 0 : if (!canonicalProto) {
423 0 : return false;
424 : }
425 0 : JS::Rooted<JSObject*> proto(aCx);
426 0 : if (aGivenProto) {
427 0 : proto = aGivenProto;
428 : // Unfortunately, while aGivenProto was in the compartment of aCx
429 : // coming in, we changed compartments to that of "parent" so may need
430 : // to wrap the proto here.
431 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
432 0 : if (!JS_WrapObject(aCx, &proto)) {
433 0 : return false;
434 : }
435 : }
436 : } else {
437 0 : proto = canonicalProto;
438 : }
439 :
440 0 : BindingJSObjectCreator<mozilla::dom::VRMockController> creator(aCx);
441 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
442 0 : if (!aReflector) {
443 0 : return false;
444 : }
445 :
446 0 : aCache->SetWrapper(aReflector);
447 0 : creator.InitializationSucceeded();
448 :
449 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
450 : aCache->GetWrapperPreserveColor() == aReflector);
451 : // If proto != canonicalProto, we have to preserve our wrapper;
452 : // otherwise we won't be able to properly recreate it later, since
453 : // we won't know what proto to use. Note that we don't check
454 : // aGivenProto here, since it's entirely possible (and even
455 : // somewhat common) to have a non-null aGivenProto which is the
456 : // same as canonicalProto.
457 0 : if (proto != canonicalProto) {
458 0 : PreserveWrapper(aObject);
459 : }
460 :
461 0 : return true;
462 : }
463 :
464 : const NativePropertyHooks sNativePropertyHooks[] = { {
465 : nullptr,
466 : nullptr,
467 : nullptr,
468 : { sNativeProperties.Upcast(), nullptr },
469 : prototypes::id::VRMockController,
470 : constructors::id::VRMockController,
471 : nullptr,
472 : &DefaultXrayExpandoObjectClass
473 : } };
474 :
475 : void
476 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
477 : {
478 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
479 0 : if (!parentProto) {
480 0 : return;
481 : }
482 :
483 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
484 0 : if (!constructorProto) {
485 0 : return;
486 : }
487 :
488 : static bool sIdsInited = false;
489 0 : if (!sIdsInited && NS_IsMainThread()) {
490 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
491 0 : return;
492 : }
493 0 : sIdsInited = true;
494 : }
495 :
496 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::VRMockController);
497 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::VRMockController);
498 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
499 : &sPrototypeClass.mBase, protoCache,
500 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
501 : interfaceCache,
502 : sNativeProperties.Upcast(),
503 : nullptr,
504 : "VRMockController", aDefineOnGlobal,
505 : nullptr,
506 0 : false);
507 : }
508 :
509 : JS::Handle<JSObject*>
510 0 : GetProtoObjectHandle(JSContext* aCx)
511 : {
512 : /* Get the interface prototype object for this class. This will create the
513 : object as needed. */
514 0 : bool aDefineOnGlobal = true;
515 :
516 : /* Make sure our global is sane. Hopefully we can remove this sometime */
517 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
518 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
519 0 : return nullptr;
520 : }
521 :
522 : /* Check to see whether the interface objects are already installed */
523 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
524 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::VRMockController)) {
525 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
526 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
527 : }
528 :
529 : /*
530 : * The object might _still_ be null, but that's OK.
531 : *
532 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
533 : * traced by TraceProtoAndIfaceCache() and its contents are never
534 : * changed after they have been set.
535 : *
536 : * Calling address() avoids the read read barrier that does gray
537 : * unmarking, but it's not possible for the object to be gray here.
538 : */
539 :
540 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::VRMockController);
541 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
542 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
543 : }
544 :
545 : JS::Handle<JSObject*>
546 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
547 : {
548 : /* Get the interface object for this class. This will create the object as
549 : needed. */
550 :
551 : /* Make sure our global is sane. Hopefully we can remove this sometime */
552 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
553 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
554 0 : return nullptr;
555 : }
556 :
557 : /* Check to see whether the interface objects are already installed */
558 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
559 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::VRMockController)) {
560 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
561 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
562 : }
563 :
564 : /*
565 : * The object might _still_ be null, but that's OK.
566 : *
567 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
568 : * traced by TraceProtoAndIfaceCache() and its contents are never
569 : * changed after they have been set.
570 : *
571 : * Calling address() avoids the read read barrier that does gray
572 : * unmarking, but it's not possible for the object to be gray here.
573 : */
574 :
575 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::VRMockController);
576 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
577 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
578 : }
579 :
580 : JSObject*
581 0 : GetConstructorObject(JSContext* aCx)
582 : {
583 0 : return GetConstructorObjectHandle(aCx);
584 : }
585 :
586 : } // namespace VRMockControllerBinding
587 :
588 :
589 :
590 : namespace VRMockDisplayBinding {
591 :
592 : static bool
593 0 : setEyeResolution(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockDisplay* self, const JSJitMethodCallArgs& args)
594 : {
595 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
596 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockDisplay.setEyeResolution");
597 : }
598 : uint32_t arg0;
599 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
600 0 : return false;
601 : }
602 : uint32_t arg1;
603 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[1], &arg1)) {
604 0 : return false;
605 : }
606 0 : self->SetEyeResolution(arg0, arg1);
607 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
608 0 : args.rval().setUndefined();
609 0 : return true;
610 : }
611 :
612 : static const JSJitInfo setEyeResolution_methodinfo = {
613 : { (JSJitGetterOp)setEyeResolution },
614 : { prototypes::id::VRMockDisplay },
615 : { PrototypeTraits<prototypes::id::VRMockDisplay>::Depth },
616 : JSJitInfo::Method,
617 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
618 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
619 : false, /* isInfallible. False in setters. */
620 : false, /* isMovable. Not relevant for setters. */
621 : false, /* isEliminatable. Not relevant for setters. */
622 : false, /* isAlwaysInSlot. Only relevant for getters. */
623 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
624 : false, /* isTypedMethod. Only relevant for methods. */
625 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
626 : };
627 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
628 : static_assert(0 < 1, "There is no slot for us");
629 :
630 : static bool
631 0 : setEyeParameter(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockDisplay* self, const JSJitMethodCallArgs& args)
632 : {
633 0 : if (MOZ_UNLIKELY(args.length() < 8)) {
634 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockDisplay.setEyeParameter");
635 : }
636 : VREye arg0;
637 : {
638 : int index;
639 0 : if (!FindEnumStringIndex<true>(cx, args[0], VREyeValues::strings, "VREye", "Argument 1 of VRMockDisplay.setEyeParameter", &index)) {
640 0 : return false;
641 : }
642 0 : MOZ_ASSERT(index >= 0);
643 0 : arg0 = static_cast<VREye>(index);
644 : }
645 : double arg1;
646 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) {
647 0 : return false;
648 0 : } else if (!mozilla::IsFinite(arg1)) {
649 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of VRMockDisplay.setEyeParameter");
650 0 : return false;
651 : }
652 : double arg2;
653 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[2], &arg2)) {
654 0 : return false;
655 0 : } else if (!mozilla::IsFinite(arg2)) {
656 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 3 of VRMockDisplay.setEyeParameter");
657 0 : return false;
658 : }
659 : double arg3;
660 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[3], &arg3)) {
661 0 : return false;
662 0 : } else if (!mozilla::IsFinite(arg3)) {
663 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 4 of VRMockDisplay.setEyeParameter");
664 0 : return false;
665 : }
666 : double arg4;
667 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[4], &arg4)) {
668 0 : return false;
669 0 : } else if (!mozilla::IsFinite(arg4)) {
670 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 5 of VRMockDisplay.setEyeParameter");
671 0 : return false;
672 : }
673 : double arg5;
674 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[5], &arg5)) {
675 0 : return false;
676 0 : } else if (!mozilla::IsFinite(arg5)) {
677 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 6 of VRMockDisplay.setEyeParameter");
678 0 : return false;
679 : }
680 : double arg6;
681 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[6], &arg6)) {
682 0 : return false;
683 0 : } else if (!mozilla::IsFinite(arg6)) {
684 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 7 of VRMockDisplay.setEyeParameter");
685 0 : return false;
686 : }
687 : double arg7;
688 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[7], &arg7)) {
689 0 : return false;
690 0 : } else if (!mozilla::IsFinite(arg7)) {
691 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 8 of VRMockDisplay.setEyeParameter");
692 0 : return false;
693 : }
694 0 : self->SetEyeParameter(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
695 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
696 0 : args.rval().setUndefined();
697 0 : return true;
698 : }
699 :
700 : static const JSJitInfo setEyeParameter_methodinfo = {
701 : { (JSJitGetterOp)setEyeParameter },
702 : { prototypes::id::VRMockDisplay },
703 : { PrototypeTraits<prototypes::id::VRMockDisplay>::Depth },
704 : JSJitInfo::Method,
705 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
706 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
707 : false, /* isInfallible. False in setters. */
708 : false, /* isMovable. Not relevant for setters. */
709 : false, /* isEliminatable. Not relevant for setters. */
710 : false, /* isAlwaysInSlot. Only relevant for getters. */
711 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
712 : false, /* isTypedMethod. Only relevant for methods. */
713 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
714 : };
715 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
716 : static_assert(0 < 1, "There is no slot for us");
717 :
718 : static bool
719 0 : setPose(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockDisplay* self, const JSJitMethodCallArgs& args)
720 : {
721 0 : if (MOZ_UNLIKELY(args.length() < 6)) {
722 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockDisplay.setPose");
723 : }
724 0 : RootedTypedArray<Nullable<Float32Array>> arg0(cx);
725 0 : if (args[0].isObject()) {
726 0 : if (!arg0.SetValue().Init(&args[0].toObject())) {
727 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of VRMockDisplay.setPose", "Float32ArrayOrNull");
728 0 : return false;
729 : }
730 0 : } else if (args[0].isNullOrUndefined()) {
731 0 : arg0.SetNull();
732 : } else {
733 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of VRMockDisplay.setPose");
734 0 : return false;
735 : }
736 0 : RootedTypedArray<Nullable<Float32Array>> arg1(cx);
737 0 : if (args[1].isObject()) {
738 0 : if (!arg1.SetValue().Init(&args[1].toObject())) {
739 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of VRMockDisplay.setPose", "Float32ArrayOrNull");
740 0 : return false;
741 : }
742 0 : } else if (args[1].isNullOrUndefined()) {
743 0 : arg1.SetNull();
744 : } else {
745 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of VRMockDisplay.setPose");
746 0 : return false;
747 : }
748 0 : RootedTypedArray<Nullable<Float32Array>> arg2(cx);
749 0 : if (args[2].isObject()) {
750 0 : if (!arg2.SetValue().Init(&args[2].toObject())) {
751 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 3 of VRMockDisplay.setPose", "Float32ArrayOrNull");
752 0 : return false;
753 : }
754 0 : } else if (args[2].isNullOrUndefined()) {
755 0 : arg2.SetNull();
756 : } else {
757 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of VRMockDisplay.setPose");
758 0 : return false;
759 : }
760 0 : RootedTypedArray<Nullable<Float32Array>> arg3(cx);
761 0 : if (args[3].isObject()) {
762 0 : if (!arg3.SetValue().Init(&args[3].toObject())) {
763 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 4 of VRMockDisplay.setPose", "Float32ArrayOrNull");
764 0 : return false;
765 : }
766 0 : } else if (args[3].isNullOrUndefined()) {
767 0 : arg3.SetNull();
768 : } else {
769 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 4 of VRMockDisplay.setPose");
770 0 : return false;
771 : }
772 0 : RootedTypedArray<Nullable<Float32Array>> arg4(cx);
773 0 : if (args[4].isObject()) {
774 0 : if (!arg4.SetValue().Init(&args[4].toObject())) {
775 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 5 of VRMockDisplay.setPose", "Float32ArrayOrNull");
776 0 : return false;
777 : }
778 0 : } else if (args[4].isNullOrUndefined()) {
779 0 : arg4.SetNull();
780 : } else {
781 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 5 of VRMockDisplay.setPose");
782 0 : return false;
783 : }
784 0 : RootedTypedArray<Nullable<Float32Array>> arg5(cx);
785 0 : if (args[5].isObject()) {
786 0 : if (!arg5.SetValue().Init(&args[5].toObject())) {
787 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 6 of VRMockDisplay.setPose", "Float32ArrayOrNull");
788 0 : return false;
789 : }
790 0 : } else if (args[5].isNullOrUndefined()) {
791 0 : arg5.SetNull();
792 : } else {
793 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 6 of VRMockDisplay.setPose");
794 0 : return false;
795 : }
796 0 : self->SetPose(Constify(arg0), Constify(arg1), Constify(arg2), Constify(arg3), Constify(arg4), Constify(arg5));
797 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
798 0 : args.rval().setUndefined();
799 0 : return true;
800 : }
801 :
802 : static const JSJitInfo setPose_methodinfo = {
803 : { (JSJitGetterOp)setPose },
804 : { prototypes::id::VRMockDisplay },
805 : { PrototypeTraits<prototypes::id::VRMockDisplay>::Depth },
806 : JSJitInfo::Method,
807 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
808 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
809 : false, /* isInfallible. False in setters. */
810 : false, /* isMovable. Not relevant for setters. */
811 : false, /* isEliminatable. Not relevant for setters. */
812 : false, /* isAlwaysInSlot. Only relevant for getters. */
813 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
814 : false, /* isTypedMethod. Only relevant for methods. */
815 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
816 : };
817 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
818 : static_assert(0 < 1, "There is no slot for us");
819 :
820 : static bool
821 0 : setMountState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockDisplay* self, const JSJitMethodCallArgs& args)
822 : {
823 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
824 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRMockDisplay.setMountState");
825 : }
826 : bool arg0;
827 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
828 0 : return false;
829 : }
830 0 : self->SetMountState(arg0);
831 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
832 0 : args.rval().setUndefined();
833 0 : return true;
834 : }
835 :
836 : static const JSJitInfo setMountState_methodinfo = {
837 : { (JSJitGetterOp)setMountState },
838 : { prototypes::id::VRMockDisplay },
839 : { PrototypeTraits<prototypes::id::VRMockDisplay>::Depth },
840 : JSJitInfo::Method,
841 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
842 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
843 : false, /* isInfallible. False in setters. */
844 : false, /* isMovable. Not relevant for setters. */
845 : false, /* isEliminatable. Not relevant for setters. */
846 : false, /* isAlwaysInSlot. Only relevant for getters. */
847 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
848 : false, /* isTypedMethod. Only relevant for methods. */
849 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
850 : };
851 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
852 : static_assert(0 < 1, "There is no slot for us");
853 :
854 : static bool
855 0 : update(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRMockDisplay* self, const JSJitMethodCallArgs& args)
856 : {
857 0 : self->Update();
858 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
859 0 : args.rval().setUndefined();
860 0 : return true;
861 : }
862 :
863 : static const JSJitInfo update_methodinfo = {
864 : { (JSJitGetterOp)update },
865 : { prototypes::id::VRMockDisplay },
866 : { PrototypeTraits<prototypes::id::VRMockDisplay>::Depth },
867 : JSJitInfo::Method,
868 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
869 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
870 : true, /* isInfallible. False in setters. */
871 : false, /* isMovable. Not relevant for setters. */
872 : false, /* isEliminatable. Not relevant for setters. */
873 : false, /* isAlwaysInSlot. Only relevant for getters. */
874 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
875 : false, /* isTypedMethod. Only relevant for methods. */
876 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
877 : };
878 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
879 : static_assert(0 < 1, "There is no slot for us");
880 :
881 : static bool
882 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
883 : {
884 0 : mozilla::dom::VRMockDisplay* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRMockDisplay>(obj);
885 : // We don't want to preserve if we don't have a wrapper, and we
886 : // obviously can't preserve if we're not initialized.
887 0 : if (self && self->GetWrapperPreserveColor()) {
888 0 : PreserveWrapper(self);
889 : }
890 0 : return true;
891 : }
892 :
893 : static void
894 0 : _finalize(js::FreeOp* fop, JSObject* obj)
895 : {
896 0 : mozilla::dom::VRMockDisplay* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRMockDisplay>(obj);
897 0 : if (self) {
898 0 : ClearWrapper(self, self, obj);
899 0 : AddForDeferredFinalization<mozilla::dom::VRMockDisplay>(self);
900 : }
901 0 : }
902 :
903 : static void
904 0 : _objectMoved(JSObject* obj, const JSObject* old)
905 : {
906 0 : mozilla::dom::VRMockDisplay* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRMockDisplay>(obj);
907 0 : if (self) {
908 0 : UpdateWrapper(self, self, obj, old);
909 : }
910 0 : }
911 :
912 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
913 : #if defined(__clang__)
914 : #pragma clang diagnostic push
915 : #pragma clang diagnostic ignored "-Wmissing-braces"
916 : #endif
917 : static const JSFunctionSpec sMethods_specs[] = {
918 : JS_FNSPEC("setEyeResolution", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setEyeResolution_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
919 : JS_FNSPEC("setEyeParameter", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setEyeParameter_methodinfo), 8, JSPROP_ENUMERATE, nullptr),
920 : JS_FNSPEC("setPose", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setPose_methodinfo), 6, JSPROP_ENUMERATE, nullptr),
921 : JS_FNSPEC("setMountState", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setMountState_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
922 : JS_FNSPEC("update", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&update_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
923 : JS_FS_END
924 : };
925 : #if defined(__clang__)
926 : #pragma clang diagnostic pop
927 : #endif
928 :
929 :
930 : // Can't be const because the pref-enabled boolean needs to be writable
931 : static Prefable<const JSFunctionSpec> sMethods[] = {
932 : { nullptr, &sMethods_specs[0] },
933 : { nullptr, nullptr }
934 : };
935 :
936 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
937 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
938 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
939 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
940 :
941 :
942 : static uint16_t sNativeProperties_sortedPropertyIndices[5];
943 : static PropertyInfo sNativeProperties_propertyInfos[5];
944 :
945 : static const NativePropertiesN<1> sNativeProperties = {
946 : false, 0,
947 : false, 0,
948 : true, 0 /* sMethods */,
949 : false, 0,
950 : false, 0,
951 : false, 0,
952 : false, 0,
953 : -1,
954 : 5,
955 : sNativeProperties_sortedPropertyIndices,
956 : {
957 : { sMethods, &sNativeProperties_propertyInfos[0] }
958 : }
959 : };
960 : static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
961 : "We have a property info count that is oversized");
962 :
963 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
964 : {
965 : "Function",
966 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
967 : &sBoringInterfaceObjectClassClassOps,
968 : JS_NULL_CLASS_SPEC,
969 : JS_NULL_CLASS_EXT,
970 : &sInterfaceObjectClassObjectOps
971 : },
972 : eInterface,
973 : true,
974 : prototypes::id::VRMockDisplay,
975 : PrototypeTraits<prototypes::id::VRMockDisplay>::Depth,
976 : sNativePropertyHooks,
977 : "function VRMockDisplay() {\n [native code]\n}",
978 : JS::GetRealmFunctionPrototype
979 : };
980 :
981 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
982 : {
983 : "VRMockDisplayPrototype",
984 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
985 : JS_NULL_CLASS_OPS,
986 : JS_NULL_CLASS_SPEC,
987 : JS_NULL_CLASS_EXT,
988 : JS_NULL_OBJECT_OPS
989 : },
990 : eInterfacePrototype,
991 : false,
992 : prototypes::id::VRMockDisplay,
993 : PrototypeTraits<prototypes::id::VRMockDisplay>::Depth,
994 : sNativePropertyHooks,
995 : "[object VRMockDisplayPrototype]",
996 : JS::GetRealmObjectPrototype
997 : };
998 :
999 : bool
1000 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1001 : {
1002 : static bool sPrefValue;
1003 : static bool sPrefCacheSetUp = false;
1004 0 : if (!sPrefCacheSetUp) {
1005 0 : sPrefCacheSetUp = true;
1006 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.vr.test.enabled");
1007 : }
1008 :
1009 0 : return sPrefValue;
1010 : }
1011 :
1012 : JSObject*
1013 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
1014 : {
1015 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
1016 : }
1017 :
1018 : static const js::ClassOps sClassOps = {
1019 : _addProperty, /* addProperty */
1020 : nullptr, /* delProperty */
1021 : nullptr, /* getProperty */
1022 : nullptr, /* setProperty */
1023 : nullptr, /* enumerate */
1024 : nullptr, /* newEnumerate */
1025 : nullptr, /* resolve */
1026 : nullptr, /* mayResolve */
1027 : _finalize, /* finalize */
1028 : nullptr, /* call */
1029 : nullptr, /* hasInstance */
1030 : nullptr, /* construct */
1031 : nullptr, /* trace */
1032 : };
1033 :
1034 : static const js::ClassExtension sClassExtension = {
1035 : nullptr, /* weakmapKeyDelegateOp */
1036 : _objectMoved /* objectMovedOp */
1037 : };
1038 :
1039 : static const DOMJSClass sClass = {
1040 : { "VRMockDisplay",
1041 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1042 : &sClassOps,
1043 : JS_NULL_CLASS_SPEC,
1044 : &sClassExtension,
1045 : JS_NULL_OBJECT_OPS
1046 : },
1047 : { prototypes::id::VRMockDisplay, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1048 : IsBaseOf<nsISupports, mozilla::dom::VRMockDisplay >::value,
1049 : sNativePropertyHooks,
1050 : FindAssociatedGlobalForNative<mozilla::dom::VRMockDisplay>::Get,
1051 : GetProtoObjectHandle,
1052 : GetCCParticipant<mozilla::dom::VRMockDisplay>::Get()
1053 : };
1054 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1055 : "Must have the right minimal number of reserved slots.");
1056 : static_assert(1 >= 1,
1057 : "Must have enough reserved slots.");
1058 :
1059 : const JSClass*
1060 0 : GetJSClass()
1061 : {
1062 0 : return sClass.ToJSClass();
1063 : }
1064 :
1065 : bool
1066 0 : Wrap(JSContext* aCx, mozilla::dom::VRMockDisplay* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1067 : {
1068 : MOZ_ASSERT(static_cast<mozilla::dom::VRMockDisplay*>(aObject) ==
1069 : reinterpret_cast<mozilla::dom::VRMockDisplay*>(aObject),
1070 : "Multiple inheritance for mozilla::dom::VRMockDisplay is broken.");
1071 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1072 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1073 0 : MOZ_ASSERT(!aCache->GetWrapper(),
1074 : "You should probably not be using Wrap() directly; use "
1075 : "GetOrCreateDOMReflector instead");
1076 :
1077 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1078 : "nsISupports must be on our primary inheritance chain");
1079 :
1080 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1081 0 : if (!global) {
1082 0 : return false;
1083 : }
1084 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
1085 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1086 :
1087 : // That might have ended up wrapping us already, due to the wonders
1088 : // of XBL. Check for that, and bail out as needed.
1089 0 : aReflector.set(aCache->GetWrapper());
1090 0 : if (aReflector) {
1091 : #ifdef DEBUG
1092 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1093 : #endif // DEBUG
1094 0 : return true;
1095 : }
1096 :
1097 0 : JSAutoCompartment ac(aCx, global);
1098 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1099 0 : if (!canonicalProto) {
1100 0 : return false;
1101 : }
1102 0 : JS::Rooted<JSObject*> proto(aCx);
1103 0 : if (aGivenProto) {
1104 0 : proto = aGivenProto;
1105 : // Unfortunately, while aGivenProto was in the compartment of aCx
1106 : // coming in, we changed compartments to that of "parent" so may need
1107 : // to wrap the proto here.
1108 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1109 0 : if (!JS_WrapObject(aCx, &proto)) {
1110 0 : return false;
1111 : }
1112 : }
1113 : } else {
1114 0 : proto = canonicalProto;
1115 : }
1116 :
1117 0 : BindingJSObjectCreator<mozilla::dom::VRMockDisplay> creator(aCx);
1118 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1119 0 : if (!aReflector) {
1120 0 : return false;
1121 : }
1122 :
1123 0 : aCache->SetWrapper(aReflector);
1124 0 : creator.InitializationSucceeded();
1125 :
1126 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1127 : aCache->GetWrapperPreserveColor() == aReflector);
1128 : // If proto != canonicalProto, we have to preserve our wrapper;
1129 : // otherwise we won't be able to properly recreate it later, since
1130 : // we won't know what proto to use. Note that we don't check
1131 : // aGivenProto here, since it's entirely possible (and even
1132 : // somewhat common) to have a non-null aGivenProto which is the
1133 : // same as canonicalProto.
1134 0 : if (proto != canonicalProto) {
1135 0 : PreserveWrapper(aObject);
1136 : }
1137 :
1138 0 : return true;
1139 : }
1140 :
1141 : const NativePropertyHooks sNativePropertyHooks[] = { {
1142 : nullptr,
1143 : nullptr,
1144 : nullptr,
1145 : { sNativeProperties.Upcast(), nullptr },
1146 : prototypes::id::VRMockDisplay,
1147 : constructors::id::VRMockDisplay,
1148 : nullptr,
1149 : &DefaultXrayExpandoObjectClass
1150 : } };
1151 :
1152 : void
1153 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1154 : {
1155 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1156 0 : if (!parentProto) {
1157 0 : return;
1158 : }
1159 :
1160 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1161 0 : if (!constructorProto) {
1162 0 : return;
1163 : }
1164 :
1165 : static bool sIdsInited = false;
1166 0 : if (!sIdsInited && NS_IsMainThread()) {
1167 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1168 0 : return;
1169 : }
1170 0 : sIdsInited = true;
1171 : }
1172 :
1173 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::VRMockDisplay);
1174 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::VRMockDisplay);
1175 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1176 : &sPrototypeClass.mBase, protoCache,
1177 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1178 : interfaceCache,
1179 : sNativeProperties.Upcast(),
1180 : nullptr,
1181 : "VRMockDisplay", aDefineOnGlobal,
1182 : nullptr,
1183 0 : false);
1184 : }
1185 :
1186 : JS::Handle<JSObject*>
1187 0 : GetProtoObjectHandle(JSContext* aCx)
1188 : {
1189 : /* Get the interface prototype object for this class. This will create the
1190 : object as needed. */
1191 0 : bool aDefineOnGlobal = true;
1192 :
1193 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1194 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1195 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1196 0 : return nullptr;
1197 : }
1198 :
1199 : /* Check to see whether the interface objects are already installed */
1200 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1201 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::VRMockDisplay)) {
1202 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1203 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1204 : }
1205 :
1206 : /*
1207 : * The object might _still_ be null, but that's OK.
1208 : *
1209 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1210 : * traced by TraceProtoAndIfaceCache() and its contents are never
1211 : * changed after they have been set.
1212 : *
1213 : * Calling address() avoids the read read barrier that does gray
1214 : * unmarking, but it's not possible for the object to be gray here.
1215 : */
1216 :
1217 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::VRMockDisplay);
1218 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1219 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1220 : }
1221 :
1222 : JS::Handle<JSObject*>
1223 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1224 : {
1225 : /* Get the interface object for this class. This will create the object as
1226 : needed. */
1227 :
1228 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1229 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1230 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1231 0 : return nullptr;
1232 : }
1233 :
1234 : /* Check to see whether the interface objects are already installed */
1235 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1236 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::VRMockDisplay)) {
1237 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1238 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1239 : }
1240 :
1241 : /*
1242 : * The object might _still_ be null, but that's OK.
1243 : *
1244 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1245 : * traced by TraceProtoAndIfaceCache() and its contents are never
1246 : * changed after they have been set.
1247 : *
1248 : * Calling address() avoids the read read barrier that does gray
1249 : * unmarking, but it's not possible for the object to be gray here.
1250 : */
1251 :
1252 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::VRMockDisplay);
1253 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1254 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1255 : }
1256 :
1257 : JSObject*
1258 0 : GetConstructorObject(JSContext* aCx)
1259 : {
1260 0 : return GetConstructorObjectHandle(aCx);
1261 : }
1262 :
1263 : } // namespace VRMockDisplayBinding
1264 :
1265 :
1266 :
1267 : namespace VRServiceTestBinding {
1268 :
1269 : static bool
1270 0 : attachVRDisplay(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRServiceTest* self, const JSJitMethodCallArgs& args)
1271 : {
1272 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1273 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRServiceTest.attachVRDisplay");
1274 : }
1275 0 : binding_detail::FakeString arg0;
1276 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1277 0 : return false;
1278 : }
1279 0 : binding_detail::FastErrorResult rv;
1280 0 : auto result(StrongOrRawPtr<Promise>(self->AttachVRDisplay(NonNullHelper(Constify(arg0)), rv)));
1281 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1282 0 : return false;
1283 : }
1284 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1285 : static_assert(!IsPointer<decltype(result)>::value,
1286 : "NewObject implies that we need to keep the object alive with a strong reference.");
1287 0 : if (!ToJSValue(cx, result, args.rval())) {
1288 0 : return false;
1289 : }
1290 0 : return true;
1291 : }
1292 :
1293 : static bool
1294 0 : attachVRDisplay_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRServiceTest* self, const JSJitMethodCallArgs& args)
1295 : {
1296 : // Make sure to save the callee before someone maybe messes
1297 : // with rval().
1298 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1299 0 : bool ok = attachVRDisplay(cx, obj, self, args);
1300 0 : if (ok) {
1301 0 : return true;
1302 : }
1303 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1304 0 : args.rval());
1305 : }
1306 :
1307 : static const JSJitInfo attachVRDisplay_methodinfo = {
1308 : { (JSJitGetterOp)attachVRDisplay_promiseWrapper },
1309 : { prototypes::id::VRServiceTest },
1310 : { PrototypeTraits<prototypes::id::VRServiceTest>::Depth },
1311 : JSJitInfo::Method,
1312 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1313 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1314 : false, /* isInfallible. False in setters. */
1315 : false, /* isMovable. Not relevant for setters. */
1316 : false, /* isEliminatable. Not relevant for setters. */
1317 : false, /* isAlwaysInSlot. Only relevant for getters. */
1318 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1319 : false, /* isTypedMethod. Only relevant for methods. */
1320 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1321 : };
1322 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1323 : static_assert(0 < 1, "There is no slot for us");
1324 :
1325 : static bool
1326 0 : attachVRController(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRServiceTest* self, const JSJitMethodCallArgs& args)
1327 : {
1328 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
1329 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "VRServiceTest.attachVRController");
1330 : }
1331 0 : binding_detail::FakeString arg0;
1332 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1333 0 : return false;
1334 : }
1335 0 : binding_detail::FastErrorResult rv;
1336 0 : auto result(StrongOrRawPtr<Promise>(self->AttachVRController(NonNullHelper(Constify(arg0)), rv)));
1337 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1338 0 : return false;
1339 : }
1340 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1341 : static_assert(!IsPointer<decltype(result)>::value,
1342 : "NewObject implies that we need to keep the object alive with a strong reference.");
1343 0 : if (!ToJSValue(cx, result, args.rval())) {
1344 0 : return false;
1345 : }
1346 0 : return true;
1347 : }
1348 :
1349 : static bool
1350 0 : attachVRController_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VRServiceTest* self, const JSJitMethodCallArgs& args)
1351 : {
1352 : // Make sure to save the callee before someone maybe messes
1353 : // with rval().
1354 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
1355 0 : bool ok = attachVRController(cx, obj, self, args);
1356 0 : if (ok) {
1357 0 : return true;
1358 : }
1359 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
1360 0 : args.rval());
1361 : }
1362 :
1363 : static const JSJitInfo attachVRController_methodinfo = {
1364 : { (JSJitGetterOp)attachVRController_promiseWrapper },
1365 : { prototypes::id::VRServiceTest },
1366 : { PrototypeTraits<prototypes::id::VRServiceTest>::Depth },
1367 : JSJitInfo::Method,
1368 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
1369 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
1370 : false, /* isInfallible. False in setters. */
1371 : false, /* isMovable. Not relevant for setters. */
1372 : false, /* isEliminatable. Not relevant for setters. */
1373 : false, /* isAlwaysInSlot. Only relevant for getters. */
1374 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
1375 : false, /* isTypedMethod. Only relevant for methods. */
1376 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
1377 : };
1378 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1379 : static_assert(0 < 1, "There is no slot for us");
1380 :
1381 : static bool
1382 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1383 : {
1384 0 : mozilla::dom::VRServiceTest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRServiceTest>(obj);
1385 : // We don't want to preserve if we don't have a wrapper, and we
1386 : // obviously can't preserve if we're not initialized.
1387 0 : if (self && self->GetWrapperPreserveColor()) {
1388 0 : PreserveWrapper(self);
1389 : }
1390 0 : return true;
1391 : }
1392 :
1393 : static void
1394 0 : _finalize(js::FreeOp* fop, JSObject* obj)
1395 : {
1396 0 : mozilla::dom::VRServiceTest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRServiceTest>(obj);
1397 0 : if (self) {
1398 0 : ClearWrapper(self, self, obj);
1399 0 : AddForDeferredFinalization<mozilla::dom::VRServiceTest>(self);
1400 : }
1401 0 : }
1402 :
1403 : static void
1404 0 : _objectMoved(JSObject* obj, const JSObject* old)
1405 : {
1406 0 : mozilla::dom::VRServiceTest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VRServiceTest>(obj);
1407 0 : if (self) {
1408 0 : UpdateWrapper(self, self, obj, old);
1409 : }
1410 0 : }
1411 :
1412 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
1413 : #if defined(__clang__)
1414 : #pragma clang diagnostic push
1415 : #pragma clang diagnostic ignored "-Wmissing-braces"
1416 : #endif
1417 : static const JSFunctionSpec sMethods_specs[] = {
1418 : JS_FNSPEC("attachVRDisplay", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&attachVRDisplay_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1419 : JS_FNSPEC("attachVRController", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&attachVRController_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1420 : JS_FS_END
1421 : };
1422 : #if defined(__clang__)
1423 : #pragma clang diagnostic pop
1424 : #endif
1425 :
1426 :
1427 : // Can't be const because the pref-enabled boolean needs to be writable
1428 : static Prefable<const JSFunctionSpec> sMethods[] = {
1429 : { nullptr, &sMethods_specs[0] },
1430 : { nullptr, nullptr }
1431 : };
1432 :
1433 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1434 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1435 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1436 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1437 :
1438 :
1439 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
1440 : static PropertyInfo sNativeProperties_propertyInfos[2];
1441 :
1442 : static const NativePropertiesN<1> sNativeProperties = {
1443 : false, 0,
1444 : false, 0,
1445 : true, 0 /* sMethods */,
1446 : false, 0,
1447 : false, 0,
1448 : false, 0,
1449 : false, 0,
1450 : -1,
1451 : 2,
1452 : sNativeProperties_sortedPropertyIndices,
1453 : {
1454 : { sMethods, &sNativeProperties_propertyInfos[0] }
1455 : }
1456 : };
1457 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1458 : "We have a property info count that is oversized");
1459 :
1460 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1461 : {
1462 : "Function",
1463 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1464 : &sBoringInterfaceObjectClassClassOps,
1465 : JS_NULL_CLASS_SPEC,
1466 : JS_NULL_CLASS_EXT,
1467 : &sInterfaceObjectClassObjectOps
1468 : },
1469 : eInterface,
1470 : true,
1471 : prototypes::id::VRServiceTest,
1472 : PrototypeTraits<prototypes::id::VRServiceTest>::Depth,
1473 : sNativePropertyHooks,
1474 : "function VRServiceTest() {\n [native code]\n}",
1475 : JS::GetRealmFunctionPrototype
1476 : };
1477 :
1478 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1479 : {
1480 : "VRServiceTestPrototype",
1481 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1482 : JS_NULL_CLASS_OPS,
1483 : JS_NULL_CLASS_SPEC,
1484 : JS_NULL_CLASS_EXT,
1485 : JS_NULL_OBJECT_OPS
1486 : },
1487 : eInterfacePrototype,
1488 : false,
1489 : prototypes::id::VRServiceTest,
1490 : PrototypeTraits<prototypes::id::VRServiceTest>::Depth,
1491 : sNativePropertyHooks,
1492 : "[object VRServiceTestPrototype]",
1493 : JS::GetRealmObjectPrototype
1494 : };
1495 :
1496 : bool
1497 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1498 : {
1499 : static bool sPrefValue;
1500 : static bool sPrefCacheSetUp = false;
1501 0 : if (!sPrefCacheSetUp) {
1502 0 : sPrefCacheSetUp = true;
1503 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.vr.test.enabled");
1504 : }
1505 :
1506 0 : return sPrefValue;
1507 : }
1508 :
1509 : JSObject*
1510 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
1511 : {
1512 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
1513 : }
1514 :
1515 : static const js::ClassOps sClassOps = {
1516 : _addProperty, /* addProperty */
1517 : nullptr, /* delProperty */
1518 : nullptr, /* getProperty */
1519 : nullptr, /* setProperty */
1520 : nullptr, /* enumerate */
1521 : nullptr, /* newEnumerate */
1522 : nullptr, /* resolve */
1523 : nullptr, /* mayResolve */
1524 : _finalize, /* finalize */
1525 : nullptr, /* call */
1526 : nullptr, /* hasInstance */
1527 : nullptr, /* construct */
1528 : nullptr, /* trace */
1529 : };
1530 :
1531 : static const js::ClassExtension sClassExtension = {
1532 : nullptr, /* weakmapKeyDelegateOp */
1533 : _objectMoved /* objectMovedOp */
1534 : };
1535 :
1536 : static const DOMJSClass sClass = {
1537 : { "VRServiceTest",
1538 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1539 : &sClassOps,
1540 : JS_NULL_CLASS_SPEC,
1541 : &sClassExtension,
1542 : JS_NULL_OBJECT_OPS
1543 : },
1544 : { prototypes::id::VRServiceTest, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1545 : IsBaseOf<nsISupports, mozilla::dom::VRServiceTest >::value,
1546 : sNativePropertyHooks,
1547 : FindAssociatedGlobalForNative<mozilla::dom::VRServiceTest>::Get,
1548 : GetProtoObjectHandle,
1549 : GetCCParticipant<mozilla::dom::VRServiceTest>::Get()
1550 : };
1551 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1552 : "Must have the right minimal number of reserved slots.");
1553 : static_assert(1 >= 1,
1554 : "Must have enough reserved slots.");
1555 :
1556 : const JSClass*
1557 0 : GetJSClass()
1558 : {
1559 0 : return sClass.ToJSClass();
1560 : }
1561 :
1562 : bool
1563 0 : Wrap(JSContext* aCx, mozilla::dom::VRServiceTest* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1564 : {
1565 : MOZ_ASSERT(static_cast<mozilla::dom::VRServiceTest*>(aObject) ==
1566 : reinterpret_cast<mozilla::dom::VRServiceTest*>(aObject),
1567 : "Multiple inheritance for mozilla::dom::VRServiceTest is broken.");
1568 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1569 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1570 0 : MOZ_ASSERT(!aCache->GetWrapper(),
1571 : "You should probably not be using Wrap() directly; use "
1572 : "GetOrCreateDOMReflector instead");
1573 :
1574 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1575 : "nsISupports must be on our primary inheritance chain");
1576 :
1577 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1578 0 : if (!global) {
1579 0 : return false;
1580 : }
1581 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
1582 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1583 :
1584 : // That might have ended up wrapping us already, due to the wonders
1585 : // of XBL. Check for that, and bail out as needed.
1586 0 : aReflector.set(aCache->GetWrapper());
1587 0 : if (aReflector) {
1588 : #ifdef DEBUG
1589 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1590 : #endif // DEBUG
1591 0 : return true;
1592 : }
1593 :
1594 0 : JSAutoCompartment ac(aCx, global);
1595 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1596 0 : if (!canonicalProto) {
1597 0 : return false;
1598 : }
1599 0 : JS::Rooted<JSObject*> proto(aCx);
1600 0 : if (aGivenProto) {
1601 0 : proto = aGivenProto;
1602 : // Unfortunately, while aGivenProto was in the compartment of aCx
1603 : // coming in, we changed compartments to that of "parent" so may need
1604 : // to wrap the proto here.
1605 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1606 0 : if (!JS_WrapObject(aCx, &proto)) {
1607 0 : return false;
1608 : }
1609 : }
1610 : } else {
1611 0 : proto = canonicalProto;
1612 : }
1613 :
1614 0 : BindingJSObjectCreator<mozilla::dom::VRServiceTest> creator(aCx);
1615 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1616 0 : if (!aReflector) {
1617 0 : return false;
1618 : }
1619 :
1620 0 : aCache->SetWrapper(aReflector);
1621 0 : creator.InitializationSucceeded();
1622 :
1623 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1624 : aCache->GetWrapperPreserveColor() == aReflector);
1625 : // If proto != canonicalProto, we have to preserve our wrapper;
1626 : // otherwise we won't be able to properly recreate it later, since
1627 : // we won't know what proto to use. Note that we don't check
1628 : // aGivenProto here, since it's entirely possible (and even
1629 : // somewhat common) to have a non-null aGivenProto which is the
1630 : // same as canonicalProto.
1631 0 : if (proto != canonicalProto) {
1632 0 : PreserveWrapper(aObject);
1633 : }
1634 :
1635 0 : return true;
1636 : }
1637 :
1638 : const NativePropertyHooks sNativePropertyHooks[] = { {
1639 : nullptr,
1640 : nullptr,
1641 : nullptr,
1642 : { sNativeProperties.Upcast(), nullptr },
1643 : prototypes::id::VRServiceTest,
1644 : constructors::id::VRServiceTest,
1645 : nullptr,
1646 : &DefaultXrayExpandoObjectClass
1647 : } };
1648 :
1649 : void
1650 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1651 : {
1652 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1653 0 : if (!parentProto) {
1654 0 : return;
1655 : }
1656 :
1657 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1658 0 : if (!constructorProto) {
1659 0 : return;
1660 : }
1661 :
1662 : static bool sIdsInited = false;
1663 0 : if (!sIdsInited && NS_IsMainThread()) {
1664 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1665 0 : return;
1666 : }
1667 0 : sIdsInited = true;
1668 : }
1669 :
1670 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::VRServiceTest);
1671 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::VRServiceTest);
1672 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1673 : &sPrototypeClass.mBase, protoCache,
1674 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1675 : interfaceCache,
1676 : sNativeProperties.Upcast(),
1677 : nullptr,
1678 : "VRServiceTest", aDefineOnGlobal,
1679 : nullptr,
1680 0 : false);
1681 : }
1682 :
1683 : JS::Handle<JSObject*>
1684 0 : GetProtoObjectHandle(JSContext* aCx)
1685 : {
1686 : /* Get the interface prototype object for this class. This will create the
1687 : object as needed. */
1688 0 : bool aDefineOnGlobal = true;
1689 :
1690 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1691 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1692 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1693 0 : return nullptr;
1694 : }
1695 :
1696 : /* Check to see whether the interface objects are already installed */
1697 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1698 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::VRServiceTest)) {
1699 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1700 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1701 : }
1702 :
1703 : /*
1704 : * The object might _still_ be null, but that's OK.
1705 : *
1706 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1707 : * traced by TraceProtoAndIfaceCache() and its contents are never
1708 : * changed after they have been set.
1709 : *
1710 : * Calling address() avoids the read read barrier that does gray
1711 : * unmarking, but it's not possible for the object to be gray here.
1712 : */
1713 :
1714 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::VRServiceTest);
1715 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1716 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1717 : }
1718 :
1719 : JS::Handle<JSObject*>
1720 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1721 : {
1722 : /* Get the interface object for this class. This will create the object as
1723 : needed. */
1724 :
1725 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1726 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1727 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1728 0 : return nullptr;
1729 : }
1730 :
1731 : /* Check to see whether the interface objects are already installed */
1732 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1733 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::VRServiceTest)) {
1734 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1735 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1736 : }
1737 :
1738 : /*
1739 : * The object might _still_ be null, but that's OK.
1740 : *
1741 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1742 : * traced by TraceProtoAndIfaceCache() and its contents are never
1743 : * changed after they have been set.
1744 : *
1745 : * Calling address() avoids the read read barrier that does gray
1746 : * unmarking, but it's not possible for the object to be gray here.
1747 : */
1748 :
1749 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::VRServiceTest);
1750 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1751 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1752 : }
1753 :
1754 : JSObject*
1755 0 : GetConstructorObject(JSContext* aCx)
1756 : {
1757 0 : return GetConstructorObjectHandle(aCx);
1758 : }
1759 :
1760 : } // namespace VRServiceTestBinding
1761 :
1762 :
1763 :
1764 : } // namespace dom
1765 : } // namespace mozilla
|