| 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..6c97d11f87a39cba0c6b902029db87f419743a31
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp
|
| @@ -0,0 +1,58 @@
|
| +// 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() {}
|
| +
|
| +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,
|
| + 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);
|
| +}
|
| +
|
| +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
|
|
|