summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/module-declaration-instantiation.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit-test/tests/modules/module-declaration-instantiation.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/modules/module-declaration-instantiation.js')
-rw-r--r--js/src/jit-test/tests/modules/module-declaration-instantiation.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/modules/module-declaration-instantiation.js b/js/src/jit-test/tests/modules/module-declaration-instantiation.js
new file mode 100644
index 0000000000..8fb557d58a
--- /dev/null
+++ b/js/src/jit-test/tests/modules/module-declaration-instantiation.js
@@ -0,0 +1,37 @@
+// Exercise ModuleDeclarationInstantiation() operation.
+
+function testModuleEnvironment(module, expected) {
+ var actual = getModuleEnvironmentNames(module).sort();
+ assertEq(actual.length, expected.length);
+ for (var i = 0; i < actual.length; i++) {
+ assertEq(actual[i], expected[i]);
+ }
+}
+
+// Check the environment of an empty module.
+let m = parseModule("");
+m.declarationInstantiation();
+testModuleEnvironment(m, []);
+
+let a = registerModule('a', parseModule("var x = 1; export { x };"));
+let b = registerModule('b', parseModule("import { x as y } from 'a';"));
+
+a.declarationInstantiation();
+b.declarationInstantiation();
+
+testModuleEnvironment(a, ['x']);
+testModuleEnvironment(b, ['y']);
+
+// Function bindings are initialized as well as instantiated.
+let c = parseModule(`function a(x) { return x; }
+ function b(x) { return x + 1; }
+ function c(x) { return x + 2; }
+ function d(x) { return x + 3; }`);
+const names = ['a', 'b', 'c', 'd'];
+testModuleEnvironment(c, names);
+names.forEach((n) => assertEq(typeof getModuleEnvironmentValue(c, n), "undefined"));
+c.declarationInstantiation();
+for (let i = 0; i < names.length; i++) {
+ let f = getModuleEnvironmentValue(c, names[i]);
+ assertEq(f(21), 21 + i);
+}