Line data Source code
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 MediaDeviceKindValues {
18 : extern const EnumEntry strings[4] = {
19 : {"audioinput", 10},
20 : {"audiooutput", 11},
21 : {"videoinput", 10},
22 : { nullptr, 0 }
23 : };
24 : } // namespace MediaDeviceKindValues
25 :
26 : bool
27 0 : ToJSValue(JSContext* aCx, MediaDeviceKind aArgument, JS::MutableHandle<JS::Value> aValue)
28 : {
29 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaDeviceKindValues::strings));
30 : JSString* resultStr =
31 0 : JS_NewStringCopyN(aCx, MediaDeviceKindValues::strings[uint32_t(aArgument)].value,
32 0 : MediaDeviceKindValues::strings[uint32_t(aArgument)].length);
33 0 : if (!resultStr) {
34 0 : return false;
35 : }
36 0 : aValue.setString(resultStr);
37 0 : return true;
38 : }
39 :
40 :
41 : namespace MediaDeviceInfoBinding {
42 :
43 : static bool
44 0 : get_deviceId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDeviceInfo* self, JSJitGetterCallArgs args)
45 : {
46 0 : DOMString result;
47 0 : self->GetDeviceId(result);
48 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
49 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
50 0 : return false;
51 : }
52 0 : return true;
53 : }
54 :
55 : static const JSJitInfo deviceId_getterinfo = {
56 : { (JSJitGetterOp)get_deviceId },
57 : { prototypes::id::MediaDeviceInfo },
58 : { PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth },
59 : JSJitInfo::Getter,
60 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
61 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
62 : false, /* isInfallible. False in setters. */
63 : false, /* isMovable. Not relevant for setters. */
64 : false, /* isEliminatable. Not relevant for setters. */
65 : false, /* isAlwaysInSlot. Only relevant for getters. */
66 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
67 : false, /* isTypedMethod. Only relevant for methods. */
68 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
69 : };
70 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
71 : static_assert(0 < 1, "There is no slot for us");
72 :
73 : static bool
74 0 : get_kind(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDeviceInfo* self, JSJitGetterCallArgs args)
75 : {
76 0 : MediaDeviceKind result(self->Kind());
77 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
78 0 : if (!ToJSValue(cx, result, args.rval())) {
79 0 : return false;
80 : }
81 0 : return true;
82 : }
83 :
84 : static const JSJitInfo kind_getterinfo = {
85 : { (JSJitGetterOp)get_kind },
86 : { prototypes::id::MediaDeviceInfo },
87 : { PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth },
88 : JSJitInfo::Getter,
89 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
90 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
91 : false, /* isInfallible. False in setters. */
92 : false, /* isMovable. Not relevant for setters. */
93 : false, /* isEliminatable. Not relevant for setters. */
94 : false, /* isAlwaysInSlot. Only relevant for getters. */
95 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
96 : false, /* isTypedMethod. Only relevant for methods. */
97 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
98 : };
99 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
100 : static_assert(0 < 1, "There is no slot for us");
101 :
102 : static bool
103 0 : get_label(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDeviceInfo* self, JSJitGetterCallArgs args)
104 : {
105 0 : DOMString result;
106 0 : self->GetLabel(result);
107 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
108 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
109 0 : return false;
110 : }
111 0 : return true;
112 : }
113 :
114 : static const JSJitInfo label_getterinfo = {
115 : { (JSJitGetterOp)get_label },
116 : { prototypes::id::MediaDeviceInfo },
117 : { PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth },
118 : JSJitInfo::Getter,
119 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
120 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
121 : false, /* isInfallible. False in setters. */
122 : false, /* isMovable. Not relevant for setters. */
123 : false, /* isEliminatable. Not relevant for setters. */
124 : false, /* isAlwaysInSlot. Only relevant for getters. */
125 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
126 : false, /* isTypedMethod. Only relevant for methods. */
127 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
128 : };
129 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
130 : static_assert(0 < 1, "There is no slot for us");
131 :
132 : static bool
133 0 : get_groupId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDeviceInfo* self, JSJitGetterCallArgs args)
134 : {
135 0 : DOMString result;
136 0 : self->GetGroupId(result);
137 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
138 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
139 0 : return false;
140 : }
141 0 : return true;
142 : }
143 :
144 : static const JSJitInfo groupId_getterinfo = {
145 : { (JSJitGetterOp)get_groupId },
146 : { prototypes::id::MediaDeviceInfo },
147 : { PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth },
148 : JSJitInfo::Getter,
149 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
150 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
151 : false, /* isInfallible. False in setters. */
152 : false, /* isMovable. Not relevant for setters. */
153 : false, /* isEliminatable. Not relevant for setters. */
154 : false, /* isAlwaysInSlot. Only relevant for getters. */
155 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
156 : false, /* isTypedMethod. Only relevant for methods. */
157 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
158 : };
159 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
160 : static_assert(0 < 1, "There is no slot for us");
161 :
162 : bool
163 0 : JsonifyAttributes(JSContext* aCx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDeviceInfo* self, JS::Rooted<JSObject*>& aResult)
164 : {
165 : { // scope for "temp"
166 0 : JS::Rooted<JS::Value> temp(aCx);
167 0 : if (!get_deviceId(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
168 0 : return false;
169 : }
170 0 : if (!JS_DefineProperty(aCx, aResult, "deviceId", temp, JSPROP_ENUMERATE)) {
171 0 : return false;
172 : }
173 : }
174 : { // scope for "temp"
175 0 : JS::Rooted<JS::Value> temp(aCx);
176 0 : if (!get_kind(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
177 0 : return false;
178 : }
179 0 : if (!JS_DefineProperty(aCx, aResult, "kind", temp, JSPROP_ENUMERATE)) {
180 0 : return false;
181 : }
182 : }
183 : { // scope for "temp"
184 0 : JS::Rooted<JS::Value> temp(aCx);
185 0 : if (!get_label(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
186 0 : return false;
187 : }
188 0 : if (!JS_DefineProperty(aCx, aResult, "label", temp, JSPROP_ENUMERATE)) {
189 0 : return false;
190 : }
191 : }
192 : { // scope for "temp"
193 0 : JS::Rooted<JS::Value> temp(aCx);
194 0 : if (!get_groupId(aCx, obj, self, JSJitGetterCallArgs(&temp))) {
195 0 : return false;
196 : }
197 0 : if (!JS_DefineProperty(aCx, aResult, "groupId", temp, JSPROP_ENUMERATE)) {
198 0 : return false;
199 : }
200 : }
201 0 : return true;
202 : }
203 :
204 : static bool
205 0 : __jsonifier(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaDeviceInfo* self, const JSJitMethodCallArgs& args)
206 : {
207 0 : JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx));
208 0 : if (!result) {
209 0 : return false;
210 : }
211 0 : if (!MediaDeviceInfoBinding::JsonifyAttributes(cx, obj, self, result)) {
212 0 : return false;
213 : }
214 0 : args.rval().setObject(*result);
215 0 : return true;
216 : }
217 :
218 : static const JSJitInfo __jsonifier_methodinfo = {
219 : { (JSJitGetterOp)__jsonifier },
220 : { prototypes::id::MediaDeviceInfo },
221 : { PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth },
222 : JSJitInfo::Method,
223 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
224 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
225 : false, /* isInfallible. False in setters. */
226 : false, /* isMovable. Not relevant for setters. */
227 : false, /* isEliminatable. Not relevant for setters. */
228 : false, /* isAlwaysInSlot. Only relevant for getters. */
229 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
230 : false, /* isTypedMethod. Only relevant for methods. */
231 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
232 : };
233 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
234 : static_assert(0 < 1, "There is no slot for us");
235 :
236 : static bool
237 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
238 : {
239 0 : mozilla::dom::MediaDeviceInfo* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaDeviceInfo>(obj);
240 : // We don't want to preserve if we don't have a wrapper, and we
241 : // obviously can't preserve if we're not initialized.
242 0 : if (self && self->GetWrapperPreserveColor()) {
243 0 : PreserveWrapper(self);
244 : }
245 0 : return true;
246 : }
247 :
248 : static void
249 0 : _finalize(js::FreeOp* fop, JSObject* obj)
250 : {
251 0 : mozilla::dom::MediaDeviceInfo* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaDeviceInfo>(obj);
252 0 : if (self) {
253 0 : ClearWrapper(self, self, obj);
254 0 : AddForDeferredFinalization<mozilla::dom::MediaDeviceInfo>(self);
255 : }
256 0 : }
257 :
258 : static void
259 0 : _objectMoved(JSObject* obj, const JSObject* old)
260 : {
261 0 : mozilla::dom::MediaDeviceInfo* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaDeviceInfo>(obj);
262 0 : if (self) {
263 0 : UpdateWrapper(self, self, obj, old);
264 : }
265 0 : }
266 :
267 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
268 : #if defined(__clang__)
269 : #pragma clang diagnostic push
270 : #pragma clang diagnostic ignored "-Wmissing-braces"
271 : #endif
272 : static const JSFunctionSpec sMethods_specs[] = {
273 : JS_FNSPEC("toJSON", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&__jsonifier_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
274 : JS_FS_END
275 : };
276 : #if defined(__clang__)
277 : #pragma clang diagnostic pop
278 : #endif
279 :
280 :
281 : // Can't be const because the pref-enabled boolean needs to be writable
282 : static 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(1 <= 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 : { "deviceId", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &deviceId_getterinfo, nullptr, nullptr },
299 : { "kind", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &kind_getterinfo, nullptr, nullptr },
300 : { "label", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &label_getterinfo, nullptr, nullptr },
301 : { "groupId", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &groupId_getterinfo, nullptr, nullptr },
302 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
303 : };
304 : #if defined(__clang__)
305 : #pragma clang diagnostic pop
306 : #endif
307 :
308 :
309 : // Can't be const because the pref-enabled boolean needs to be writable
310 : static Prefable<const JSPropertySpec> sAttributes[] = {
311 : { nullptr, &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(4 <= 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[5];
322 : static PropertyInfo sNativeProperties_propertyInfos[5];
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 : 5,
334 : sNativeProperties_sortedPropertyIndices,
335 : {
336 : { sMethods, &sNativeProperties_propertyInfos[0] },
337 : { sAttributes, &sNativeProperties_propertyInfos[1] }
338 : }
339 : };
340 : static_assert(5 < 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::MediaDeviceInfo,
355 : PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth,
356 : sNativePropertyHooks,
357 : "function MediaDeviceInfo() {\n [native code]\n}",
358 : JS::GetRealmFunctionPrototype
359 : };
360 :
361 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
362 : {
363 : "MediaDeviceInfoPrototype",
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::MediaDeviceInfo,
373 : PrototypeTraits<prototypes::id::MediaDeviceInfo>::Depth,
374 : sNativePropertyHooks,
375 : "[object MediaDeviceInfoPrototype]",
376 : JS::GetRealmObjectPrototype
377 : };
378 :
379 : bool
380 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
381 : {
382 0 : return Navigator::HasUserMediaSupport(aCx, aObj);
383 : }
384 :
385 : JSObject*
386 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
387 : {
388 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
389 : }
390 :
391 : static const js::ClassOps sClassOps = {
392 : _addProperty, /* addProperty */
393 : nullptr, /* delProperty */
394 : nullptr, /* getProperty */
395 : nullptr, /* setProperty */
396 : nullptr, /* enumerate */
397 : nullptr, /* newEnumerate */
398 : nullptr, /* resolve */
399 : nullptr, /* mayResolve */
400 : _finalize, /* finalize */
401 : nullptr, /* call */
402 : nullptr, /* hasInstance */
403 : nullptr, /* construct */
404 : nullptr, /* trace */
405 : };
406 :
407 : static const js::ClassExtension sClassExtension = {
408 : nullptr, /* weakmapKeyDelegateOp */
409 : _objectMoved /* objectMovedOp */
410 : };
411 :
412 : static const DOMJSClass sClass = {
413 : { "MediaDeviceInfo",
414 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
415 : &sClassOps,
416 : JS_NULL_CLASS_SPEC,
417 : &sClassExtension,
418 : JS_NULL_OBJECT_OPS
419 : },
420 : { 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 },
421 : IsBaseOf<nsISupports, mozilla::dom::MediaDeviceInfo >::value,
422 : sNativePropertyHooks,
423 : FindAssociatedGlobalForNative<mozilla::dom::MediaDeviceInfo>::Get,
424 : GetProtoObjectHandle,
425 : GetCCParticipant<mozilla::dom::MediaDeviceInfo>::Get()
426 : };
427 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
428 : "Must have the right minimal number of reserved slots.");
429 : static_assert(1 >= 1,
430 : "Must have enough reserved slots.");
431 :
432 : const JSClass*
433 0 : GetJSClass()
434 : {
435 0 : return sClass.ToJSClass();
436 : }
437 :
438 : bool
439 0 : Wrap(JSContext* aCx, mozilla::dom::MediaDeviceInfo* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
440 : {
441 : MOZ_ASSERT(static_cast<mozilla::dom::MediaDeviceInfo*>(aObject) ==
442 : reinterpret_cast<mozilla::dom::MediaDeviceInfo*>(aObject),
443 : "Multiple inheritance for mozilla::dom::MediaDeviceInfo is broken.");
444 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
445 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
446 0 : MOZ_ASSERT(!aCache->GetWrapper(),
447 : "You should probably not be using Wrap() directly; use "
448 : "GetOrCreateDOMReflector instead");
449 :
450 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
451 : "nsISupports must be on our primary inheritance chain");
452 :
453 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
454 0 : if (!global) {
455 0 : return false;
456 : }
457 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
458 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
459 :
460 : // That might have ended up wrapping us already, due to the wonders
461 : // of XBL. Check for that, and bail out as needed.
462 0 : aReflector.set(aCache->GetWrapper());
463 0 : if (aReflector) {
464 : #ifdef DEBUG
465 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
466 : #endif // DEBUG
467 0 : return true;
468 : }
469 :
470 0 : JSAutoCompartment ac(aCx, global);
471 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
472 0 : if (!canonicalProto) {
473 0 : return false;
474 : }
475 0 : JS::Rooted<JSObject*> proto(aCx);
476 0 : if (aGivenProto) {
477 0 : proto = aGivenProto;
478 : // Unfortunately, while aGivenProto was in the compartment of aCx
479 : // coming in, we changed compartments to that of "parent" so may need
480 : // to wrap the proto here.
481 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
482 0 : if (!JS_WrapObject(aCx, &proto)) {
483 0 : return false;
484 : }
485 : }
486 : } else {
487 0 : proto = canonicalProto;
488 : }
489 :
490 0 : BindingJSObjectCreator<mozilla::dom::MediaDeviceInfo> creator(aCx);
491 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
492 0 : if (!aReflector) {
493 0 : return false;
494 : }
495 :
496 0 : aCache->SetWrapper(aReflector);
497 0 : creator.InitializationSucceeded();
498 :
499 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
500 : aCache->GetWrapperPreserveColor() == aReflector);
501 : // If proto != canonicalProto, we have to preserve our wrapper;
502 : // otherwise we won't be able to properly recreate it later, since
503 : // we won't know what proto to use. Note that we don't check
504 : // aGivenProto here, since it's entirely possible (and even
505 : // somewhat common) to have a non-null aGivenProto which is the
506 : // same as canonicalProto.
507 0 : if (proto != canonicalProto) {
508 0 : PreserveWrapper(aObject);
509 : }
510 :
511 0 : return true;
512 : }
513 :
514 : const NativePropertyHooks sNativePropertyHooks[] = { {
515 : nullptr,
516 : nullptr,
517 : nullptr,
518 : { sNativeProperties.Upcast(), nullptr },
519 : prototypes::id::MediaDeviceInfo,
520 : constructors::id::MediaDeviceInfo,
521 : nullptr,
522 : &DefaultXrayExpandoObjectClass
523 : } };
524 :
525 : void
526 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
527 : {
528 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
529 0 : if (!parentProto) {
530 0 : return;
531 : }
532 :
533 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
534 0 : if (!constructorProto) {
535 0 : return;
536 : }
537 :
538 : static bool sIdsInited = false;
539 0 : if (!sIdsInited && NS_IsMainThread()) {
540 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
541 0 : return;
542 : }
543 0 : sIdsInited = true;
544 : }
545 :
546 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaDeviceInfo);
547 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaDeviceInfo);
548 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
549 : &sPrototypeClass.mBase, protoCache,
550 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
551 : interfaceCache,
552 : sNativeProperties.Upcast(),
553 : nullptr,
554 : "MediaDeviceInfo", aDefineOnGlobal,
555 : nullptr,
556 0 : false);
557 : }
558 :
559 : JS::Handle<JSObject*>
560 0 : GetProtoObjectHandle(JSContext* aCx)
561 : {
562 : /* Get the interface prototype object for this class. This will create the
563 : object as needed. */
564 0 : bool aDefineOnGlobal = true;
565 :
566 : /* Make sure our global is sane. Hopefully we can remove this sometime */
567 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
568 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
569 0 : return nullptr;
570 : }
571 :
572 : /* Check to see whether the interface objects are already installed */
573 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
574 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MediaDeviceInfo)) {
575 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
576 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
577 : }
578 :
579 : /*
580 : * The object might _still_ be null, but that's OK.
581 : *
582 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
583 : * traced by TraceProtoAndIfaceCache() and its contents are never
584 : * changed after they have been set.
585 : *
586 : * Calling address() avoids the read read barrier that does gray
587 : * unmarking, but it's not possible for the object to be gray here.
588 : */
589 :
590 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MediaDeviceInfo);
591 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
592 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
593 : }
594 :
595 : JS::Handle<JSObject*>
596 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
597 : {
598 : /* Get the interface object for this class. This will create the object as
599 : needed. */
600 :
601 : /* Make sure our global is sane. Hopefully we can remove this sometime */
602 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
603 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
604 0 : return nullptr;
605 : }
606 :
607 : /* Check to see whether the interface objects are already installed */
608 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
609 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MediaDeviceInfo)) {
610 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
611 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
612 : }
613 :
614 : /*
615 : * The object might _still_ be null, but that's OK.
616 : *
617 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
618 : * traced by TraceProtoAndIfaceCache() and its contents are never
619 : * changed after they have been set.
620 : *
621 : * Calling address() avoids the read read barrier that does gray
622 : * unmarking, but it's not possible for the object to be gray here.
623 : */
624 :
625 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MediaDeviceInfo);
626 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
627 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
628 : }
629 :
630 : JSObject*
631 0 : GetConstructorObject(JSContext* aCx)
632 : {
633 0 : return GetConstructorObjectHandle(aCx);
634 : }
635 :
636 : } // namespace MediaDeviceInfoBinding
637 :
638 :
639 :
640 : } // namespace dom
641 : } // namespace mozilla
|