Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3d6df80996bcc208c710f61b7333773b70e02501 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2016 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 "bindings/core/v8/ScriptModule.h" |
| + |
| +#include "bindings/core/v8/V8Binding.h" |
| + |
| +namespace blink { |
| + |
| +ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) |
| + : m_module(SharedPersistent<v8::Module>::create(module, isolate)) {} |
| + |
| +ScriptModule::~ScriptModule() {} |
| + |
| +// TODO(adamk): This method should either live in V8ScriptRunner or call out |
| +// to code there. |
| +ScriptModule ScriptModule::compile(v8::Isolate* isolate, |
| + const String& source, |
| + const String& fileName) { |
| + // TODO(adamk): Pass more info into ScriptOrigin. |
| + v8::ScriptOrigin origin(v8String(isolate, fileName)); |
| + v8::ScriptCompiler::Source scriptSource(v8String(isolate, source), origin); |
| + v8::TryCatch tryCatch(isolate); |
| + tryCatch.SetVerbose(true); |
| + v8::Local<v8::Module> module; |
| + if (!v8Call(v8::ScriptCompiler::CompileModule(isolate, &scriptSource), module, |
|
haraken
2017/01/11 02:21:35
I want to create a helper function in V8ScriptRunn
adamk
2017/01/11 18:27:30
Ok added a helper to V8ScriptRunner with some basi
|
| + tryCatch)) { |
| + // TODO(adamk): Signal failure somehow. |
| + return ScriptModule(isolate, module); |
| + } |
| + return ScriptModule(isolate, module); |
| +} |
| + |
| +v8::MaybeLocal<v8::Module> dummyCallback(v8::Local<v8::Context> context, |
| + v8::Local<v8::String> specifier, |
| + v8::Local<v8::Module> referrer) { |
| + return v8::MaybeLocal<v8::Module>(); |
| +} |
| + |
| +bool ScriptModule::instantiate(ScriptState* scriptState) { |
| + DCHECK(!isNull()); |
| + v8::Local<v8::Context> context = scriptState->context(); |
| + // TODO(adamk): pass in a real callback. |
| + return m_module->newLocal(scriptState->isolate()) |
| + ->Instantiate(context, &dummyCallback); |
|
haraken
2017/01/11 02:21:35
Can we make V8 accept a nullptr as a callback?
adamk
2017/01/11 18:27:30
There's not a good use for such a thing in the mod
|
| +} |
| + |
| +// TODO(adamk): This method should either live in V8ScriptRunner or call out |
| +// to code there. |
|
haraken
2017/01/11 02:21:35
Yes, I'd prefer moving the Evaluate call to V8Scri
adamk
2017/01/11 18:27:30
Done
|
| +void ScriptModule::evaluate(ScriptState* scriptState) { |
| + v8::TryCatch tryCatch(scriptState->isolate()); |
| + tryCatch.SetVerbose(true); |
| + v8::Local<v8::Value> result; |
| + if (!v8Call(m_module->newLocal(scriptState->isolate()) |
| + ->Evaluate(scriptState->context()), |
| + result, tryCatch)) { |
| + // TODO(adamk): report error |
| + } |
| +} |
| + |
| +} // namespace blink |