summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/dynamic-import-module.js
blob: fa19b743031c9612f4be6ba33d10b7a1f7621b39 (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
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 direct 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");`)();