summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules/import-entries.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/modules/import-entries.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/modules/import-entries.js')
-rw-r--r--js/src/jit-test/tests/modules/import-entries.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/modules/import-entries.js b/js/src/jit-test/tests/modules/import-entries.js
new file mode 100644
index 0000000000..d79bc0a4d5
--- /dev/null
+++ b/js/src/jit-test/tests/modules/import-entries.js
@@ -0,0 +1,85 @@
+// Test importEntries property
+
+function assertionEq(actual, expected) {
+ var actualAssertions = actual['assertions'];
+ var expectedAssertions = expected['assertions'];
+
+ if(actualAssertions === null) {
+ return expectedAssertions === actualAssertions
+ }
+
+ if(actualAssertions.length !== expectedAssertions.length) {
+ return false;
+ }
+
+ for (var i = 0; i < expected.length; i++) {
+ if(expected[i].type !== actual[i].type) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function importEntryEq(a, b) {
+ var r1 = a['moduleRequest']['specifier'] === b['moduleRequest']['specifier'] &&
+ a['importName'] === b['importName'] &&
+ a['localName'] === b['localName'];
+
+ return r1 && assertionEq(a['moduleRequest'], b['moduleRequest']);
+}
+
+function findImportEntry(array, target)
+{
+ for (let i = 0; i < array.length; i++) {
+ if (importEntryEq(array[i], target))
+ return i;
+ }
+ return -1;
+}
+
+function testImportEntries(source, expected) {
+ var module = parseModule(source);
+ var actual = module.importEntries.slice(0);
+ assertEq(actual.length, expected.length);
+ for (var i = 0; i < expected.length; i++) {
+ let index = findImportEntry(actual, expected[i]);
+ assertEq(index >= 0, true);
+ actual.splice(index, 1);
+ }
+}
+
+testImportEntries('', []);
+
+testImportEntries('import v from "mod";',
+ [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'default', localName: 'v'}]);
+
+testImportEntries('import * as ns from "mod";',
+ [{moduleRequest: {specifier: 'mod', assertions: null}, importName: null, localName: 'ns'}]);
+
+testImportEntries('import {x} from "mod";',
+ [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'x', localName: 'x'}]);
+
+testImportEntries('import {x as v} from "mod";',
+ [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'x', localName: 'v'}]);
+
+testImportEntries('import "mod";',
+ []);
+
+testImportEntries('import {x} from "a"; import {y} from "b";',
+ [{moduleRequest: {specifier: 'a', assertions: null}, importName: 'x', localName: 'x'},
+ {moduleRequest: {specifier: 'b', assertions: null}, importName: 'y', localName: 'y'}]);
+
+if(getRealmConfiguration()['importAssertions']) {
+ testImportEntries('import v from "mod" assert {};',
+ [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'default', localName: 'v'}]);
+
+ testImportEntries('import v from "mod" assert { type: "js"};',
+ [{moduleRequest: {specifier: 'mod', assertions: [{ type: 'js'}]}, importName: 'default', localName: 'v'}]);
+
+ testImportEntries('import {x} from "mod" assert { type: "js"};',
+ [{moduleRequest: {specifier: 'mod', assertions: [{ type: 'js'}]}, importName: 'x', localName: 'x'}]);
+
+ testImportEntries('import {x as v} from "mod" assert { type: "js"};',
+ [{moduleRequest: {specifier: 'mod', assertions: [{ type: 'js'}]}, importName: 'x', localName: 'v'}]);
+} \ No newline at end of file