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

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

Issue 2727733002: Implement AudioWorkletProcessor interface (Closed)
Patch Set: Added AudioWorkletProcessor and AudioWorkletProcessorDefinition classes Created 3 years, 10 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..d87a6db448636de73905359313fa4f0843a75f43 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,88 @@ AudioWorkletGlobalScope::AudioWorkletGlobalScope(
AudioWorkletGlobalScope::~AudioWorkletGlobalScope() {}
+void AudioWorkletGlobalScope::dispose() {
+ m_processorDefinitionMap.clear();
+ ThreadedWorkletGlobalScope::dispose();
+}
+
+void AudioWorkletGlobalScope::registerProcessor(
+ const String& name,
+ const ScriptValue& ctor,
+ ExceptionState& exceptionState) {
nhiroki 2017/03/06 10:08:44 I'd recommend that threaded objects have thread ch
hongchan 2017/03/06 20:06:11 Good point. I do not have the thread for this code
+ 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 = scriptController()->getScriptState()->isolate();
+ v8::Local<v8::Context> context = scriptController()->context();
haraken 2017/03/06 11:51:11 If you pass in [ScriptState] to registerProcessor
hongchan 2017/03/06 20:06:11 Done.
+
+ DCHECK(ctor.v8Value()->IsFunction());
+
+ v8::Local<v8::Function> constructor =
+ v8::Local<v8::Function>::Cast(ctor.v8Value());
+
+ v8::Local<v8::Value> prototypeValue;
+ if (!v8Call(constructor->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")),
+ 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> process = v8::Local<v8::Function>::Cast(processValue);
+
+ AudioWorkletProcessorDefinition* definition =
+ AudioWorkletProcessorDefinition::create(
+ scriptController()->getScriptState(), constructor, process);
+
+ 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