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