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

Unified Diff: src/runtime/runtime-module.cc

Issue 2703563002: [ESNext] Implement DynamicImportCall (Closed)
Patch Set: simplify error handling 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: src/runtime/runtime-module.cc
diff --git a/src/runtime/runtime-module.cc b/src/runtime/runtime-module.cc
index f36a09b410bf00a8658882f021f0918bd6aff2c3..92bbed4f1e22d7a632306fb929e31d4a4344ebd0 100644
--- a/src/runtime/runtime-module.cc
+++ b/src/runtime/runtime-module.cc
@@ -13,9 +13,39 @@ namespace internal {
RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
HandleScope scope(isolate);
- DCHECK_EQ(1, args.length());
- // TODO(gsathya): Implement ImportCall.
- return isolate->heap()->undefined_value();
+ DCHECK_EQ(2, args.length());
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, specifier, 1);
+
+ Handle<JSPromise> promise = isolate->factory()->NewJSPromise();
+
+ Handle<String> specifier_str;
+ v8::TryCatch catcher(reinterpret_cast<v8::Isolate*>(isolate));
+ MaybeHandle<String> maybe_specifier = Object::ToString(isolate, specifier);
+ if (!maybe_specifier.ToHandle(&specifier_str)) {
+ DCHECK(catcher.HasCaught());
+ MaybeHandle<Object> reason = v8::Utils::OpenHandle(*catcher.Exception());
+ isolate->OptionalRescheduleException(true);
+
+ Handle<Object> argv[] = {promise, reason.ToHandleChecked(),
+ isolate->factory()->ToBoolean(false)};
+
+ RETURN_FAILURE_ON_EXCEPTION(
+ isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
+ isolate->factory()->undefined_value(),
+ arraysize(argv), argv))
+ return *promise;
+ }
neis 2017/03/17 10:36:32 Please add DCHECK(!catcher.HasCaught()) here.
gsathya 2017/03/17 21:47:59 Done.
+
neis 2017/03/17 10:36:32 This comment is about the spec, not your implement
gsathya 2017/03/17 21:47:59 Yeah, I found this weird too.
+ Handle<String> source_url = isolate->factory()->empty_string();
+ Handle<Script> script(Script::cast(function->shared()->script()));
+ if (script->name()->IsString()) {
+ source_url = handle(String::cast(script->name()), isolate);
+ }
+
neis 2017/03/17 10:36:32 Do we understand in which situations the name is n
gsathya 2017/03/17 21:48:00 I had this because I thought the D8 shell didn't p
+ isolate->RunHostImportModuleDynamicallyCallback(source_url, specifier_str,
+ promise);
+ return *promise;
}
RUNTIME_FUNCTION(Runtime_GetModuleNamespace) {

Powered by Google App Engine
This is Rietveld 408576698