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 "bindings/core/v8/ScriptModule.h" |
| 6 |
| 7 #include "bindings/core/v8/V8Binding.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module) |
| 12 : m_module(SharedPersistent<v8::Module>::create(module, isolate)) {} |
| 13 |
| 14 ScriptModule::~ScriptModule() {} |
| 15 |
| 16 ScriptModule ScriptModule::compile(v8::Isolate* isolate, |
| 17 const String& source, |
| 18 const String& fileName) { |
| 19 v8::TryCatch tryCatch(isolate); |
| 20 tryCatch.SetVerbose(true); |
| 21 v8::Local<v8::Module> module; |
| 22 if (!v8Call(V8ScriptRunner::compileModule(isolate, source, fileName), module, |
| 23 tryCatch)) { |
| 24 // TODO(adamk): Signal failure somehow. |
| 25 return ScriptModule(isolate, module); |
| 26 } |
| 27 return ScriptModule(isolate, module); |
| 28 } |
| 29 |
| 30 v8::MaybeLocal<v8::Module> dummyCallback(v8::Local<v8::Context> context, |
| 31 v8::Local<v8::String> specifier, |
| 32 v8::Local<v8::Module> referrer) { |
| 33 return v8::MaybeLocal<v8::Module>(); |
| 34 } |
| 35 |
| 36 bool ScriptModule::instantiate(ScriptState* scriptState) { |
| 37 DCHECK(!isNull()); |
| 38 v8::Local<v8::Context> context = scriptState->context(); |
| 39 // TODO(adamk): pass in a real callback. |
| 40 return m_module->newLocal(scriptState->isolate()) |
| 41 ->Instantiate(context, &dummyCallback); |
| 42 } |
| 43 |
| 44 void ScriptModule::evaluate(ScriptState* scriptState) { |
| 45 v8::Isolate* isolate = scriptState->isolate(); |
| 46 v8::TryCatch tryCatch(isolate); |
| 47 tryCatch.SetVerbose(true); |
| 48 v8::Local<v8::Value> result; |
| 49 if (!v8Call(V8ScriptRunner::evaluateModule(m_module->newLocal(isolate), |
| 50 scriptState->context(), isolate), |
| 51 result, tryCatch)) { |
| 52 // TODO(adamk): report error |
| 53 } |
| 54 } |
| 55 |
| 56 } // namespace blink |
OLD | NEW |