Debian Codegraph @

js/src/jit-test/tests/modules/module-declaration-instantiation.js

raw
1 // Exercise ModuleDeclarationInstantiation() operation.
2
3 function testModuleEnvironment(module, expected) {
4 var actual = getModuleEnvironmentNames(module).sort();
5 assertEq(actual.length, expected.length);
6 for (var i = 0; i < actual.length; i++) {
7 assertEq(actual[i], expected[i]);
8 }
9 }
10
11 // Check the environment of an empty module.
12 let m = parseModule("");
13 moduleLink(m);
14 testModuleEnvironment(m, []);
15
16 let a = registerModule('a', parseModule("var x = 1; export { x };"));
17 let b = registerModule('b', parseModule("import { x as y } from 'a';"));
18
19 moduleLink(a);
20 moduleLink(b);
21
22 testModuleEnvironment(a, ['x']);
23 testModuleEnvironment(b, ['y']);
24
25 // Function bindings are initialized as well as instantiated.
26 let c = parseModule(`function a(x) { return x; }
27 function b(x) { return x + 1; }
28 function c(x) { return x + 2; }
29 function d(x) { return x + 3; }`);
30 const names = ['a', 'b', 'c', 'd'];
31 testModuleEnvironment(c, names);
32 names.forEach((n) => assertEq(typeof getModuleEnvironmentValue(c, n), "undefined"));
33 moduleLink(c);
34 for (let i = 0; i < names.length; i++) {
35 let f = getModuleEnvironmentValue(c, names[i]);
36 assertEq(f(21), 21 + i);
37 }