Copy as Markdown

Other Tools

/* THIS FILE IS AUTOGENERATED FROM AudioWorkletGlobalScope.webidl BY Codegen.py - DO NOT EDIT */
#include <type_traits>
#include "AudioWorkletGlobalScopeBinding.h"
#include "MainThreadUtils.h"
#include "WorkletGlobalScopeBinding.h"
#include "WrapperFactory.h"
#include "js/CallAndConstruct.h"
#include "js/Exception.h"
#include "js/MapAndSet.h"
#include "js/Object.h"
#include "js/PropertyAndElement.h"
#include "js/PropertyDescriptor.h"
#include "js/experimental/JitInfo.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/dom/AudioWorkletGlobalScope.h"
#include "mozilla/dom/AudioWorkletProcessor.h"
#include "mozilla/dom/BindingCallContext.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMJSClass.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/PrimitiveConversions.h"
namespace mozilla::dom {
namespace binding_detail {}; // Just to make sure it's known as a namespace
using namespace mozilla::dom::binding_detail;
MOZ_CAN_RUN_SCRIPT already_AddRefed<AudioWorkletProcessor>
AudioWorkletProcessorConstructor::Construct(JS::Handle<JSObject*> options, ErrorResult& aRv, const char* aExecutionReason, ExceptionHandling aExceptionHandling, JS::Realm* aRealm)
{
CallSetup s(this, aRv, "AudioWorkletProcessorConstructor", aExceptionHandling, aRealm);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(s.GetContext());
BindingCallContext& cx = s.GetCallContext();
JS::Rooted<JS::Value> rval(cx);
JS::RootedVector<JS::Value> argv(cx);
if (!argv.resize(1)) {
// That threw an exception on the JSContext, and our CallSetup will do
// the right thing with that.
return nullptr;
}
unsigned argc = 1;
do {
JS::ExposeObjectToActiveJS(options);
argv[0].setObject(*options);
if (!MaybeWrapObjectValue(cx, argv[0])) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
break;
} while (false);
JS::Rooted<JS::Value> constructor(cx, JS::ObjectValue(*mCallback));
JS::Rooted<JSObject*> constructedObj(cx);
if (!JS::Construct(cx, constructor,
JS::HandleValueArray::subarray(argv, 0, argc), &constructedObj)) {
aRv.NoteJSContextException(cx);
return nullptr;
}
rval.setObject(*constructedObj);
RefPtr<mozilla::dom::AudioWorkletProcessor> rvalDecl;
static_assert(IsRefcounted<mozilla::dom::AudioWorkletProcessor>::value, "We can only store refcounted classes.");
{
// Our JSContext should be in the right global to do unwrapping in.
nsresult rv = UnwrapObject<prototypes::id::AudioWorkletProcessor, mozilla::dom::AudioWorkletProcessor>(rval, rvalDecl, cx);
if (NS_FAILED(rv)) {
cx.ThrowErrorMessage<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Return value of AudioWorkletProcessorConstructor", "AudioWorkletProcessor");
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
}
return rvalDecl.forget();
}
namespace AudioWorkletGlobalScope_Binding {
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<WorkletGlobalScope_Binding::NativeType>::value,
"Can't inherit from an interface with a different ownership model.");
MOZ_CAN_RUN_SCRIPT static bool
registerProcessor(JSContext* cx_, JS::Handle<JSObject*> obj, void* void_self, const JSJitMethodCallArgs& args)
{
BindingCallContext cx(cx_, "AudioWorkletGlobalScope.registerProcessor");
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AudioWorkletGlobalScope", "registerProcessor", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_METHOD) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AudioWorkletGlobalScope*>(void_self);
if (!args.requireAtLeast(cx, "AudioWorkletGlobalScope.registerProcessor", 2)) {
return false;
}
binding_detail::FakeString<char16_t> arg0;
if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
return false;
}
RootedCallback<OwningNonNull<binding_detail::FastAudioWorkletProcessorConstructor>> arg1(cx);
if (args[1].isObject()) {
if (JS::IsCallable(&args[1].toObject())) {
{ // scope for tempRoot and tempGlobalRoot if needed
arg1 = new binding_detail::FastAudioWorkletProcessorConstructor(&args[1].toObject(), JS::CurrentGlobalOrNull(cx));
}
} else {
cx.ThrowErrorMessage<MSG_NOT_CALLABLE>("Argument 2");
return false;
}
} else {
cx.ThrowErrorMessage<MSG_NOT_OBJECT>("Argument 2");
return false;
}
FastErrorResult rv;
// NOTE: This assert does NOT call the function.
static_assert(std::is_void_v<decltype(MOZ_KnownLive(self)->RegisterProcessor(cx, NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv))>, "Should be returning void here");
MOZ_KnownLive(self)->RegisterProcessor(cx, NonNullHelper(Constify(arg0)), MOZ_KnownLive(NonNullHelper(arg1)), rv);
if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx, "AudioWorkletGlobalScope.registerProcessor"))) {
return false;
}
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().setUndefined();
return true;
}
static const JSJitInfo registerProcessor_methodinfo = {
{ (JSJitGetterOp)registerProcessor },
{ prototypes::id::AudioWorkletGlobalScope },
{ PrototypeTraits<prototypes::id::AudioWorkletGlobalScope>::Depth },
JSJitInfo::Method,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
false, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_currentFrame(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AudioWorkletGlobalScope", "currentFrame", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AudioWorkletGlobalScope*>(void_self);
uint64_t result(MOZ_KnownLive(self)->CurrentFrame());
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().set(JS_NumberValue(double(result)));
return true;
}
static const JSJitInfo currentFrame_getterinfo = {
{ get_currentFrame },
{ prototypes::id::AudioWorkletGlobalScope },
{ PrototypeTraits<prototypes::id::AudioWorkletGlobalScope>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_currentTime(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AudioWorkletGlobalScope", "currentTime", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AudioWorkletGlobalScope*>(void_self);
double result(MOZ_KnownLive(self)->CurrentTime());
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().set(JS_NumberValue(double(result)));
return true;
}
static const JSJitInfo currentTime_getterinfo = {
{ get_currentTime },
{ prototypes::id::AudioWorkletGlobalScope },
{ PrototypeTraits<prototypes::id::AudioWorkletGlobalScope>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
MOZ_CAN_RUN_SCRIPT static bool
get_sampleRate(JSContext* cx, JS::Handle<JSObject*> obj, void* void_self, JSJitGetterCallArgs args)
{
AUTO_PROFILER_LABEL_DYNAMIC_FAST(
"AudioWorkletGlobalScope", "sampleRate", DOM, cx,
uint32_t(js::ProfilingStackFrame::Flags::STRING_TEMPLATE_GETTER) |
uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS));
auto* self = static_cast<mozilla::dom::AudioWorkletGlobalScope*>(void_self);
float result(MOZ_KnownLive(self)->SampleRate());
MOZ_ASSERT(!JS_IsExceptionPending(cx));
args.rval().set(JS_NumberValue(double(result)));
return true;
}
static const JSJitInfo sampleRate_getterinfo = {
{ get_sampleRate },
{ prototypes::id::AudioWorkletGlobalScope },
{ PrototypeTraits<prototypes::id::AudioWorkletGlobalScope>::Depth },
JSJitInfo::Getter,
JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
true, /* isInfallible. False in setters. */
false, /* isMovable. Not relevant for setters. */
false, /* isEliminatable. Not relevant for setters. */
false, /* isAlwaysInSlot. Only relevant for getters. */
false, /* isLazilyCachedInSlot. Only relevant for getters. */
false, /* isTypedMethod. Only relevant for methods. */
0 /* Reserved slot index, if we're stored in a slot, else 0. */
};
static void
_finalize(JS::GCContext* gcx, JSObject* obj)
{
mozilla::dom::AudioWorkletGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioWorkletGlobalScope>(obj);
if (self) {
JS::SetReservedSlot(obj, DOM_OBJECT_SLOT, JS::UndefinedValue());
ClearWrapper(self, self, obj);
mozilla::dom::FinalizeGlobal(gcx, obj);
if (size_t mallocBytes = BindingJSObjectMallocBytes(self)) {
JS::RemoveAssociatedMemory(obj, mallocBytes,
JS::MemoryUse::DOMBinding);
}
AddForDeferredFinalization<mozilla::dom::AudioWorkletGlobalScope>(self);
}
}
static size_t
_objectMoved(JSObject* obj, JSObject* old)
{
mozilla::dom::AudioWorkletGlobalScope* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::AudioWorkletGlobalScope>(obj);
if (self) {
UpdateWrapper(self, self, obj, old);
}
return 0;
}
static const JSFunctionSpec sMethods_specs[] = {
JS_FNSPEC("registerProcessor", (GenericMethod<MaybeGlobalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&registerProcessor_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
JS_FS_END
};
static const Prefable<const JSFunctionSpec> sMethods[] = {
{ nullptr, &sMethods_specs[0] },
{ nullptr, nullptr }
};
static const JSPropertySpec sAttributes_specs[] = {
JSPropertySpec::nativeAccessors("currentFrame", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &currentFrame_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("currentTime", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &currentTime_getterinfo, nullptr, nullptr),
JSPropertySpec::nativeAccessors("sampleRate", JSPROP_ENUMERATE, GenericGetter<MaybeGlobalThisPolicy, ThrowExceptions>, &sampleRate_getterinfo, nullptr, nullptr),
JS_PS_END
};
static const Prefable<const JSPropertySpec> sAttributes[] = {
{ nullptr, &sAttributes_specs[0] },
{ nullptr, nullptr }
};
static const NativePropertiesN<2> sNativeProperties = {
false, 0,
false, 0,
true, 0 /* sMethods */,
true, 1 /* sAttributes */,
false, 0,
false, 0,
false, 0,
-1,
0,
nullptr,
{
{ sMethods, nullptr },
{ sAttributes, nullptr }
}
};
static const DOMInterfaceInfo sInterfaceObjectInfo = {
{ ThrowingConstructor, &sEmptyNativePropertyHooks },
WorkletGlobalScope_Binding::GetConstructorObject,
prototypes::id::AudioWorkletGlobalScope,
PrototypeTraits<prototypes::id::AudioWorkletGlobalScope>::Depth,
true,
};
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
{
"AudioWorkletGlobalScopePrototype",
JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
JS_NULL_CLASS_OPS,
JS_NULL_CLASS_SPEC,
JS_NULL_CLASS_EXT,
JS_NULL_OBJECT_OPS
},
eGlobalInterfacePrototype,
prototypes::id::AudioWorkletGlobalScope,
PrototypeTraits<prototypes::id::AudioWorkletGlobalScope>::Depth,
&sEmptyNativePropertyHooks,
WorkletGlobalScope_Binding::GetProtoObject
};
static const JSClassOps sClassOps = {
nullptr, /* addProperty */
nullptr, /* delProperty */
nullptr, /* enumerate */
mozilla::dom::EnumerateGlobal, /* newEnumerate */
mozilla::dom::ResolveGlobal, /* resolve */
mozilla::dom::MayResolveGlobal, /* mayResolve */
_finalize, /* finalize */
nullptr, /* call */
nullptr, /* construct */
JS_GlobalObjectTraceHook, /* trace */
};
static const js::ClassExtension sClassExtension = {
_objectMoved /* objectMovedOp */
};
static const DOMJSClass sClass = {
{ "AudioWorkletGlobalScope",
JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_DOM_GLOBAL | JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(DOM_GLOBAL_SLOTS),
&sClassOps,
JS_NULL_CLASS_SPEC,
&sClassExtension,
JS_NULL_OBJECT_OPS
},
{ prototypes::id::WorkletGlobalScope, prototypes::id::AudioWorkletGlobalScope, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
std::is_base_of_v<nsISupports, mozilla::dom::AudioWorkletGlobalScope>,
&sEmptyNativePropertyHooks,
FindAssociatedGlobalForNative<mozilla::dom::AudioWorkletGlobalScope>::Get,
GetProtoObjectHandle,
GetCCParticipant<mozilla::dom::AudioWorkletGlobalScope>::Get(),
nullptr,
nullptr
};
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
"Must have the right minimal number of reserved slots.");
static_assert(JSCLASS_GLOBAL_APPLICATION_SLOTS >= 1,
"Must have enough reserved slots.");
bool
Wrap(JSContext* aCx, mozilla::dom::AudioWorkletGlobalScope* aObject, nsWrapperCache* aCache, JS::RealmOptions& aOptions, JSPrincipals* aPrincipal, JS::MutableHandle<JSObject*> aReflector)
{
static_assert(std::is_same_v<decltype(aObject), mozilla::dom::AudioWorkletGlobalScope*>);
MOZ_ASSERT(static_cast<mozilla::dom::WorkletGlobalScope*>(aObject) ==
reinterpret_cast<mozilla::dom::WorkletGlobalScope*>(aObject),
"Multiple inheritance for mozilla::dom::WorkletGlobalScope is broken.");
MOZ_ASSERT(ToSupportsIsCorrect(aObject));
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
if (!CreateGlobal<mozilla::dom::AudioWorkletGlobalScope, GetProtoObjectHandle>(aCx,
aObject,
aCache,
sClass.ToJSClass(),
aOptions,
aPrincipal,
aReflector)) {
aCache->ReleaseWrapper(aObject);
aCache->ClearWrapper();
return false;
}
// aReflector is a new global, so has a new realm. Enter it
// before doing anything with it.
JSAutoRealm ar(aCx, aReflector);
if (!DefineProperties(aCx, aReflector, sNativeProperties.Upcast(), nullptr)) {
aCache->ReleaseWrapper(aObject);
aCache->ClearWrapper();
return false;
}
return true;
}
void
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
{
JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::AudioWorkletGlobalScope);
JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AudioWorkletGlobalScope);
JS::Handle<JSObject*> parentProto(WorkletGlobalScope_Binding::GetProtoObjectHandle(aCx));
if (!parentProto) {
return;
}
JS::Handle<JSObject*> constructorProto(WorkletGlobalScope_Binding::GetConstructorObjectHandle(aCx));
if (!constructorProto) {
return;
}
dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
&sPrototypeClass, protoCache,
constructorProto, &sInterfaceObjectInfo, 0, false, Span<const LegacyFactoryFunction, 0>{},
interfaceCache,
sNativeProperties.Upcast(),
nullptr,
"AudioWorkletGlobalScope", aDefineOnGlobal,
nullptr,
true,
nullptr);
JS::AssertObjectIsNotGray(*protoCache);
JS::Handle<JSObject*> proto = JS::Handle<JSObject*>::fromMarkedLocation(protoCache->address());
if (!proto) {
*protoCache = nullptr;
if (interfaceCache) {
*interfaceCache = nullptr;
}
return;
}
{
bool succeeded;
if (!JS_SetImmutablePrototype(aCx, proto, &succeeded)) {
*protoCache = nullptr;
if (interfaceCache) {
*interfaceCache = nullptr;
}
return;
}
MOZ_ASSERT(succeeded,
"making a fresh prototype object's [[Prototype]] "
"immutable can internally fail, but it should "
"never be unsuccessful");
}
}
JSObject*
GetConstructorObject(JSContext* aCx)
{
return GetConstructorObjectHandle(aCx);
}
} // namespace AudioWorkletGlobalScope_Binding
} // namespace mozilla::dom