summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/dynamic-import-script.js
blob: e6986a42ecaab00ef1f294b4344835e4774fbdc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function testImport(path, name, value) {
    let result = null;
    let error = null;
    let promise = import(path);
    promise.then((ns) => {
        result = ns;
    }).catch((e) => {
        error = e;
    });

    drainJobQueue();
    assertEq(error, null);
    assertEq(result[name], value);
}

// Resolved via module load path.
testImport("module1.js", "a", 1);

// Relative path resolved relative to this script.
testImport("../../modules/module1a.js", "a", 2);

// Import inside function.
function f() {
    testImport("../../modules/module2.js", "b", 2);
}
f();

// Import inside eval.
eval(`testImport("../../modules/module3.js", "c", 3)`);

// Import inside indirect eval.
const indirect = eval;
const defineTestFunc = testImport.toString();
indirect(defineTestFunc + `testImport("../../modules/module3.js");`);

// Import inside dynamic function.
Function(defineTestFunc + `testImport("../../modules/module3.js");`)();

// Import in eval in promise handler.
let ran = false;
Promise
    .resolve(`import("../../modules/module3.js").then(() => { ran = true; })`)
    .then(eval)
drainJobQueue();
assertEq(ran, true);