| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/webaudio/AudioWorkletProcessorDefinition.h" |
| 6 |
| 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/ToV8.h" |
| 9 #include "bindings/core/v8/V8Binding.h" |
| 10 #include "bindings/core/v8/V8BindingMacros.h" |
| 11 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 12 #include "core/dom/ExecutionContext.h" |
| 13 #include "modules/webaudio/AudioBuffer.h" |
| 14 #include "wtf/PtrUtil.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 AudioWorkletProcessorDefinition* AudioWorkletProcessorDefinition::create( |
| 19 ScriptState* scriptState, |
| 20 v8::Local<v8::Function> constructor, |
| 21 v8::Local<v8::Function> process) { |
| 22 return new AudioWorkletProcessorDefinition(scriptState, constructor, process); |
| 23 } |
| 24 |
| 25 AudioWorkletProcessorDefinition::AudioWorkletProcessorDefinition( |
| 26 ScriptState* scriptState, |
| 27 v8::Local<v8::Function> constructor, |
| 28 v8::Local<v8::Function> process) |
| 29 : m_constructor(scriptState->isolate(), constructor), |
| 30 m_process(scriptState->isolate(), process) {} |
| 31 |
| 32 AudioWorkletProcessorDefinition::~AudioWorkletProcessorDefinition() {} |
| 33 |
| 34 void AudioWorkletProcessorDefinition::createInstance( |
| 35 ScopedPersistent<v8::Object>& instance) { |
| 36 v8::Isolate* isolate = m_scriptState->isolate(); |
| 37 v8::Local<v8::Object> instanceLocal; |
| 38 if (!V8ObjectConstructor::newInstance(isolate, |
| 39 m_constructor.newLocal(isolate)) |
| 40 .ToLocal(&instanceLocal)) { |
| 41 instance.clear(); |
| 42 return; |
| 43 } |
| 44 |
| 45 instance.set(isolate, instanceLocal); |
| 46 } |
| 47 |
| 48 bool AudioWorkletProcessorDefinition::process( |
| 49 ScopedPersistent<v8::Object>& instance, |
| 50 AudioBuffer* inputBuffer, |
| 51 AudioBuffer* outputBuffer) { |
| 52 ScriptState::Scope scope(m_scriptState.get()); |
| 53 v8::Isolate* isolate = m_scriptState->isolate(); |
| 54 |
| 55 v8::Local<v8::Value> argv[] = { |
| 56 ToV8(inputBuffer, m_scriptState->context()->Global(), isolate), |
| 57 ToV8(outputBuffer, m_scriptState->context()->Global(), isolate)}; |
| 58 |
| 59 v8::TryCatch block(isolate); |
| 60 block.SetVerbose(true); |
| 61 |
| 62 V8ScriptRunner::callFunction( |
| 63 m_process.newLocal(isolate), m_scriptState->getExecutionContext(), |
| 64 instance.newLocal(isolate), WTF_ARRAY_LENGTH(argv), argv, isolate); |
| 65 |
| 66 if (block.HasCaught()) { |
| 67 return false; |
| 68 } |
| 69 |
| 70 return true; |
| 71 } |
| 72 |
| 73 } // namespace blink |
| OLD | NEW |