Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM AudioContext.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AudioContextBinding.h"
4 : #include "BaseAudioContextBinding.h"
5 : #include "DOMMediaStream.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/Preferences.h"
9 : #include "mozilla/dom/AudioContext.h"
10 : #include "mozilla/dom/BindingUtils.h"
11 : #include "mozilla/dom/DOMJSClass.h"
12 : #include "mozilla/dom/HTMLMediaElement.h"
13 : #include "mozilla/dom/MediaElementAudioSourceNode.h"
14 : #include "mozilla/dom/MediaStreamAudioDestinationNode.h"
15 : #include "mozilla/dom/MediaStreamAudioSourceNode.h"
16 : #include "mozilla/dom/NonRefcountedDOMObject.h"
17 : #include "mozilla/dom/Promise.h"
18 : #include "mozilla/dom/ToJSValue.h"
19 : #include "mozilla/dom/XrayExpandoClass.h"
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 : namespace AudioContextBinding {
25 :
26 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<BaseAudioContextBinding::NativeType>::value,
27 : "Can't inherit from an interface with a different ownership model.");
28 :
29 : static bool
30 0 : suspend(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
31 : {
32 0 : binding_detail::FastErrorResult rv;
33 0 : auto result(StrongOrRawPtr<Promise>(self->Suspend(rv)));
34 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
35 0 : return false;
36 : }
37 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
38 0 : if (!ToJSValue(cx, result, args.rval())) {
39 0 : return false;
40 : }
41 0 : return true;
42 : }
43 :
44 : static bool
45 0 : suspend_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
46 : {
47 : // Make sure to save the callee before someone maybe messes
48 : // with rval().
49 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
50 0 : bool ok = suspend(cx, obj, self, args);
51 0 : if (ok) {
52 0 : return true;
53 : }
54 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
55 0 : args.rval());
56 : }
57 :
58 : static const JSJitInfo suspend_methodinfo = {
59 : { (JSJitGetterOp)suspend_promiseWrapper },
60 : { prototypes::id::AudioContext },
61 : { PrototypeTraits<prototypes::id::AudioContext>::Depth },
62 : JSJitInfo::Method,
63 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
64 : JSVAL_TYPE_OBJECT, /* 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 : close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
78 : {
79 0 : binding_detail::FastErrorResult rv;
80 0 : auto result(StrongOrRawPtr<Promise>(self->Close(rv)));
81 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
82 0 : return false;
83 : }
84 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
85 0 : if (!ToJSValue(cx, result, args.rval())) {
86 0 : return false;
87 : }
88 0 : return true;
89 : }
90 :
91 : static bool
92 0 : close_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
93 : {
94 : // Make sure to save the callee before someone maybe messes
95 : // with rval().
96 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
97 0 : bool ok = close(cx, obj, self, args);
98 0 : if (ok) {
99 0 : return true;
100 : }
101 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
102 0 : args.rval());
103 : }
104 :
105 : static const JSJitInfo close_methodinfo = {
106 : { (JSJitGetterOp)close_promiseWrapper },
107 : { prototypes::id::AudioContext },
108 : { PrototypeTraits<prototypes::id::AudioContext>::Depth },
109 : JSJitInfo::Method,
110 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
111 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
112 : false, /* isInfallible. False in setters. */
113 : false, /* isMovable. Not relevant for setters. */
114 : false, /* isEliminatable. Not relevant for setters. */
115 : false, /* isAlwaysInSlot. Only relevant for getters. */
116 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
117 : false, /* isTypedMethod. Only relevant for methods. */
118 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
119 : };
120 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
121 : static_assert(0 < 1, "There is no slot for us");
122 :
123 : static bool
124 0 : createMediaElementSource(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
125 : {
126 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
127 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "AudioContext.createMediaElementSource");
128 : }
129 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
130 : // Return false from the JSNative in order to trigger
131 : // an uncatchable exception.
132 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
133 0 : return false;
134 : }
135 0 : NonNull<mozilla::dom::HTMLMediaElement> arg0;
136 0 : if (args[0].isObject()) {
137 : {
138 0 : nsresult rv = UnwrapObject<prototypes::id::HTMLMediaElement, mozilla::dom::HTMLMediaElement>(args[0], arg0);
139 0 : if (NS_FAILED(rv)) {
140 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of AudioContext.createMediaElementSource", "HTMLMediaElement");
141 0 : return false;
142 : }
143 : }
144 : } else {
145 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of AudioContext.createMediaElementSource");
146 0 : return false;
147 : }
148 0 : binding_detail::FastErrorResult rv;
149 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaElementAudioSourceNode>(self->CreateMediaElementSource(NonNullHelper(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 (!GetOrCreateDOMReflector(cx, result, args.rval())) {
157 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
158 0 : return false;
159 : }
160 0 : return true;
161 : }
162 :
163 : static const JSJitInfo createMediaElementSource_methodinfo = {
164 : { (JSJitGetterOp)createMediaElementSource },
165 : { prototypes::id::AudioContext },
166 : { PrototypeTraits<prototypes::id::AudioContext>::Depth },
167 : JSJitInfo::Method,
168 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
169 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
170 : false, /* isInfallible. False in setters. */
171 : false, /* isMovable. Not relevant for setters. */
172 : false, /* isEliminatable. Not relevant for setters. */
173 : false, /* isAlwaysInSlot. Only relevant for getters. */
174 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
175 : false, /* isTypedMethod. Only relevant for methods. */
176 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
177 : };
178 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
179 : static_assert(0 < 1, "There is no slot for us");
180 :
181 : static bool
182 0 : createMediaStreamSource(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
183 : {
184 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
185 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "AudioContext.createMediaStreamSource");
186 : }
187 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
188 : // Return false from the JSNative in order to trigger
189 : // an uncatchable exception.
190 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
191 0 : return false;
192 : }
193 0 : NonNull<mozilla::DOMMediaStream> arg0;
194 0 : if (args[0].isObject()) {
195 : {
196 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStream, mozilla::DOMMediaStream>(args[0], arg0);
197 0 : if (NS_FAILED(rv)) {
198 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of AudioContext.createMediaStreamSource", "MediaStream");
199 0 : return false;
200 : }
201 : }
202 : } else {
203 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of AudioContext.createMediaStreamSource");
204 0 : return false;
205 : }
206 0 : binding_detail::FastErrorResult rv;
207 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaStreamAudioSourceNode>(self->CreateMediaStreamSource(NonNullHelper(arg0), rv)));
208 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
209 0 : return false;
210 : }
211 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
212 : static_assert(!IsPointer<decltype(result)>::value,
213 : "NewObject implies that we need to keep the object alive with a strong reference.");
214 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
215 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
216 0 : return false;
217 : }
218 0 : return true;
219 : }
220 :
221 : static const JSJitInfo createMediaStreamSource_methodinfo = {
222 : { (JSJitGetterOp)createMediaStreamSource },
223 : { prototypes::id::AudioContext },
224 : { PrototypeTraits<prototypes::id::AudioContext>::Depth },
225 : JSJitInfo::Method,
226 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
227 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
228 : false, /* isInfallible. False in setters. */
229 : false, /* isMovable. Not relevant for setters. */
230 : false, /* isEliminatable. Not relevant for setters. */
231 : false, /* isAlwaysInSlot. Only relevant for getters. */
232 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
233 : false, /* isTypedMethod. Only relevant for methods. */
234 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
235 : };
236 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
237 : static_assert(0 < 1, "There is no slot for us");
238 :
239 : static bool
240 0 : createMediaStreamDestination(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::AudioContext* self, const JSJitMethodCallArgs& args)
241 : {
242 0 : binding_detail::FastErrorResult rv;
243 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaStreamAudioDestinationNode>(self->CreateMediaStreamDestination(rv)));
244 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
245 0 : return false;
246 : }
247 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
248 : static_assert(!IsPointer<decltype(result)>::value,
249 : "NewObject implies that we need to keep the object alive with a strong reference.");
250 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
251 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
252 0 : return false;
253 : }
254 0 : return true;
255 : }
256 :
257 : static const JSJitInfo createMediaStreamDestination_methodinfo = {
258 : { (JSJitGetterOp)createMediaStreamDestination },
259 : { prototypes::id::AudioContext },
260 : { PrototypeTraits<prototypes::id::AudioContext>::Depth },
261 : JSJitInfo::Method,
262 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
263 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
264 : false, /* isInfallible. False in setters. */
265 : false, /* isMovable. Not relevant for setters. */
266 : false, /* isEliminatable. Not relevant for setters. */
267 : false, /* isAlwaysInSlot. Only relevant for getters. */
268 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
269 : false, /* isTypedMethod. Only relevant for methods. */
270 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
271 : };
272 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
273 : static_assert(0 < 1, "There is no slot for us");
274 :
275 : static bool
276 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
277 : {
278 0 : mozilla::dom::AudioContext* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioContext>(obj);
279 : // We don't want to preserve if we don't have a wrapper, and we
280 : // obviously can't preserve if we're not initialized.
281 0 : if (self && self->GetWrapperPreserveColor()) {
282 0 : PreserveWrapper(self);
283 : }
284 0 : return true;
285 : }
286 :
287 : static void
288 0 : _finalize(js::FreeOp* fop, JSObject* obj)
289 : {
290 0 : mozilla::dom::AudioContext* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioContext>(obj);
291 0 : if (self) {
292 0 : ClearWrapper(self, self, obj);
293 0 : AddForDeferredFinalization<mozilla::dom::AudioContext>(self);
294 : }
295 0 : }
296 :
297 : static void
298 0 : _objectMoved(JSObject* obj, const JSObject* old)
299 : {
300 0 : mozilla::dom::AudioContext* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioContext>(obj);
301 0 : if (self) {
302 0 : UpdateWrapper(self, self, obj, old);
303 : }
304 0 : }
305 :
306 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
307 : #if defined(__clang__)
308 : #pragma clang diagnostic push
309 : #pragma clang diagnostic ignored "-Wmissing-braces"
310 : #endif
311 : static const JSFunctionSpec sMethods_specs[] = {
312 : JS_FNSPEC("suspend", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&suspend_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
313 : JS_FNSPEC("close", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
314 : JS_FNSPEC("createMediaElementSource", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createMediaElementSource_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
315 : JS_FNSPEC("createMediaStreamSource", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createMediaStreamSource_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
316 : JS_FNSPEC("createMediaStreamDestination", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createMediaStreamDestination_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
317 : JS_FS_END
318 : };
319 : #if defined(__clang__)
320 : #pragma clang diagnostic pop
321 : #endif
322 :
323 :
324 : // Can't be const because the pref-enabled boolean needs to be writable
325 : static Prefable<const JSFunctionSpec> sMethods[] = {
326 : { nullptr, &sMethods_specs[0] },
327 : { nullptr, nullptr }
328 : };
329 :
330 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
331 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
332 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
333 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
334 :
335 :
336 : static uint16_t sNativeProperties_sortedPropertyIndices[5];
337 : static PropertyInfo sNativeProperties_propertyInfos[5];
338 :
339 : static const NativePropertiesN<1> sNativeProperties = {
340 : false, 0,
341 : false, 0,
342 : true, 0 /* sMethods */,
343 : false, 0,
344 : false, 0,
345 : false, 0,
346 : false, 0,
347 : -1,
348 : 5,
349 : sNativeProperties_sortedPropertyIndices,
350 : {
351 : { sMethods, &sNativeProperties_propertyInfos[0] }
352 : }
353 : };
354 : static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
355 : "We have a property info count that is oversized");
356 :
357 : static bool
358 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
359 : {
360 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
361 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
362 0 : if (!args.isConstructing()) {
363 : // XXXbz wish I could get the name from the callee instead of
364 : // Adding more relocations
365 0 : return ThrowConstructorWithoutNew(cx, "AudioContext");
366 : }
367 :
368 0 : GlobalObject global(cx, obj);
369 0 : if (global.Failed()) {
370 0 : return false;
371 : }
372 :
373 0 : JS::Rooted<JSObject*> desiredProto(cx);
374 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
375 0 : return false;
376 : }
377 :
378 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
379 0 : Maybe<JSAutoCompartment> ac;
380 0 : if (objIsXray) {
381 0 : obj = js::CheckedUnwrap(obj);
382 0 : if (!obj) {
383 0 : return false;
384 : }
385 0 : ac.emplace(cx, obj);
386 0 : if (!JS_WrapObject(cx, &desiredProto)) {
387 0 : return false;
388 : }
389 : }
390 0 : binding_detail::FastErrorResult rv;
391 0 : auto result(StrongOrRawPtr<mozilla::dom::AudioContext>(mozilla::dom::AudioContext::Constructor(global, rv)));
392 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
393 0 : return false;
394 : }
395 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
396 : static_assert(!IsPointer<decltype(result)>::value,
397 : "NewObject implies that we need to keep the object alive with a strong reference.");
398 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
399 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
400 0 : return false;
401 : }
402 0 : return true;
403 : }
404 :
405 : static const js::ClassOps sInterfaceObjectClassOps = {
406 : nullptr, /* addProperty */
407 : nullptr, /* delProperty */
408 : nullptr, /* getProperty */
409 : nullptr, /* setProperty */
410 : nullptr, /* enumerate */
411 : nullptr, /* newEnumerate */
412 : nullptr, /* resolve */
413 : nullptr, /* mayResolve */
414 : nullptr, /* finalize */
415 : _constructor, /* call */
416 : nullptr, /* hasInstance */
417 : _constructor, /* construct */
418 : nullptr, /* trace */
419 : };
420 :
421 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
422 : {
423 : "Function",
424 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
425 : &sInterfaceObjectClassOps,
426 : JS_NULL_CLASS_SPEC,
427 : JS_NULL_CLASS_EXT,
428 : &sInterfaceObjectClassObjectOps
429 : },
430 : eInterface,
431 : true,
432 : prototypes::id::AudioContext,
433 : PrototypeTraits<prototypes::id::AudioContext>::Depth,
434 : sNativePropertyHooks,
435 : "function AudioContext() {\n [native code]\n}",
436 : BaseAudioContextBinding::GetConstructorObject
437 : };
438 :
439 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
440 : {
441 : "AudioContextPrototype",
442 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
443 : JS_NULL_CLASS_OPS,
444 : JS_NULL_CLASS_SPEC,
445 : JS_NULL_CLASS_EXT,
446 : JS_NULL_OBJECT_OPS
447 : },
448 : eInterfacePrototype,
449 : false,
450 : prototypes::id::AudioContext,
451 : PrototypeTraits<prototypes::id::AudioContext>::Depth,
452 : sNativePropertyHooks,
453 : "[object AudioContextPrototype]",
454 : BaseAudioContextBinding::GetProtoObject
455 : };
456 :
457 : bool
458 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
459 : {
460 : static bool sPrefValue;
461 : static bool sPrefCacheSetUp = false;
462 0 : if (!sPrefCacheSetUp) {
463 0 : sPrefCacheSetUp = true;
464 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.webaudio.enabled");
465 : }
466 :
467 0 : return sPrefValue;
468 : }
469 :
470 : JSObject*
471 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
472 : {
473 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
474 : }
475 :
476 : static const js::ClassOps sClassOps = {
477 : _addProperty, /* addProperty */
478 : nullptr, /* delProperty */
479 : nullptr, /* getProperty */
480 : nullptr, /* setProperty */
481 : nullptr, /* enumerate */
482 : nullptr, /* newEnumerate */
483 : nullptr, /* resolve */
484 : nullptr, /* mayResolve */
485 : _finalize, /* finalize */
486 : nullptr, /* call */
487 : nullptr, /* hasInstance */
488 : nullptr, /* construct */
489 : nullptr, /* trace */
490 : };
491 :
492 : static const js::ClassExtension sClassExtension = {
493 : nullptr, /* weakmapKeyDelegateOp */
494 : _objectMoved /* objectMovedOp */
495 : };
496 :
497 : static const DOMJSClass sClass = {
498 : { "AudioContext",
499 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
500 : &sClassOps,
501 : JS_NULL_CLASS_SPEC,
502 : &sClassExtension,
503 : JS_NULL_OBJECT_OPS
504 : },
505 : { prototypes::id::EventTarget, prototypes::id::BaseAudioContext, prototypes::id::AudioContext, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
506 : IsBaseOf<nsISupports, mozilla::dom::AudioContext >::value,
507 : sNativePropertyHooks,
508 : FindAssociatedGlobalForNative<mozilla::dom::AudioContext>::Get,
509 : GetProtoObjectHandle,
510 : GetCCParticipant<mozilla::dom::AudioContext>::Get()
511 : };
512 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
513 : "Must have the right minimal number of reserved slots.");
514 : static_assert(1 >= 1,
515 : "Must have enough reserved slots.");
516 :
517 : const JSClass*
518 0 : GetJSClass()
519 : {
520 0 : return sClass.ToJSClass();
521 : }
522 :
523 : bool
524 0 : Wrap(JSContext* aCx, mozilla::dom::AudioContext* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
525 : {
526 : MOZ_ASSERT(static_cast<mozilla::dom::AudioContext*>(aObject) ==
527 : reinterpret_cast<mozilla::dom::AudioContext*>(aObject),
528 : "Multiple inheritance for mozilla::dom::AudioContext is broken.");
529 : MOZ_ASSERT(static_cast<mozilla::dom::AudioContext*>(aObject) ==
530 : reinterpret_cast<mozilla::dom::AudioContext*>(aObject),
531 : "Multiple inheritance for mozilla::dom::AudioContext is broken.");
532 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
533 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
534 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
535 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
536 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
537 0 : MOZ_ASSERT(!aCache->GetWrapper(),
538 : "You should probably not be using Wrap() directly; use "
539 : "GetOrCreateDOMReflector instead");
540 :
541 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
542 : "nsISupports must be on our primary inheritance chain");
543 :
544 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
545 0 : if (!global) {
546 0 : return false;
547 : }
548 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
549 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
550 :
551 : // That might have ended up wrapping us already, due to the wonders
552 : // of XBL. Check for that, and bail out as needed.
553 0 : aReflector.set(aCache->GetWrapper());
554 0 : if (aReflector) {
555 : #ifdef DEBUG
556 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
557 : #endif // DEBUG
558 0 : return true;
559 : }
560 :
561 0 : JSAutoCompartment ac(aCx, global);
562 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
563 0 : if (!canonicalProto) {
564 0 : return false;
565 : }
566 0 : JS::Rooted<JSObject*> proto(aCx);
567 0 : if (aGivenProto) {
568 0 : proto = aGivenProto;
569 : // Unfortunately, while aGivenProto was in the compartment of aCx
570 : // coming in, we changed compartments to that of "parent" so may need
571 : // to wrap the proto here.
572 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
573 0 : if (!JS_WrapObject(aCx, &proto)) {
574 0 : return false;
575 : }
576 : }
577 : } else {
578 0 : proto = canonicalProto;
579 : }
580 :
581 0 : BindingJSObjectCreator<mozilla::dom::AudioContext> creator(aCx);
582 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
583 0 : if (!aReflector) {
584 0 : return false;
585 : }
586 :
587 0 : aCache->SetWrapper(aReflector);
588 0 : creator.InitializationSucceeded();
589 :
590 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
591 : aCache->GetWrapperPreserveColor() == aReflector);
592 : // If proto != canonicalProto, we have to preserve our wrapper;
593 : // otherwise we won't be able to properly recreate it later, since
594 : // we won't know what proto to use. Note that we don't check
595 : // aGivenProto here, since it's entirely possible (and even
596 : // somewhat common) to have a non-null aGivenProto which is the
597 : // same as canonicalProto.
598 0 : if (proto != canonicalProto) {
599 0 : PreserveWrapper(aObject);
600 : }
601 :
602 0 : return true;
603 : }
604 :
605 : const NativePropertyHooks sNativePropertyHooks[] = { {
606 : nullptr,
607 : nullptr,
608 : nullptr,
609 : { sNativeProperties.Upcast(), nullptr },
610 : prototypes::id::AudioContext,
611 : constructors::id::AudioContext,
612 : BaseAudioContextBinding::sNativePropertyHooks,
613 : &DefaultXrayExpandoObjectClass
614 : } };
615 :
616 : void
617 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
618 : {
619 0 : JS::Handle<JSObject*> parentProto(BaseAudioContextBinding::GetProtoObjectHandle(aCx));
620 0 : if (!parentProto) {
621 0 : return;
622 : }
623 :
624 0 : JS::Handle<JSObject*> constructorProto(BaseAudioContextBinding::GetConstructorObjectHandle(aCx));
625 0 : if (!constructorProto) {
626 0 : return;
627 : }
628 :
629 : static bool sIdsInited = false;
630 0 : if (!sIdsInited && NS_IsMainThread()) {
631 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
632 0 : return;
633 : }
634 0 : sIdsInited = true;
635 : }
636 :
637 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::AudioContext);
638 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AudioContext);
639 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
640 : &sPrototypeClass.mBase, protoCache,
641 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
642 : interfaceCache,
643 : sNativeProperties.Upcast(),
644 : nullptr,
645 : "AudioContext", aDefineOnGlobal,
646 : nullptr,
647 0 : false);
648 : }
649 :
650 : JS::Handle<JSObject*>
651 0 : GetProtoObjectHandle(JSContext* aCx)
652 : {
653 : /* Get the interface prototype object for this class. This will create the
654 : object as needed. */
655 0 : bool aDefineOnGlobal = true;
656 :
657 : /* Make sure our global is sane. Hopefully we can remove this sometime */
658 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
659 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
660 0 : return nullptr;
661 : }
662 :
663 : /* Check to see whether the interface objects are already installed */
664 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
665 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::AudioContext)) {
666 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
667 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
668 : }
669 :
670 : /*
671 : * The object might _still_ be null, but that's OK.
672 : *
673 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
674 : * traced by TraceProtoAndIfaceCache() and its contents are never
675 : * changed after they have been set.
676 : *
677 : * Calling address() avoids the read read barrier that does gray
678 : * unmarking, but it's not possible for the object to be gray here.
679 : */
680 :
681 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::AudioContext);
682 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
683 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
684 : }
685 :
686 : JS::Handle<JSObject*>
687 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
688 : {
689 : /* Get the interface object for this class. This will create the object as
690 : needed. */
691 :
692 : /* Make sure our global is sane. Hopefully we can remove this sometime */
693 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
694 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
695 0 : return nullptr;
696 : }
697 :
698 : /* Check to see whether the interface objects are already installed */
699 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
700 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::AudioContext)) {
701 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
702 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
703 : }
704 :
705 : /*
706 : * The object might _still_ be null, but that's OK.
707 : *
708 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
709 : * traced by TraceProtoAndIfaceCache() and its contents are never
710 : * changed after they have been set.
711 : *
712 : * Calling address() avoids the read read barrier that does gray
713 : * unmarking, but it's not possible for the object to be gray here.
714 : */
715 :
716 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::AudioContext);
717 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
718 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
719 : }
720 :
721 : JSObject*
722 0 : GetConstructorObject(JSContext* aCx)
723 : {
724 0 : return GetConstructorObjectHandle(aCx);
725 : }
726 :
727 : } // namespace AudioContextBinding
728 :
729 :
730 :
731 : } // namespace dom
732 : } // namespace mozilla
|