Commit f6e20fcb authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[modules] Fix dynamic import in eval

In the case of a function constructor or eval, we create a new script
object which doesn't have a script name. In this case, we traverse
upwards on the list of SFI's through script->eval_from_shared() to get
the outermost script that was not an eval script and get the script
name from that script.

Bug: chromium:746909, v8:6683, v8:5785
Change-Id: I430459f632a0e3b18fc3111a5cf1c00cedb9f520
Reviewed-on: https://chromium-review.googlesource.com/606701
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47352}
parent 13a990aa
......@@ -18,8 +18,17 @@ RUNTIME_FUNCTION(Runtime_DynamicImportCall) {
CONVERT_ARG_HANDLE_CHECKED(Object, specifier, 1);
Handle<Script> script(Script::cast(function->shared()->script()));
Handle<String> source_url(String::cast(script->name()));
while (script->eval_from_shared()->IsSharedFunctionInfo()) {
script = handle(
Script::cast(
SharedFunctionInfo::cast(script->eval_from_shared())->script()),
isolate);
}
// TODO(gsathya): Check if script name is a string before casting
// and return undefined if not.
Handle<String> source_url(String::cast(script->name()));
RETURN_RESULT_OR_FAILURE(
isolate,
isolate->RunHostImportModuleDynamicallyCallback(source_url, specifier));
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --harmony-dynamic-import
var ran = false;
var x;
var body = "import('modules-skip-1.js').then(ns => { x = ns.life();" +
" ran = true;} ).catch(err => %AbortJS(err))"
var func = new Function(body);
func();
%RunMicrotasks();
assertEquals(42, x);
assertTrue(ran);
var ran = false;
var body = "import('modules-skip-1.js').then(ns => { x = ns.life();" +
" ran = true;} ).catch(err => %AbortJS(err))"
eval("var func = new Function(body); func();");
%RunMicrotasks();
assertEquals(42, x);
assertTrue(ran);
var ran = false;
var body = "eval(import('modules-skip-1.js').then(ns => { x = ns.life();" +
" ran = true;} ).catch(err => %AbortJS(err)))"
var func = new Function(body);
func();
%RunMicrotasks();
assertEquals(42, x);
assertTrue(ran);
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-dynamic-import
eval(`import('modules-skip-2.js');`);
eval(`eval(import('modules-skip-2.js'));`);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment