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