| 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
|
| index 3642e50d29e06bf845e1c80fa82a44cdbdc378f8..f3a9cee8cd144787deb2ce4cfb4f0232fb6307e6 100644
|
| --- a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp
|
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp
|
| @@ -5,11 +5,17 @@
|
| #include "bindings/core/v8/ScriptModule.h"
|
|
|
| #include "bindings/core/v8/V8Binding.h"
|
| +#include "bindings/core/v8/V8PerContextData.h"
|
| +#include "core/dom/DOMException.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| +#include "core/dom/Modulator.h"
|
| +#include "core/dom/ScriptModuleResolver.h"
|
|
|
| namespace blink {
|
|
|
| ScriptModule::ScriptModule(v8::Isolate* isolate, v8::Local<v8::Module> module)
|
| - : m_module(SharedPersistent<v8::Module>::create(module, isolate)) {}
|
| + : m_module(SharedPersistent<v8::Module>::create(module, isolate)),
|
| + m_identityHash(static_cast<unsigned>(module->GetIdentityHash())) {}
|
|
|
| ScriptModule::~ScriptModule() {}
|
|
|
| @@ -21,24 +27,47 @@ ScriptModule ScriptModule::compile(v8::Isolate* isolate,
|
| v8::Local<v8::Module> module;
|
| if (!v8Call(V8ScriptRunner::compileModule(isolate, source, fileName), module,
|
| tryCatch)) {
|
| - // TODO(adamk): Signal failure somehow.
|
| - return ScriptModule(isolate, module);
|
| + return ScriptModule();
|
| }
|
| 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>();
|
| +v8::MaybeLocal<v8::Module> ScriptModule::resolveModuleCallback(
|
| + v8::Local<v8::Context> context,
|
| + v8::Local<v8::String> specifier,
|
| + v8::Local<v8::Module> referrer) {
|
| + v8::Isolate* isolate = context->GetIsolate();
|
| + Modulator* modulator = V8PerContextData::from(context)->modulator();
|
| + DCHECK(modulator);
|
| +
|
| + ScriptModule referrerRecord(isolate, referrer);
|
| + ExceptionState exceptionState(isolate, ExceptionState::ExecutionContext,
|
| + "ScriptModule", "resolveModuleCallback");
|
| + ScriptModule resolved = modulator->scriptModuleResolver()->resolve(
|
| + toCoreStringWithNullCheck(specifier), referrerRecord,
|
| + exceptionState);
|
| + if (resolved.isNull()) {
|
| + DCHECK(exceptionState.hadException());
|
| + return v8::MaybeLocal<v8::Module>();
|
| + }
|
| +
|
| + return v8::MaybeLocal<v8::Module>(resolved.m_module->newLocal(isolate));
|
| }
|
|
|
| -bool ScriptModule::instantiate(ScriptState* scriptState) {
|
| +ScriptValue ScriptModule::instantiate(ScriptState* scriptState) {
|
| + v8::Isolate* isolate = scriptState->isolate();
|
| + v8::TryCatch tryCatch(isolate);
|
| +
|
| 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);
|
| + bool success = m_module->newLocal(scriptState->isolate())
|
| + ->Instantiate(context, &resolveModuleCallback);
|
| + if (!success) {
|
| + DCHECK(tryCatch.HasCaught());
|
| + return ScriptValue(scriptState, tryCatch.Exception());
|
| + }
|
| + // DCHECK(!tryCatch.HasCaught());
|
| + return ScriptValue();
|
| }
|
|
|
| void ScriptModule::evaluate(ScriptState* scriptState) {
|
| @@ -53,4 +82,22 @@ void ScriptModule::evaluate(ScriptState* scriptState) {
|
| }
|
| }
|
|
|
| +Vector<String> ScriptModule::moduleRequests(ScriptState* scriptState) {
|
| + if (isNull())
|
| + return Vector<String>();
|
| +
|
| + v8::Local<v8::Module> module = m_module->newLocal(scriptState->isolate());
|
| +
|
| + Vector<String> ret;
|
| +
|
| + int length = module->GetModuleRequestsLength();
|
| + ret.reserveInitialCapacity(length);
|
| + for (int i = 0; i < length; ++i) {
|
| + v8::Local<v8::String> v8Name = module->GetModuleRequest(i);
|
| + String name = toCoreString(v8Name);
|
| + ret.push_back(name);
|
| + }
|
| + return ret;
|
| +}
|
| +
|
| } // namespace blink
|
|
|