Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(856)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp

Issue 2727733002: Implement AudioWorkletProcessor interface (Closed)
Patch Set: Addressing feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
index 33abafe5dd2497fded72ea08c2b587cd44bcadeb..d2ee992f95067e2a1658899c025801a4715f2f0a 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
@@ -4,6 +4,10 @@
#include "modules/webaudio/AudioWorkletGlobalScope.h"
+#include "bindings/core/v8/V8BindingMacros.h"
+#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
+#include "core/dom/ExceptionCode.h"
+#include "modules/webaudio/AudioWorkletProcessorDefinition.h"
#include "platform/weborigin/SecurityOrigin.h"
namespace blink {
@@ -32,4 +36,92 @@ AudioWorkletGlobalScope::AudioWorkletGlobalScope(
AudioWorkletGlobalScope::~AudioWorkletGlobalScope() {}
+void AudioWorkletGlobalScope::dispose() {
+ m_processorDefinitionMap.clear();
+ ThreadedWorkletGlobalScope::dispose();
+}
+
+void AudioWorkletGlobalScope::registerProcessor(
+ ScriptState* scriptState,
+ const String& name,
+ const ScriptValue& constructor,
+ ExceptionState& exceptionState) {
+ DCHECK(isContextThread());
+
+ if (m_processorDefinitionMap.contains(name)) {
+ exceptionState.throwDOMException(
+ NotSupportedError,
+ "A class with name:'" + name + "' is already registered.");
+ return;
+ }
+
+ if (name.isEmpty()) {
+ exceptionState.throwTypeError("The empty string is not a valid name.");
+ return;
+ }
+
+ v8::Isolate* isolate = scriptState->isolate();
+ v8::Local<v8::Context> context = scriptState->context();
+
+ DCHECK(constructor.v8Value()->IsFunction());
+
+ v8::Local<v8::Function> constructorLocal =
+ v8::Local<v8::Function>::Cast(constructor.v8Value());
+
+ v8::Local<v8::Value> prototypeValue;
+ if (!v8Call(constructorLocal->Get(context, v8String(isolate, "prototype")),
+ prototypeValue))
+ return;
+
+ if (isUndefinedOrNull(prototypeValue)) {
+ exceptionState.throwTypeError(
+ "The 'prototype' object on the class does not exist.");
+ return;
+ }
+
+ if (!prototypeValue->IsObject()) {
+ exceptionState.throwTypeError(
+ "The 'prototype' property on the class is not an object.");
+ return;
+ }
+
+ v8::Local<v8::Object> prototype = v8::Local<v8::Object>::Cast(prototypeValue);
+
+ v8::Local<v8::Value> processValue;
+ if (!v8Call(prototype->Get(context, v8String(isolate, "process")),
haraken 2017/03/08 09:57:19 It looks a bit nasty to look up a prototype object
hongchan 2017/03/08 19:38:46 Yes, this is how it is specced.
+ processValue))
+ return;
+
+ if (isUndefinedOrNull(processValue)) {
+ exceptionState.throwTypeError(
+ "The 'process' function on the prototype does not exist.");
+ return;
+ }
+
+ if (!processValue->IsFunction()) {
+ exceptionState.throwTypeError(
+ "The 'process' property on the prototype is not a function.");
+ return;
+ }
+
+ v8::Local<v8::Function> processLocal =
+ v8::Local<v8::Function>::Cast(processValue);
+
+ AudioWorkletProcessorDefinition* definition =
+ AudioWorkletProcessorDefinition::create(scriptState, constructorLocal,
+ processLocal);
+
+ m_processorDefinitionMap.set(name, definition);
+}
+
+AudioWorkletProcessorDefinition* AudioWorkletGlobalScope::findDefinition(
+ const String& name) {
+ return m_processorDefinitionMap.at(name);
+}
+
+DEFINE_TRACE(AudioWorkletGlobalScope) {
+ visitor->trace(m_processorDefinitionMap);
+ ThreadedWorkletGlobalScope::trace(visitor);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698