From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/jit-test/tests/modules/import-entries.js | 85 +++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 js/src/jit-test/tests/modules/import-entries.js (limited to 'js/src/jit-test/tests/modules/import-entries.js') 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 -- cgit v1.2.3