/work/obj-fuzz/dom/bindings/MediaDevicesBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MediaDevices.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "MediaDevicesBinding.h" |
6 | | #include "MediaStreamBinding.h" |
7 | | #include "MediaTrackSupportedConstraintsBinding.h" |
8 | | #include "Navigator.h" |
9 | | #include "WrapperFactory.h" |
10 | | #include "mozilla/OwningNonNull.h" |
11 | | #include "mozilla/Preferences.h" |
12 | | #include "mozilla/dom/BindingUtils.h" |
13 | | #include "mozilla/dom/DOMJSClass.h" |
14 | | #include "mozilla/dom/MediaDevices.h" |
15 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
16 | | #include "mozilla/dom/Nullable.h" |
17 | | #include "mozilla/dom/Promise.h" |
18 | | #include "mozilla/dom/ToJSValue.h" |
19 | | #include "mozilla/dom/XrayExpandoClass.h" |
20 | | #include "nsContentUtils.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | namespace MediaDevices_Binding { |
30 | | |
31 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
32 | | "Can't inherit from an interface with a different ownership model."); |
33 | | |
34 | | MOZ_CAN_RUN_SCRIPT static bool |
35 | | get_ondevicechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, JSJitGetterCallArgs args) |
36 | 0 | { |
37 | 0 | AUTO_PROFILER_LABEL_FAST("get MediaDevices.ondevicechange", DOM, cx); |
38 | 0 |
|
39 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOndevicechange()); |
40 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
41 | 0 | if (result) { |
42 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
43 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
44 | 0 | return false; |
45 | 0 | } |
46 | 0 | return true; |
47 | 0 | } else { |
48 | 0 | args.rval().setNull(); |
49 | 0 | return true; |
50 | 0 | } |
51 | 0 | } |
52 | | |
53 | | MOZ_CAN_RUN_SCRIPT static bool |
54 | | set_ondevicechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, JSJitSetterCallArgs args) |
55 | 0 | { |
56 | 0 | AUTO_PROFILER_LABEL_FAST("set MediaDevices.ondevicechange", DOM, cx); |
57 | 0 |
|
58 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
59 | 0 | if (args[0].isObject()) { |
60 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
61 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
62 | 0 | } |
63 | 0 | } else { |
64 | 0 | arg0 = nullptr; |
65 | 0 | } |
66 | 0 | self->SetOndevicechange(Constify(arg0)); |
67 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
68 | 0 |
|
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | static const JSJitInfo ondevicechange_getterinfo = { |
73 | | { (JSJitGetterOp)get_ondevicechange }, |
74 | | { prototypes::id::MediaDevices }, |
75 | | { PrototypeTraits<prototypes::id::MediaDevices>::Depth }, |
76 | | JSJitInfo::Getter, |
77 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
78 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
79 | | false, /* isInfallible. False in setters. */ |
80 | | false, /* isMovable. Not relevant for setters. */ |
81 | | false, /* isEliminatable. Not relevant for setters. */ |
82 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
83 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
84 | | false, /* isTypedMethod. Only relevant for methods. */ |
85 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
86 | | }; |
87 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
88 | | static_assert(0 < 1, "There is no slot for us"); |
89 | | static const JSJitInfo ondevicechange_setterinfo = { |
90 | | { (JSJitGetterOp)set_ondevicechange }, |
91 | | { prototypes::id::MediaDevices }, |
92 | | { PrototypeTraits<prototypes::id::MediaDevices>::Depth }, |
93 | | JSJitInfo::Setter, |
94 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
95 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
96 | | false, /* isInfallible. False in setters. */ |
97 | | false, /* isMovable. Not relevant for setters. */ |
98 | | false, /* isEliminatable. Not relevant for setters. */ |
99 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
100 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
101 | | false, /* isTypedMethod. Only relevant for methods. */ |
102 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
103 | | }; |
104 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
105 | | static_assert(0 < 1, "There is no slot for us"); |
106 | | |
107 | | MOZ_CAN_RUN_SCRIPT static bool |
108 | | getSupportedConstraints(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, const JSJitMethodCallArgs& args) |
109 | 0 | { |
110 | 0 | AUTO_PROFILER_LABEL_FAST("MediaDevices.getSupportedConstraints", DOM, cx); |
111 | 0 |
|
112 | 0 | MediaTrackSupportedConstraints result; |
113 | 0 | self->GetSupportedConstraints(result); |
114 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
115 | 0 | if (!result.ToObjectInternal(cx, args.rval())) { |
116 | 0 | return false; |
117 | 0 | } |
118 | 0 | return true; |
119 | 0 | } |
120 | | |
121 | | static const JSJitInfo getSupportedConstraints_methodinfo = { |
122 | | { (JSJitGetterOp)getSupportedConstraints }, |
123 | | { prototypes::id::MediaDevices }, |
124 | | { PrototypeTraits<prototypes::id::MediaDevices>::Depth }, |
125 | | JSJitInfo::Method, |
126 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
127 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
128 | | false, /* isInfallible. False in setters. */ |
129 | | false, /* isMovable. Not relevant for setters. */ |
130 | | false, /* isEliminatable. Not relevant for setters. */ |
131 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
132 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
133 | | false, /* isTypedMethod. Only relevant for methods. */ |
134 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
135 | | }; |
136 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
137 | | static_assert(0 < 1, "There is no slot for us"); |
138 | | |
139 | | MOZ_CAN_RUN_SCRIPT static bool |
140 | | enumerateDevices(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, const JSJitMethodCallArgs& args) |
141 | 0 | { |
142 | 0 | AUTO_PROFILER_LABEL_FAST("MediaDevices.enumerateDevices", DOM, cx); |
143 | 0 |
|
144 | 0 | FastErrorResult rv; |
145 | 0 | auto result(StrongOrRawPtr<Promise>(self->EnumerateDevices(nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
146 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
147 | 0 | return false; |
148 | 0 | } |
149 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
150 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 | return true; |
154 | 0 | } |
155 | | |
156 | | MOZ_CAN_RUN_SCRIPT static bool |
157 | | enumerateDevices_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, const JSJitMethodCallArgs& args) |
158 | 0 | { |
159 | 0 | bool ok = enumerateDevices(cx, obj, self, args); |
160 | 0 | if (ok) { |
161 | 0 | return true; |
162 | 0 | } |
163 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
164 | 0 | } |
165 | | |
166 | | static const JSJitInfo enumerateDevices_methodinfo = { |
167 | | { (JSJitGetterOp)enumerateDevices_promiseWrapper }, |
168 | | { prototypes::id::MediaDevices }, |
169 | | { PrototypeTraits<prototypes::id::MediaDevices>::Depth }, |
170 | | JSJitInfo::Method, |
171 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
172 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
173 | | false, /* isInfallible. False in setters. */ |
174 | | false, /* isMovable. Not relevant for setters. */ |
175 | | false, /* isEliminatable. Not relevant for setters. */ |
176 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
177 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
178 | | false, /* isTypedMethod. Only relevant for methods. */ |
179 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
180 | | }; |
181 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
182 | | static_assert(0 < 1, "There is no slot for us"); |
183 | | |
184 | | MOZ_CAN_RUN_SCRIPT static bool |
185 | | getUserMedia(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, const JSJitMethodCallArgs& args) |
186 | 0 | { |
187 | 0 | AUTO_PROFILER_LABEL_FAST("MediaDevices.getUserMedia", DOM, cx); |
188 | 0 |
|
189 | 0 | binding_detail::FastMediaStreamConstraints arg0; |
190 | 0 | if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue, "Argument 1 of MediaDevices.getUserMedia", false)) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | FastErrorResult rv; |
194 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetUserMedia(Constify(arg0), nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv))); |
195 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
196 | 0 | return false; |
197 | 0 | } |
198 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
199 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
200 | 0 | return false; |
201 | 0 | } |
202 | 0 | return true; |
203 | 0 | } |
204 | | |
205 | | MOZ_CAN_RUN_SCRIPT static bool |
206 | | getUserMedia_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDevices* self, const JSJitMethodCallArgs& args) |
207 | 0 | { |
208 | 0 | bool ok = getUserMedia(cx, obj, self, args); |
209 | 0 | if (ok) { |
210 | 0 | return true; |
211 | 0 | } |
212 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
213 | 0 | } |
214 | | |
215 | | static const JSJitInfo getUserMedia_methodinfo = { |
216 | | { (JSJitGetterOp)getUserMedia_promiseWrapper }, |
217 | | { prototypes::id::MediaDevices }, |
218 | | { PrototypeTraits<prototypes::id::MediaDevices>::Depth }, |
219 | | JSJitInfo::Method, |
220 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
221 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
222 | | false, /* isInfallible. False in setters. */ |
223 | | false, /* isMovable. Not relevant for setters. */ |
224 | | false, /* isEliminatable. Not relevant for setters. */ |
225 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
226 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
227 | | false, /* isTypedMethod. Only relevant for methods. */ |
228 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
229 | | }; |
230 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
231 | | static_assert(0 < 1, "There is no slot for us"); |
232 | | |
233 | | static bool |
234 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
235 | 0 | { |
236 | 0 | mozilla::dom::MediaDevices* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaDevices>(obj); |
237 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
238 | 0 | // obviously can't preserve if we're not initialized. |
239 | 0 | if (self && self->GetWrapperPreserveColor()) { |
240 | 0 | PreserveWrapper(self); |
241 | 0 | } |
242 | 0 | return true; |
243 | 0 | } |
244 | | |
245 | | static void |
246 | | _finalize(js::FreeOp* fop, JSObject* obj) |
247 | 0 | { |
248 | 0 | mozilla::dom::MediaDevices* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaDevices>(obj); |
249 | 0 | if (self) { |
250 | 0 | ClearWrapper(self, self, obj); |
251 | 0 | AddForDeferredFinalization<mozilla::dom::MediaDevices>(self); |
252 | 0 | } |
253 | 0 | } |
254 | | |
255 | | static size_t |
256 | | _objectMoved(JSObject* obj, JSObject* old) |
257 | 0 | { |
258 | 0 | mozilla::dom::MediaDevices* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaDevices>(obj); |
259 | 0 | if (self) { |
260 | 0 | UpdateWrapper(self, self, obj, old); |
261 | 0 | } |
262 | 0 |
|
263 | 0 | return 0; |
264 | 0 | } |
265 | | |
266 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
267 | | #if defined(__clang__) |
268 | | #pragma clang diagnostic push |
269 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
270 | | #endif |
271 | | static const JSFunctionSpec sMethods_specs[] = { |
272 | | JS_FNSPEC("getSupportedConstraints", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getSupportedConstraints_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
273 | | JS_FNSPEC("enumerateDevices", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&enumerateDevices_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
274 | | JS_FNSPEC("getUserMedia", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getUserMedia_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
275 | | JS_FS_END |
276 | | }; |
277 | | #if defined(__clang__) |
278 | | #pragma clang diagnostic pop |
279 | | #endif |
280 | | |
281 | | |
282 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
283 | | { nullptr, &sMethods_specs[0] }, |
284 | | { nullptr, nullptr } |
285 | | }; |
286 | | |
287 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
288 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
289 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
290 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
291 | | |
292 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
293 | | #if defined(__clang__) |
294 | | #pragma clang diagnostic push |
295 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
296 | | #endif |
297 | | static const JSPropertySpec sAttributes_specs[] = { |
298 | | { "ondevicechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ondevicechange_getterinfo, GenericSetter<NormalThisPolicy>, &ondevicechange_setterinfo }, |
299 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
300 | | }; |
301 | | #if defined(__clang__) |
302 | | #pragma clang diagnostic pop |
303 | | #endif |
304 | | |
305 | | // Can't be const because the pref-enabled boolean needs to be writable |
306 | | static PrefableDisablers sAttributes_disablers0 = { |
307 | | true, false, 0, nullptr |
308 | | }; |
309 | | |
310 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
311 | | { &sAttributes_disablers0, &sAttributes_specs[0] }, |
312 | | { nullptr, nullptr } |
313 | | }; |
314 | | |
315 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
316 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
317 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
318 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
319 | | |
320 | | |
321 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
322 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
323 | | |
324 | | static const NativePropertiesN<2> sNativeProperties = { |
325 | | false, 0, |
326 | | false, 0, |
327 | | true, 0 /* sMethods */, |
328 | | true, 1 /* sAttributes */, |
329 | | false, 0, |
330 | | false, 0, |
331 | | false, 0, |
332 | | -1, |
333 | | 4, |
334 | | sNativeProperties_sortedPropertyIndices, |
335 | | { |
336 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
337 | | { sAttributes, &sNativeProperties_propertyInfos[3] } |
338 | | } |
339 | | }; |
340 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
341 | | "We have a property info count that is oversized"); |
342 | | |
343 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
344 | | { |
345 | | "Function", |
346 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
347 | | &sBoringInterfaceObjectClassClassOps, |
348 | | JS_NULL_CLASS_SPEC, |
349 | | JS_NULL_CLASS_EXT, |
350 | | &sInterfaceObjectClassObjectOps |
351 | | }, |
352 | | eInterface, |
353 | | true, |
354 | | prototypes::id::MediaDevices, |
355 | | PrototypeTraits<prototypes::id::MediaDevices>::Depth, |
356 | | sNativePropertyHooks, |
357 | | "function MediaDevices() {\n [native code]\n}", |
358 | | EventTarget_Binding::GetConstructorObject |
359 | | }; |
360 | | |
361 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
362 | | { |
363 | | "MediaDevicesPrototype", |
364 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
365 | | JS_NULL_CLASS_OPS, |
366 | | JS_NULL_CLASS_SPEC, |
367 | | JS_NULL_CLASS_EXT, |
368 | | JS_NULL_OBJECT_OPS |
369 | | }, |
370 | | eInterfacePrototype, |
371 | | false, |
372 | | prototypes::id::MediaDevices, |
373 | | PrototypeTraits<prototypes::id::MediaDevices>::Depth, |
374 | | sNativePropertyHooks, |
375 | | "[object MediaDevicesPrototype]", |
376 | | EventTarget_Binding::GetProtoObject |
377 | | }; |
378 | | |
379 | | bool |
380 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
381 | 0 | { |
382 | 0 | return Navigator::HasUserMediaSupport(aCx, aObj); |
383 | 0 | } |
384 | | |
385 | | static const js::ClassOps sClassOps = { |
386 | | _addProperty, /* addProperty */ |
387 | | nullptr, /* delProperty */ |
388 | | nullptr, /* enumerate */ |
389 | | nullptr, /* newEnumerate */ |
390 | | nullptr, /* resolve */ |
391 | | nullptr, /* mayResolve */ |
392 | | _finalize, /* finalize */ |
393 | | nullptr, /* call */ |
394 | | nullptr, /* hasInstance */ |
395 | | nullptr, /* construct */ |
396 | | nullptr, /* trace */ |
397 | | }; |
398 | | |
399 | | static const js::ClassExtension sClassExtension = { |
400 | | nullptr, /* weakmapKeyDelegateOp */ |
401 | | _objectMoved /* objectMovedOp */ |
402 | | }; |
403 | | |
404 | | static const DOMJSClass sClass = { |
405 | | { "MediaDevices", |
406 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
407 | | &sClassOps, |
408 | | JS_NULL_CLASS_SPEC, |
409 | | &sClassExtension, |
410 | | JS_NULL_OBJECT_OPS |
411 | | }, |
412 | | { prototypes::id::EventTarget, prototypes::id::MediaDevices, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
413 | | IsBaseOf<nsISupports, mozilla::dom::MediaDevices >::value, |
414 | | sNativePropertyHooks, |
415 | | FindAssociatedGlobalForNative<mozilla::dom::MediaDevices>::Get, |
416 | | GetProtoObjectHandle, |
417 | | GetCCParticipant<mozilla::dom::MediaDevices>::Get() |
418 | | }; |
419 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
420 | | "Must have the right minimal number of reserved slots."); |
421 | | static_assert(1 >= 1, |
422 | | "Must have enough reserved slots."); |
423 | | |
424 | | const JSClass* |
425 | | GetJSClass() |
426 | 0 | { |
427 | 0 | return sClass.ToJSClass(); |
428 | 0 | } |
429 | | |
430 | | bool |
431 | | Wrap(JSContext* aCx, mozilla::dom::MediaDevices* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
432 | 0 | { |
433 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MediaDevices>::value, |
434 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
435 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::MediaDevices*>(aObject) == |
436 | 0 | reinterpret_cast<mozilla::dom::MediaDevices*>(aObject), |
437 | 0 | "Multiple inheritance for mozilla::dom::MediaDevices is broken."); |
438 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
439 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
440 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
441 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
442 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
443 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
444 | 0 | "You should probably not be using Wrap() directly; use " |
445 | 0 | "GetOrCreateDOMReflector instead"); |
446 | 0 |
|
447 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
448 | 0 | "nsISupports must be on our primary inheritance chain"); |
449 | 0 |
|
450 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
451 | 0 | if (!global) { |
452 | 0 | return false; |
453 | 0 | } |
454 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
455 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
456 | 0 |
|
457 | 0 | // That might have ended up wrapping us already, due to the wonders |
458 | 0 | // of XBL. Check for that, and bail out as needed. |
459 | 0 | aReflector.set(aCache->GetWrapper()); |
460 | 0 | if (aReflector) { |
461 | | #ifdef DEBUG |
462 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
463 | | #endif // DEBUG |
464 | | return true; |
465 | 0 | } |
466 | 0 |
|
467 | 0 | JSAutoRealm ar(aCx, global); |
468 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
469 | 0 | if (!canonicalProto) { |
470 | 0 | return false; |
471 | 0 | } |
472 | 0 | JS::Rooted<JSObject*> proto(aCx); |
473 | 0 | if (aGivenProto) { |
474 | 0 | proto = aGivenProto; |
475 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
476 | 0 | // coming in, we changed compartments to that of "parent" so may need |
477 | 0 | // to wrap the proto here. |
478 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
479 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
480 | 0 | return false; |
481 | 0 | } |
482 | 0 | } |
483 | 0 | } else { |
484 | 0 | proto = canonicalProto; |
485 | 0 | } |
486 | 0 |
|
487 | 0 | BindingJSObjectCreator<mozilla::dom::MediaDevices> creator(aCx); |
488 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
489 | 0 | if (!aReflector) { |
490 | 0 | return false; |
491 | 0 | } |
492 | 0 | |
493 | 0 | aCache->SetWrapper(aReflector); |
494 | 0 | creator.InitializationSucceeded(); |
495 | 0 |
|
496 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
497 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
498 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
499 | 0 | // otherwise we won't be able to properly recreate it later, since |
500 | 0 | // we won't know what proto to use. Note that we don't check |
501 | 0 | // aGivenProto here, since it's entirely possible (and even |
502 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
503 | 0 | // same as canonicalProto. |
504 | 0 | if (proto != canonicalProto) { |
505 | 0 | PreserveWrapper(aObject); |
506 | 0 | } |
507 | 0 |
|
508 | 0 | return true; |
509 | 0 | } |
510 | | |
511 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
512 | | nullptr, |
513 | | nullptr, |
514 | | nullptr, |
515 | | { sNativeProperties.Upcast(), nullptr }, |
516 | | prototypes::id::MediaDevices, |
517 | | constructors::id::MediaDevices, |
518 | | EventTarget_Binding::sNativePropertyHooks, |
519 | | &DefaultXrayExpandoObjectClass |
520 | | } }; |
521 | | |
522 | | void |
523 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
524 | 0 | { |
525 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
526 | 0 | if (!parentProto) { |
527 | 0 | return; |
528 | 0 | } |
529 | 0 | |
530 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
531 | 0 | if (!constructorProto) { |
532 | 0 | return; |
533 | 0 | } |
534 | 0 | |
535 | 0 | static bool sIdsInited = false; |
536 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
537 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
538 | 0 | return; |
539 | 0 | } |
540 | 0 | sIdsInited = true; |
541 | 0 | } |
542 | 0 |
|
543 | 0 | static bool sPrefCachesInited = false; |
544 | 0 | if (!sPrefCachesInited && NS_IsMainThread()) { |
545 | 0 | sPrefCachesInited = true; |
546 | 0 | Preferences::AddBoolVarCache(&sAttributes[0].disablers->enabled, "media.ondevicechange.enabled"); |
547 | 0 | } |
548 | 0 |
|
549 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaDevices); |
550 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaDevices); |
551 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
552 | 0 | &sPrototypeClass.mBase, protoCache, |
553 | 0 | nullptr, |
554 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
555 | 0 | interfaceCache, |
556 | 0 | sNativeProperties.Upcast(), |
557 | 0 | nullptr, |
558 | 0 | "MediaDevices", aDefineOnGlobal, |
559 | 0 | nullptr, |
560 | 0 | false); |
561 | 0 | } |
562 | | |
563 | | JSObject* |
564 | | GetConstructorObject(JSContext* aCx) |
565 | 0 | { |
566 | 0 | return GetConstructorObjectHandle(aCx); |
567 | 0 | } |
568 | | |
569 | | } // namespace MediaDevices_Binding |
570 | | |
571 | | |
572 | | |
573 | | } // namespace dom |
574 | | } // namespace mozilla |