Chromium Code Reviews| 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_scriptState(scriptState), | |
| 30 m_constructor(scriptState->isolate(), constructor), | |
| 31 m_process(scriptState->isolate(), process) {} | |
| 32 | |
| 33 AudioWorkletProcessorDefinition::~AudioWorkletProcessorDefinition() {} | |
| 34 | |
| 35 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
| |
| 36 v8::Isolate* isolate = m_scriptState->isolate(); | |
| 37 v8::Local<v8::Object> instance; | |
| 38 if (!V8ObjectConstructor::newInstance(isolate, | |
| 39 m_constructor.newLocal(isolate)) | |
| 40 .ToLocal(&instance)) { | |
| 41 return v8::Local<v8::Object>(); | |
| 42 } | |
| 43 | |
| 44 return instance->Clone(); | |
| 45 } | |
| 46 | |
| 47 bool AudioWorkletProcessorDefinition::process(v8::Local<v8::Object> instance, | |
| 48 AudioBuffer* inputBuffer, | |
| 49 AudioBuffer* outputBuffer) { | |
| 50 ScriptState::Scope scope(m_scriptState.get()); | |
| 51 | |
| 52 v8::Isolate* isolate = m_scriptState->isolate(); | |
| 53 v8::Local<v8::Value> argv[] = { | |
| 54 ToV8(inputBuffer, m_scriptState->context()->Global(), isolate), | |
| 55 ToV8(outputBuffer, m_scriptState->context()->Global(), isolate)}; | |
| 56 | |
| 57 v8::TryCatch block(isolate); | |
| 58 block.SetVerbose(true); | |
| 59 | |
| 60 V8ScriptRunner::callFunction(m_process.newLocal(isolate), | |
| 61 m_scriptState->getExecutionContext(), instance, | |
| 62 WTF_ARRAY_LENGTH(argv), argv, isolate); | |
| 63 | |
| 64 if (block.HasCaught()) { | |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 } // namespace blink | |
| OLD | NEW |