Bug 1519100 - Adjust jit tests to work with module promises; r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D96067
This commit is contained in:
yulia 2020-12-02 12:41:08 +00:00
Родитель 5a92ccc7e6
Коммит 8ca98dd89c
10 изменённых файлов: 238 добавлений и 156 удалений

Просмотреть файл

@ -1,2 +1,2 @@
// |jit-test| module
// |jit-test| module --enable-top-level-await;
eval("1");

Просмотреть файл

@ -8,7 +8,11 @@ let c = registerModule("c", parseModule(`import "a";`));
b.declarationInstantiation();
c.declarationInstantiation();
let count = 0;
try { b.evaluation() } catch (e) { count++; }
try { c.evaluation() } catch (e) { count++; }
assertEq(count, 2);
(async () => {
let count = 0;
try { await b.evaluation() } catch (e) { count++; }
try { await c.evaluation() } catch (e) { count++; }
assertEq(count, 2);
})();
drainJobQueue();

Просмотреть файл

@ -1,3 +1,4 @@
// |jit-test| --enable-top-level-await;
"use strict";
load(libdir + "asserts.js");
@ -13,6 +14,18 @@ let b = registerModule('b', parseModule(`
`));
a.declarationInstantiation();
assertThrowsInstanceOf(() => a.evaluation(), UniqueError);
a.evaluation()
.then(r => {
// We should not reach here, as we expect an error to be thrown.
assertEq(false, true);
})
.catch(e => assertEq(e instanceof UniqueError, true));
b.declarationInstantiation();
assertThrowsInstanceOf(() => b.evaluation(), UniqueError);
b.evaluation()
.then(r => {
// We should not reach here, as we expect an error to be thrown.
assertEq(false, true);
})
.catch(e => assertEq(e instanceof UniqueError, true));
drainJobQueue();

Просмотреть файл

@ -1,3 +1,4 @@
// |jit-test| --enable-top-level-await;
dbgGlobal = newGlobal({newCompartment: true});
dbg = new dbgGlobal.Debugger;
dbg.addDebuggee(this);
@ -9,16 +10,20 @@ function f() {
function execModule(source) {
m = parseModule(source);
m.declarationInstantiation();
m.evaluation();
return m.evaluation();
}
execModule("f();");
gc();
execModule("f();").then(() => {
gc();
let caught;
try {
execModule("throw 'foo'");
} catch (e) {
caught = e;
}
assertEq(caught, 'foo');
execModule("throw 'foo'")
.then(r => {
// We should not reach here.
assertEq(false, true);
})
.catch(e => {
assertEq(e, 'foo');
});
})
drainJobQueue();

Просмотреть файл

@ -1,3 +1,3 @@
// |jit-test| --more-compartments
// |jit-test| --more-compartments;
fullcompartmentchecks(true);
newGlobal().eval(`import("javascript:")`).catch(() => {});

Просмотреть файл

@ -2,11 +2,11 @@
class MyError {}
function assertThrowsMyError(f)
async function assertThrowsMyError(f)
{
let caught = false;
try {
f();
await f();
} catch (e) {
caught = true;
assertEq(e.constructor, MyError);
@ -29,3 +29,5 @@ let b = registerModule('b', parseModule(`
`));
b.declarationInstantiation();
assertThrowsMyError(() => b.evaluation(b));
drainJobQueue();

Просмотреть файл

@ -1,3 +1,4 @@
// |jit-test| --enable-top-level-await;
// Test importing module namespaces
"use strict";
@ -90,7 +91,14 @@ let d = registerModule('d',
parseModule("export let d = 2; import * as ns from 'c'; let c = ns.c;"));
c.declarationInstantiation();
d.declarationInstantiation();
assertThrowsInstanceOf(() => c.evaluation(), ReferenceError);
c.evaluation()
.then(r => {
// We expect the evaluation to throw, so we should not reach this.
assertEq(false, true)
})
.catch(e => {
assertEq(e instanceof ReferenceError, true)
});
// Test cyclic namespace import.
let e = registerModule('e',
@ -103,3 +111,4 @@ e.evaluation();
f.evaluation();
assertEq(e.namespace.f(), 2);
assertEq(f.namespace.e(), 1);
drainJobQueue();

Просмотреть файл

@ -1,34 +1,46 @@
// |jit-test| --enable-top-level-await;
// Exercise ModuleEvaluation() concrete method.
load(libdir + "asserts.js");
function parseAndEvaluate(source) {
async function parseAndEvaluate(source) {
let m = parseModule(source);
m.declarationInstantiation();
m.evaluation();
await m.evaluation();
return m;
}
// Check the evaluation of an empty module succeeds.
parseAndEvaluate("");
(async () => {
await parseAndEvaluate("");
})();
// Check evaluation returns evaluation result the first time, then undefined.
let m = parseModule("1");
m.declarationInstantiation();
assertEq(m.evaluation(), undefined);
assertEq(typeof m.evaluation(), "undefined");
(async () => {
// Check that evaluation returns evaluation promise,
// and promise is always the same.
let m = parseModule("1");
m.declarationInstantiation();
assertEq(typeof m.evaluation(), "object");
assertEq(m.evaluation() instanceof Promise, true);
assertEq(m.evaluation(), m.evaluation());
await m.evaluation();
})();
// Check top level variables are initialized by evaluation.
m = parseModule("export var x = 2 + 2;");
assertEq(typeof getModuleEnvironmentValue(m, "x"), "undefined");
m.declarationInstantiation();
m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 4);
(async () => {
// Check top level variables are initialized by evaluation.
let m = parseModule("export var x = 2 + 2;");
assertEq(typeof getModuleEnvironmentValue(m, "x"), "undefined");
m.declarationInstantiation();
await m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 4);
})();
m = parseModule("export let x = 2 * 3;");
m.declarationInstantiation();
m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 6);
(async () => {
let m = parseModule("export let x = 2 * 3;");
m.declarationInstantiation();
await m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 6);
})();
// Set up a module to import from.
let a = registerModule('a',
@ -37,62 +49,77 @@ let a = registerModule('a',
export default 2;
export function f(x) { return x + 1; }`));
// Check we can evaluate top level definitions.
parseAndEvaluate("var foo = 1;");
parseAndEvaluate("let foo = 1;");
parseAndEvaluate("const foo = 1");
parseAndEvaluate("function foo() {}");
parseAndEvaluate("class foo { constructor() {} }");
(async () => {
// Check we can evaluate top level definitions.
await parseAndEvaluate("var foo = 1;");
await parseAndEvaluate("let foo = 1;");
await parseAndEvaluate("const foo = 1");
await parseAndEvaluate("function foo() {}");
await parseAndEvaluate("class foo { constructor() {} }");
// Check we can evaluate all module-related syntax.
parseAndEvaluate("export var foo = 1;");
parseAndEvaluate("export let foo = 1;");
parseAndEvaluate("export const foo = 1;");
parseAndEvaluate("var x = 1; export { x };");
parseAndEvaluate("export default 1");
parseAndEvaluate("export default function() {};");
parseAndEvaluate("export default function foo() {};");
parseAndEvaluate("import a from 'a';");
parseAndEvaluate("import { x } from 'a';");
parseAndEvaluate("import * as ns from 'a';");
parseAndEvaluate("export * from 'a'");
parseAndEvaluate("export default class { constructor() {} };");
parseAndEvaluate("export default class foo { constructor() {} };");
// Check we can evaluate all module-related syntax.
await parseAndEvaluate("export var foo = 1;");
await parseAndEvaluate("export let foo = 1;");
await parseAndEvaluate("export const foo = 1;");
await parseAndEvaluate("var x = 1; export { x };");
await parseAndEvaluate("export default 1");
await parseAndEvaluate("export default function() {};");
await parseAndEvaluate("export default function foo() {};");
await parseAndEvaluate("import a from 'a';");
await parseAndEvaluate("import { x } from 'a';");
await parseAndEvaluate("import * as ns from 'a';");
await parseAndEvaluate("export * from 'a'");
await parseAndEvaluate("export default class { constructor() {} };");
await parseAndEvaluate("export default class foo { constructor() {} };");
})();
// Test default import
m = parseModule("import a from 'a'; export { a };")
m.declarationInstantiation();
m.evaluation()
assertEq(getModuleEnvironmentValue(m, "a"), 2);
(async () => {
// Test default import
let m = parseModule("import a from 'a'; export { a };")
m.declarationInstantiation();
await m.evaluation()
assertEq(getModuleEnvironmentValue(m, "a"), 2);
})();
// Test named import
m = parseModule("import { x as y } from 'a'; export { y };")
m.declarationInstantiation();
m.evaluation();
assertEq(getModuleEnvironmentValue(m, "y"), 1);
(async () => {
// Test named import
let m = parseModule("import { x as y } from 'a'; export { y };")
m.declarationInstantiation();
await m.evaluation();
assertEq(getModuleEnvironmentValue(m, "y"), 1);
})();
// Call exported function
m = parseModule("import { f } from 'a'; export let x = f(3);")
m.declarationInstantiation();
m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 4);
(async () => {
// Call exported function
let m = parseModule("import { f } from 'a'; export let x = f(3);")
m.declarationInstantiation();
await m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 4);
})();
// Test importing an indirect export
registerModule('b', parseModule("export { x as z } from 'a';"));
m = parseAndEvaluate("import { z } from 'b'; export { z }");
assertEq(getModuleEnvironmentValue(m, "z"), 1);
(async () => {
// Test importing an indirect export
registerModule('b', parseModule("export { x as z } from 'a';"));
let m = await parseAndEvaluate("import { z } from 'b'; export { z }");
assertEq(getModuleEnvironmentValue(m, "z"), 1);
})();
// Test cyclic dependencies
registerModule('c1', parseModule("export var x = 1; export {y} from 'c2'"));
registerModule('c2', parseModule("export var y = 2; export {x} from 'c1'"));
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]);
(async () => {
// Test cyclic dependencies
registerModule('c1', parseModule("export var x = 1; export {y} from 'c2'"));
registerModule('c2', parseModule("export var y = 2; export {x} from 'c1'"));
let m = await 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; }")
m.declarationInstantiation();
m.evaluation();
let f = getModuleEnvironmentValue(m, "f");
assertEq(f(), 1);
(async () => {
// Import access in functions
let m = await parseModule("import { x } from 'a'; function f() { return x; }")
m.declarationInstantiation();
m.evaluation();
let f = getModuleEnvironmentValue(m, "f");
assertEq(f(), 1);
})();
drainJobQueue();

Просмотреть файл

@ -1,3 +1,4 @@
// |jit-test| --enable-top-level-await;
// Test 'this' is undefined in modules.
function parseAndEvaluate(source) {
@ -6,10 +7,19 @@ function parseAndEvaluate(source) {
return m.evaluation();
}
assertEq(typeof(parseAndEvaluate("this")), "undefined");
parseAndEvaluate("this")
.then(value => assertEq(typeof(value), "undefined"))
.catch(error => {
// We shouldn't throw in this case.
assertEq(false, true)
});
let m = parseModule("export function getThis() { return this; }");
m.declarationInstantiation();
m.evaluation();
let f = getModuleEnvironmentValue(m, "getThis");
assertEq(typeof(f()), "undefined");
m.evaluation()
.then(() => {
let f = getModuleEnvironmentValue(m, "getThis");
assertEq(typeof(f()), "undefined");
});
drainJobQueue();

Просмотреть файл

@ -1,81 +1,93 @@
// |jit-test| --enable-top-level-await;
load(libdir + "asserts.js");
function parseAndEvaluate(source) {
async function parseAndEvaluate(source) {
let og = parseModule(source);
let bc = codeModule(og);
let m = decodeModule(bc);
m.declarationInstantiation();
m.evaluation();
await m.evaluation();
return m;
}
// Check the evaluation of an empty module succeeds.
parseAndEvaluate("");
(async () => {
// Check the evaluation of an empty module succeeds.
await parseAndEvaluate("");
})();
// Check evaluation returns evaluation result the first time, then undefined.
let og = parseModule("1");
let bc = codeModule(og);
let m = decodeModule(bc);
m.declarationInstantiation();
assertEq(m.evaluation(), undefined);
assertEq(typeof m.evaluation(), "undefined");
(async () => {
// Check that evaluation returns evaluation promise,
// and promise is always the same.
let og = parseModule("1");
let bc = codeModule(og);
let m = decodeModule(bc);
m.declarationInstantiation();
assertEq(typeof m.evaluation(), "object");
assertEq(m.evaluation() instanceof Promise, true);
assertEq(m.evaluation(), m.evaluation());
})();
// Check top level variables are initialized by evaluation.
og = parseModule("export var x = 2 + 2;");
bc = codeModule(og);
m = decodeModule(bc);
assertEq(typeof getModuleEnvironmentValue(m, "x"), "undefined");
m.declarationInstantiation();
m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 4);
(async () => {
// Check top level variables are initialized by evaluation.
let og = parseModule("export var x = 2 + 2;");
let bc = codeModule(og);
let m = decodeModule(bc);
assertEq(typeof getModuleEnvironmentValue(m, "x"), "undefined");
m.declarationInstantiation();
await m.evaluation();
assertEq(getModuleEnvironmentValue(m, "x"), 4);
})();
m = parseAndEvaluate("export let x = 2 * 3;");
assertEq(getModuleEnvironmentValue(m, "x"), 6);
(async () => {
let m = await parseAndEvaluate("export let x = 2 * 3;");
assertEq(getModuleEnvironmentValue(m, "x"), 6);
// Set up a module to import from.
og = parseModule(`var x = 1;
export { x };
export default 2;
export function f(x) { return x + 1; }`);
bc = codeModule(og);
a = registerModule('a', decodeModule(bc));
// Set up a module to import from.
let og = parseModule(`var x = 1;
export { x };
export default 2;
export function f(x) { return x + 1; }`);
let bc = codeModule(og);
let a = registerModule('a', decodeModule(bc));
// Check we can evaluate top level definitions.
parseAndEvaluate("var foo = 1;");
parseAndEvaluate("let foo = 1;");
parseAndEvaluate("const foo = 1");
parseAndEvaluate("function foo() {}");
parseAndEvaluate("class foo { constructor() {} }");
// Check we can evaluate top level definitions.
await parseAndEvaluate("var foo = 1;");
await parseAndEvaluate("let foo = 1;");
await parseAndEvaluate("const foo = 1");
await parseAndEvaluate("function foo() {}");
await parseAndEvaluate("class foo { constructor() {} }");
// Check we can evaluate all module-related syntax.
parseAndEvaluate("export var foo = 1;");
parseAndEvaluate("export let foo = 1;");
parseAndEvaluate("export const foo = 1;");
parseAndEvaluate("var x = 1; export { x };");
parseAndEvaluate("export default 1");
parseAndEvaluate("export default function() {};");
parseAndEvaluate("export default function foo() {};");
parseAndEvaluate("import a from 'a';");
parseAndEvaluate("import { x } from 'a';");
parseAndEvaluate("import * as ns from 'a';");
parseAndEvaluate("export * from 'a'");
parseAndEvaluate("export default class { constructor() {} };");
parseAndEvaluate("export default class foo { constructor() {} };");
// Check we can evaluate all module-related syntax.
await parseAndEvaluate("export var foo = 1;");
await parseAndEvaluate("export let foo = 1;");
await parseAndEvaluate("export const foo = 1;");
await parseAndEvaluate("var x = 1; export { x };");
await parseAndEvaluate("export default 1");
await parseAndEvaluate("export default function() {};");
await parseAndEvaluate("export default function foo() {};");
await parseAndEvaluate("import a from 'a';");
await parseAndEvaluate("import { x } from 'a';");
await parseAndEvaluate("import * as ns from 'a';");
await parseAndEvaluate("export * from 'a'");
await parseAndEvaluate("export default class { constructor() {} };");
await parseAndEvaluate("export default class foo { constructor() {} };");
// Test default import
m = parseAndEvaluate("import a from 'a'; export { a };")
assertEq(getModuleEnvironmentValue(m, "a"), 2);
// Test default import
m = await parseAndEvaluate("import a from 'a'; export { a };")
assertEq(getModuleEnvironmentValue(m, "a"), 2);
// Test named import
m = parseAndEvaluate("import { x as y } from 'a'; export { y };")
assertEq(getModuleEnvironmentValue(m, "y"), 1);
// Test named import
m = await parseAndEvaluate("import { x as y } from 'a'; export { y };")
assertEq(getModuleEnvironmentValue(m, "y"), 1);
// Call exported function
m = parseAndEvaluate("import { f } from 'a'; export let x = f(3);")
assertEq(getModuleEnvironmentValue(m, "x"), 4);
// Call exported function
m = await parseAndEvaluate("import { f } from 'a'; export let x = f(3);")
assertEq(getModuleEnvironmentValue(m, "x"), 4);
// Import access in functions
m = parseAndEvaluate("import { x } from 'a'; function f() { return x; }")
let f = getModuleEnvironmentValue(m, "f");
assertEq(f(), 1);
// Import access in functions
m = await parseAndEvaluate("import { x } from 'a'; function f() { return x; }")
let f = getModuleEnvironmentValue(m, "f");
assertEq(f(), 1);
})();
drainJobQueue();