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