Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/AudioWorkletProcessorDefinition.cpp |
| diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletProcessorDefinition.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletProcessorDefinition.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14967acd472b2db0f4ac098805550a08ce5e3b63 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletProcessorDefinition.cpp |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/webaudio/AudioWorkletProcessorDefinition.h" |
| + |
| +#include "bindings/core/v8/ScriptState.h" |
| +#include "bindings/core/v8/ToV8.h" |
| +#include "bindings/core/v8/V8Binding.h" |
| +#include "bindings/core/v8/V8BindingMacros.h" |
| +#include "bindings/core/v8/V8ObjectConstructor.h" |
| +#include "core/dom/ExecutionContext.h" |
| +#include "modules/webaudio/AudioBuffer.h" |
| +#include "wtf/PtrUtil.h" |
| + |
| +namespace blink { |
| + |
| +AudioWorkletProcessorDefinition* AudioWorkletProcessorDefinition::create( |
| + ScriptState* scriptState, |
| + v8::Local<v8::Function> constructor, |
| + v8::Local<v8::Function> process) { |
| + return new AudioWorkletProcessorDefinition(scriptState, constructor, process); |
| +} |
| + |
| +AudioWorkletProcessorDefinition::AudioWorkletProcessorDefinition( |
| + ScriptState* scriptState, |
| + v8::Local<v8::Function> constructor, |
| + v8::Local<v8::Function> process) |
| + : m_scriptState(scriptState), |
| + m_constructor(scriptState->isolate(), constructor), |
| + m_process(scriptState->isolate(), process) {} |
| + |
| +AudioWorkletProcessorDefinition::~AudioWorkletProcessorDefinition() {} |
| + |
| +v8::Local<v8::Object> AudioWorkletProcessorDefinition::createInstance() { |
|
nhiroki
2017/03/06 10:08:44
Ditto: Can you add thread checks if possible?
hongchan
2017/03/06 20:06:12
Hmm. AudioWorkletGlobalScope and this definition o
|
| + v8::Isolate* isolate = m_scriptState->isolate(); |
| + v8::Local<v8::Object> instance; |
| + if (!V8ObjectConstructor::newInstance(isolate, |
| + m_constructor.newLocal(isolate)) |
| + .ToLocal(&instance)) { |
| + return v8::Local<v8::Object>(); |
| + } |
| + |
| + return instance->Clone(); |
| +} |
| + |
| +bool AudioWorkletProcessorDefinition::process(v8::Local<v8::Object> instance, |
| + AudioBuffer* inputBuffer, |
| + AudioBuffer* outputBuffer) { |
| + ScriptState::Scope scope(m_scriptState.get()); |
| + |
| + v8::Isolate* isolate = m_scriptState->isolate(); |
| + v8::Local<v8::Value> argv[] = { |
| + ToV8(inputBuffer, m_scriptState->context()->Global(), isolate), |
| + ToV8(outputBuffer, m_scriptState->context()->Global(), isolate)}; |
| + |
| + v8::TryCatch block(isolate); |
| + block.SetVerbose(true); |
| + |
| + V8ScriptRunner::callFunction(m_process.newLocal(isolate), |
| + m_scriptState->getExecutionContext(), instance, |
| + WTF_ARRAY_LENGTH(argv), argv, isolate); |
| + |
| + if (block.HasCaught()) { |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace blink |