Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp

Issue 2785983002: [ES6 modules] ScriptModule::instantiate with resolveModule cb and error handling (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..15a35ac46f2451c141b0b6b63ba8750009aded46 100644
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptModule.cpp
@@ -5,6 +5,8 @@
#include "bindings/core/v8/ScriptModule.h"
#include "bindings/core/v8/V8Binding.h"
+#include "core/dom/Modulator.h"
+#include "core/dom/ScriptModuleResolver.h"
namespace blink {
@@ -33,12 +35,40 @@ v8::MaybeLocal<v8::Module> dummyCallback(v8::Local<v8::Context> context,
return v8::MaybeLocal<v8::Module>();
}
-bool ScriptModule::instantiate(ScriptState* scriptState) {
+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));
+}
+
+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());
+ }
+ return ScriptValue();
}
void ScriptModule::evaluate(ScriptState* scriptState) {

Powered by Google App Engine
This is Rietveld 408576698