summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-07-10 18:46:10 +0000
committerMoonchild <moonchild@palemoon.org>2020-07-10 18:46:10 +0000
commitf1b51be787c11090c8d9b2ec73255df7a67c7eb7 (patch)
tree9c6d35ce6f19e0fef3c47c7e2c152394854cf217 /js/src/jit-test/tests/modules
parent2deaddfca28508ac1a634eb6088a1da8e571ec6e (diff)
parent82faff19e1761797b7a75f9221f0709c5a38bfe6 (diff)
downloadUXP-f1b51be787c11090c8d9b2ec73255df7a67c7eb7.tar
UXP-f1b51be787c11090c8d9b2ec73255df7a67c7eb7.tar.gz
UXP-f1b51be787c11090c8d9b2ec73255df7a67c7eb7.tar.lz
UXP-f1b51be787c11090c8d9b2ec73255df7a67c7eb7.tar.xz
UXP-f1b51be787c11090c8d9b2ec73255df7a67c7eb7.zip
Merge branch 'redwood' into releaseRELBASE_20200711
Diffstat (limited to 'js/src/jit-test/tests/modules')
-rw-r--r--js/src/jit-test/tests/modules/ambiguous-star-export.js15
-rw-r--r--js/src/jit-test/tests/modules/bad-namespace-created.js17
-rw-r--r--js/src/jit-test/tests/modules/bug-1284486.js39
-rw-r--r--js/src/jit-test/tests/modules/bug-1287410.js2
-rw-r--r--js/src/jit-test/tests/modules/bug-1394492.js6
-rw-r--r--js/src/jit-test/tests/modules/global-scope.js18
-rw-r--r--js/src/jit-test/tests/modules/module-evaluation.js33
7 files changed, 89 insertions, 41 deletions
diff --git a/js/src/jit-test/tests/modules/ambiguous-star-export.js b/js/src/jit-test/tests/modules/ambiguous-star-export.js
index b8c91445c..94aa7ac4a 100644
--- a/js/src/jit-test/tests/modules/ambiguous-star-export.js
+++ b/js/src/jit-test/tests/modules/ambiguous-star-export.js
@@ -5,10 +5,11 @@
load(libdir + "asserts.js");
load(libdir + "dummyModuleResolveHook.js");
-function checkModuleEval(source, result) {
+function checkModuleEval(source) {
let m = parseModule(source);
m.declarationInstantiation();
- assertEq(m.evaluation(), result);
+ m.evaluation();
+ return m;
}
function checkModuleSyntaxError(source) {
@@ -23,17 +24,19 @@ c.declarationInstantiation();
c.evaluation();
// Check importing/exporting non-ambiguous name works.
-checkModuleEval("import { a } from 'c'; a;", 1);
-checkModuleEval("export { a } from 'c';", undefined);
+let d = checkModuleEval("import { a } from 'c';");
+assertEq(getModuleEnvironmentValue(d, "a"), 1);
+checkModuleEval("export { a } from 'c';");
// Check importing/exporting ambiguous name is a syntax error.
checkModuleSyntaxError("import { b } from 'c';");
checkModuleSyntaxError("export { b } from 'c';");
// Check that namespace objects include only non-ambiguous names.
-let m = parseModule("import * as ns from 'c'; ns;");
+let m = parseModule("import * as ns from 'c';");
m.declarationInstantiation();
-let ns = m.evaluation();
+m.evaluation();
+let ns = c.namespace;
let names = Object.keys(ns);
assertEq(names.length, 2);
assertEq('a' in ns, true);
diff --git a/js/src/jit-test/tests/modules/bad-namespace-created.js b/js/src/jit-test/tests/modules/bad-namespace-created.js
new file mode 100644
index 000000000..127892d6e
--- /dev/null
+++ b/js/src/jit-test/tests/modules/bad-namespace-created.js
@@ -0,0 +1,17 @@
+// Prior to https://github.com/tc39/ecma262/pull/916 it was possible for a
+// module namespace object to be successfully created that was later found to be
+// erroneous. Test that this is no longer the case.
+
+"use strict";
+
+load(libdir + "asserts.js");
+load(libdir + "dummyModuleResolveHook.js");
+
+moduleRepo['A'] = parseModule('import "B"; export {x} from "C"');
+moduleRepo['B'] = parseModule('import * as a from "A"');
+moduleRepo['C'] = parseModule('export * from "D"; export * from "E"');
+moduleRepo['D'] = parseModule('export let x');
+moduleRepo['E'] = parseModule('export let x');
+
+let m = moduleRepo['A'];
+assertThrowsInstanceOf(() => m.declarationInstantiation(), SyntaxError);
diff --git a/js/src/jit-test/tests/modules/bug-1284486.js b/js/src/jit-test/tests/modules/bug-1284486.js
index 9a3244ec3..08286393a 100644
--- a/js/src/jit-test/tests/modules/bug-1284486.js
+++ b/js/src/jit-test/tests/modules/bug-1284486.js
@@ -1,23 +1,36 @@
-// |jit-test| error: InternalError
-
// This tests that attempting to perform ModuleDeclarationInstantation a second
-// time after a failure throws an error. Doing this would be a bug in the module
-// loader, which is expected to throw away modules if there is an error
-// instantiating them.
+// time after a failure re-throws the same error.
//
// The first attempt fails becuase module 'a' is not available. The second
// attempt fails because of the previous failure (it would otherwise succeed as
// 'a' is now available).
-let moduleRepo = {};
-setModuleResolveHook(function(module, specifier) {
- return moduleRepo[specifier];
-});
+load(libdir + "dummyModuleResolveHook.js");
+
+let b = moduleRepo['b'] = parseModule("export var b = 3; export var c = 4;");
+let c = moduleRepo['c'] = parseModule("export * from 'a'; export * from 'b';");
+
+let e1;
+let threw = false;
try {
- let b = moduleRepo['b'] = parseModule("export var b = 3; export var c = 4;");
- let c = moduleRepo['c'] = parseModule("export * from 'a'; export * from 'b';");
c.declarationInstantiation();
-} catch (exc) {}
+} catch (exc) {
+ threw = true;
+ e1 = exc;
+}
+assertEq(threw, true);
+assertEq(typeof e1 === "undefined", false);
+
let a = moduleRepo['a'] = parseModule("export var a = 1; export var b = 2;");
let d = moduleRepo['d'] = parseModule("import { a } from 'c'; a;");
-d.declarationInstantiation();
+
+threw = false;
+let e2;
+try {
+ d.declarationInstantiation();
+} catch (exc) {
+ threw = true;
+ e2 = exc;
+}
+assertEq(threw, true);
+assertEq(e1, e2);
diff --git a/js/src/jit-test/tests/modules/bug-1287410.js b/js/src/jit-test/tests/modules/bug-1287410.js
index 8a891372a..7df5621a5 100644
--- a/js/src/jit-test/tests/modules/bug-1287410.js
+++ b/js/src/jit-test/tests/modules/bug-1287410.js
@@ -20,3 +20,5 @@ let d = moduleRepo['d'] = parseModule("import { a } from 'c'; a;");
// Attempting to instantiate 'd' throws an error because depdency 'a' of
// instantiated module 'c' is not instantiated.
d.declarationInstantiation();
+d.evaluation();
+
diff --git a/js/src/jit-test/tests/modules/bug-1394492.js b/js/src/jit-test/tests/modules/bug-1394492.js
new file mode 100644
index 000000000..a0e5d2ac3
--- /dev/null
+++ b/js/src/jit-test/tests/modules/bug-1394492.js
@@ -0,0 +1,6 @@
+// |jit-test| error: NaN
+let m = parseModule(`
+ throw i => { return 5; }, m-1;
+`);
+m.declarationInstantiation();
+m.evaluation();
diff --git a/js/src/jit-test/tests/modules/global-scope.js b/js/src/jit-test/tests/modules/global-scope.js
index 90a9f7026..b99019fa8 100644
--- a/js/src/jit-test/tests/modules/global-scope.js
+++ b/js/src/jit-test/tests/modules/global-scope.js
@@ -1,32 +1,34 @@
// Test interaction with global object and global lexical scope.
-function parseAndEvaluate(source) {
+function evalModuleAndCheck(source, expected) {
let m = parseModule(source);
m.declarationInstantiation();
- return m.evaluation();
+ m.evaluation();
+ assertEq(getModuleEnvironmentValue(m, "r"), expected);
}
var x = 1;
-assertEq(parseAndEvaluate("let r = x; x = 2; r"), 1);
+evalModuleAndCheck("export let r = x; x = 2;", 1);
assertEq(x, 2);
let y = 3;
-assertEq(parseAndEvaluate("let r = y; y = 4; r"), 3);
+evalModuleAndCheck("export let r = y; y = 4;", 3);
assertEq(y, 4);
if (helperThreadCount() == 0)
quit();
-function offThreadParseAndEvaluate(source) {
+function offThreadEvalModuleAndCheck(source, expected) {
offThreadCompileModule(source);
let m = finishOffThreadModule();
print("compiled");
m.declarationInstantiation();
- return m.evaluation();
+ m.evaluation();
+ assertEq(getModuleEnvironmentValue(m, "r"), expected);
}
-assertEq(offThreadParseAndEvaluate("let r = x; x = 5; r"), 2);
+offThreadEvalModuleAndCheck("export let r = x; x = 5;", 2);
assertEq(x, 5);
-assertEq(offThreadParseAndEvaluate("let r = y; y = 6; r"), 4);
+offThreadEvalModuleAndCheck("export let r = y; y = 6;", 4);
assertEq(y, 6);
diff --git a/js/src/jit-test/tests/modules/module-evaluation.js b/js/src/jit-test/tests/modules/module-evaluation.js
index eec13c040..84d88f19c 100644
--- a/js/src/jit-test/tests/modules/module-evaluation.js
+++ b/js/src/jit-test/tests/modules/module-evaluation.js
@@ -6,16 +6,17 @@ load(libdir + "dummyModuleResolveHook.js");
function parseAndEvaluate(source) {
let m = parseModule(source);
m.declarationInstantiation();
- return m.evaluation();
+ m.evaluation();
+ return m;
}
// Check the evaluation of an empty module succeeds.
-assertEq(typeof parseAndEvaluate(""), "undefined");
+parseAndEvaluate("");
// Check evaluation returns evaluation result the first time, then undefined.
let m = parseModule("1");
m.declarationInstantiation();
-assertEq(m.evaluation(), 1);
+assertEq(m.evaluation(), undefined);
assertEq(typeof m.evaluation(), "undefined");
// Check top level variables are initialized by evaluation.
@@ -60,31 +61,35 @@ parseAndEvaluate("export default class { constructor() {} };");
parseAndEvaluate("export default class foo { constructor() {} };");
// Test default import
-m = parseModule("import a from 'a'; a;")
+m = parseModule("import a from 'a'; export { a };")
m.declarationInstantiation();
-assertEq(m.evaluation(), 2);
+m.evaluation();
+assertEq(getModuleEnvironmentValue(m, "a"), 2);
// Test named import
-m = parseModule("import { x as y } from 'a'; y;")
+m = parseModule("import { x as y } from 'a'; export { y };")
m.declarationInstantiation();
-assertEq(m.evaluation(), 1);
+m.evaluation();
+assertEq(getModuleEnvironmentValue(m, "y"), 1);
// Call exported function
-m = parseModule("import { f } from 'a'; f(3);")
+m = parseModule("import { f } from 'a'; export let x = f(3);")
m.declarationInstantiation();
-assertEq(m.evaluation(), 4);
+m.evaluation();
+assertEq(getModuleEnvironmentValue(m, "x"), 4);
// Test importing an indirect export
moduleRepo['b'] = parseModule("export { x as z } from 'a';");
-assertEq(parseAndEvaluate("import { z } from 'b'; z"), 1);
+m = parseAndEvaluate("import { z } from 'b'; export { z }");
+assertEq(getModuleEnvironmentValue(m, "z"), 1);
// Test cyclic dependencies
moduleRepo['c1'] = parseModule("export var x = 1; export {y} from 'c2'");
moduleRepo['c2'] = parseModule("export var y = 2; export {x} from 'c1'");
-assertDeepEq(parseAndEvaluate(`import { x as x1, y as y1 } from 'c1';
- import { x as x2, y as y2 } from 'c2';
- [x1, y1, x2, y2]`),
- [1, 2, 1, 2]);
+m = parseAndEvaluate(`import { x as x1, y as y1 } from 'c1';
+ import { x as x2, y as y2 } from 'c2';
+ export let z = [x1, y1, x2, y2]`),
+assertDeepEq(getModuleEnvironmentValue(m, "z"), [1, 2, 1, 2]);
// Import access in functions
m = parseModule("import { x } from 'a'; function f() { return x; }")