| 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..b606d4f464160a7c04311d1decec0da4c841c3ea
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletProcessorDefinition.cpp
|
| @@ -0,0 +1,73 @@
|
| +// 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_constructor(scriptState->isolate(), constructor),
|
| + m_process(scriptState->isolate(), process) {}
|
| +
|
| +AudioWorkletProcessorDefinition::~AudioWorkletProcessorDefinition() {}
|
| +
|
| +void AudioWorkletProcessorDefinition::createInstance(
|
| + ScopedPersistent<v8::Object>& instance) {
|
| + v8::Isolate* isolate = m_scriptState->isolate();
|
| + v8::Local<v8::Object> instanceLocal;
|
| + if (!V8ObjectConstructor::newInstance(isolate,
|
| + m_constructor.newLocal(isolate))
|
| + .ToLocal(&instanceLocal)) {
|
| + instance.clear();
|
| + return;
|
| + }
|
| +
|
| + instance.set(isolate, instanceLocal);
|
| +}
|
| +
|
| +bool AudioWorkletProcessorDefinition::process(
|
| + ScopedPersistent<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.newLocal(isolate), WTF_ARRAY_LENGTH(argv), argv, isolate);
|
| +
|
| + if (block.HasCaught()) {
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|