v8/test/mjsunit/harmony/modules-import-16.js
Sathya Gunasekaran f6e20fcbba [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: Adam Klein <adamk@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47352}
2017-08-14 23:21:49 +00:00

37 lines
954 B
JavaScript

// 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);