summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/modules
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/modules')
-rw-r--r--js/src/jit-test/tests/modules/dynamic-import-unsupported-attribute.js29
-rw-r--r--js/src/jit-test/tests/modules/failure-on-resume.js79
-rw-r--r--js/src/jit-test/tests/modules/import-entries.js51
-rw-r--r--js/src/jit-test/tests/modules/import-unsupported-attribute.js2
-rw-r--r--js/src/jit-test/tests/modules/requested-modules.js81
5 files changed, 178 insertions, 64 deletions
diff --git a/js/src/jit-test/tests/modules/dynamic-import-unsupported-attribute.js b/js/src/jit-test/tests/modules/dynamic-import-unsupported-attribute.js
new file mode 100644
index 0000000000..2b6ccb80bf
--- /dev/null
+++ b/js/src/jit-test/tests/modules/dynamic-import-unsupported-attribute.js
@@ -0,0 +1,29 @@
+// |jit-test| --enable-import-attributes
+
+async function test() {
+ try {
+ await import('./not-a-real-file.json', {with:{'unsupportedAttributeKey': 'json'}});
+ throw new Error("unreachable");
+ } catch (error) {
+ assertEq(error instanceof TypeError, true);
+ assertEq(error.message, "Unsupported import attribute: unsupportedAttributeKey");
+ }
+
+ try {
+ await import('./not-a-real-file.json', {with:{'unsupportedAttributeKey': 'json', type: 'json'}});
+ throw new Error("unreachable");
+ } catch (error) {
+ assertEq(error instanceof TypeError, true);
+ assertEq(error.message, "Unsupported import attribute: unsupportedAttributeKey");
+ }
+
+ try {
+ await import('./not-a-real-file.json', {with:{type: 'json', 'unsupportedAttributeKey': 'json'}});
+ throw new Error("unreachable");
+ } catch (error) {
+ assertEq(error instanceof TypeError, true);
+ assertEq(error.message, "Unsupported import attribute: unsupportedAttributeKey");
+ }
+}
+
+test(); \ No newline at end of file
diff --git a/js/src/jit-test/tests/modules/failure-on-resume.js b/js/src/jit-test/tests/modules/failure-on-resume.js
new file mode 100644
index 0000000000..d0e716b0bb
--- /dev/null
+++ b/js/src/jit-test/tests/modules/failure-on-resume.js
@@ -0,0 +1,79 @@
+const dbgGlobal = newGlobal({ newCompartment: true });
+dbgGlobal.parent = this;
+dbgGlobal.eval(`
+var entered = 0;
+var forceReturn = false;
+Debugger(parent).onEnterFrame = function () {
+ entered++;
+ if (forceReturn) {
+ return { return: "force return" };
+ }
+ return undefined;
+};
+`);
+
+{
+ function* f1() { yield 10; };
+
+ dbgGlobal.entered = 0;
+ let g = f1();
+ assertEq(dbgGlobal.entered, 1);
+ dbgGlobal.forceReturn = true;
+ let ret = g.next();
+ dbgGlobal.forceReturn = false;
+ assertEq(dbgGlobal.entered, 2);
+
+ assertEq(ret.value, "force return");
+}
+
+{
+ async function f2() { await {}; }
+
+ dbgGlobal.entered = 0;
+ let p = f2();
+ assertEq(dbgGlobal.entered, 1);
+ dbgGlobal.forceReturn = true;
+ drainJobQueue();
+ dbgGlobal.forceReturn = false;
+ assertEq(dbgGlobal.entered, 2);
+
+ let ret = null;
+ p.then(x => ret = x);
+ drainJobQueue();
+ assertEq(ret, "force return");
+}
+
+{
+ async function* f3() { await {}; }
+
+ dbgGlobal.entered = 0;
+ let g = f3();
+ assertEq(dbgGlobal.entered, 1);
+ dbgGlobal.forceReturn = true;
+ let p = g.next();
+ dbgGlobal.forceReturn = false;
+ assertEq(dbgGlobal.entered, 2);
+
+ let ret = null;
+ p.then(v => ret = v);
+ drainJobQueue();
+ assertEq(ret.value, "force return");
+}
+
+{
+ let m = registerModule("1", parseModule("await {};"));
+ moduleLink(m);
+
+ dbgGlobal.entered = 0;
+ let p = moduleEvaluate(m);
+ assertEq(dbgGlobal.entered, 1);
+ dbgGlobal.forceReturn = true;
+ drainJobQueue();
+ dbgGlobal.forceReturn = false;
+ assertEq(dbgGlobal.entered, 2);
+
+ let ret = null;
+ p.then(x => ret = x);
+ drainJobQueue();
+ assertEq(ret, undefined);
+}
diff --git a/js/src/jit-test/tests/modules/import-entries.js b/js/src/jit-test/tests/modules/import-entries.js
index e20d4e119b..ed668f0069 100644
--- a/js/src/jit-test/tests/modules/import-entries.js
+++ b/js/src/jit-test/tests/modules/import-entries.js
@@ -1,21 +1,24 @@
-// |jit-test| --enable-import-assertions
+// |jit-test| --enable-import-attributes
// Test importEntries property
-function assertionEq(actual, expected) {
- var actualAssertions = actual['assertions'];
- var expectedAssertions = expected['assertions'];
+function attributeEq(actual, expected) {
+ var actualAttributes = actual['attributes'];
+ var expectedAttributes = expected['attributes'];
- if(actualAssertions === null) {
- return expectedAssertions === actualAssertions
+ if(actualAttributes === null) {
+ return expectedAttributes === actualAttributes
}
- if(actualAssertions.length !== expectedAssertions.length) {
+ if(actualAttributes.length !== expectedAttributes.length) {
return false;
}
- for (var i = 0; i < expected.length; i++) {
- if(expected[i].type !== actual[i].type) {
+ for (var i = 0; i < expectedAttributes.length; i++) {
+ if (
+ expectedAttributes[i]['key'] !== actualAttributes[i]['key'] ||
+ expectedAttributes[i]['value'] !== actualAttributes[i]['value']
+ ) {
return false;
}
}
@@ -28,7 +31,7 @@ function importEntryEq(a, b) {
a['importName'] === b['importName'] &&
a['localName'] === b['localName'];
- return r1 && assertionEq(a['moduleRequest'], b['moduleRequest']);
+ return r1 && attributeEq(a['moduleRequest'], b['moduleRequest']);
}
function findImportEntry(array, target)
@@ -54,34 +57,34 @@ function testImportEntries(source, expected) {
testImportEntries('', []);
testImportEntries('import v from "mod";',
- [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'default', localName: 'v'}]);
+ [{moduleRequest: {specifier: 'mod', attributes: null}, importName: 'default', localName: 'v'}]);
testImportEntries('import * as ns from "mod";',
- [{moduleRequest: {specifier: 'mod', assertions: null}, importName: null, localName: 'ns'}]);
+ [{moduleRequest: {specifier: 'mod', attributes: null}, importName: null, localName: 'ns'}]);
testImportEntries('import {x} from "mod";',
- [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'x', localName: 'x'}]);
+ [{moduleRequest: {specifier: 'mod', attributes: null}, importName: 'x', localName: 'x'}]);
testImportEntries('import {x as v} from "mod";',
- [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'x', localName: 'v'}]);
+ [{moduleRequest: {specifier: 'mod', attributes: 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'}]);
+ [{moduleRequest: {specifier: 'a', attributes: null}, importName: 'x', localName: 'x'},
+ {moduleRequest: {specifier: 'b', attributes: null}, importName: 'y', localName: 'y'}]);
if (getRealmConfiguration("importAttributes")) {
- testImportEntries('import v from "mod" assert {};',
- [{moduleRequest: {specifier: 'mod', assertions: null}, importName: 'default', localName: 'v'}]);
+ testImportEntries('import v from "mod" with {};',
+ [{moduleRequest: {specifier: 'mod', attributes: 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 v from "mod" with { type: "js"};',
+ [{moduleRequest: {specifier: 'mod', attributes: [{ key: 'type', value: '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} from "mod" with { type: "js"};',
+ [{moduleRequest: {specifier: 'mod', attributes: [{ key: 'type', value: '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'}]);
+ testImportEntries('import {x as v} from "mod" with { type: "js"};',
+ [{moduleRequest: {specifier: 'mod', attributes: [{ key: 'type', value: 'js'}]}, importName: 'x', localName: 'v'}]);
}
diff --git a/js/src/jit-test/tests/modules/import-unsupported-attribute.js b/js/src/jit-test/tests/modules/import-unsupported-attribute.js
new file mode 100644
index 0000000000..c771c6556b
--- /dev/null
+++ b/js/src/jit-test/tests/modules/import-unsupported-attribute.js
@@ -0,0 +1,2 @@
+// |jit-test| --enable-import-attributes; module; error: TypeError: Unsupported import attribute: unsupported
+import a from 'foo' with { unsupported: 'test'}
diff --git a/js/src/jit-test/tests/modules/requested-modules.js b/js/src/jit-test/tests/modules/requested-modules.js
index ebbf8ce6c1..e0a7fb66b8 100644
--- a/js/src/jit-test/tests/modules/requested-modules.js
+++ b/js/src/jit-test/tests/modules/requested-modules.js
@@ -1,4 +1,4 @@
-// |jit-test| --enable-import-assertions
+// |jit-test| --enable-import-attributes
// Test requestedModules property
@@ -8,15 +8,16 @@ function testRequestedModules(source, expected) {
assertEq(actual.length, expected.length);
for (var i = 0; i < actual.length; i++) {
assertEq(actual[i].moduleRequest.specifier, expected[i].specifier);
- if(expected[i].assertions === null) {
- assertEq(actual[i].moduleRequest.assertions, null);
+ if(expected[i].attributes === null) {
+ assertEq(actual[i].moduleRequest.attributes, null);
}
else {
- var expectedAssertions = expected[i].assertions;
- var actualAssertions = actual[i].moduleRequest.assertions;
- assertEq(actualAssertions.length, expectedAssertions.length);
- for (var j = 0; j < expectedAssertions.length; j++) {
- assertEq(expectedAssertions[j].type, actualAssertions[j].type);
+ var expectedAttributes = expected[i].attributes;
+ var actualAttributes = actual[i].moduleRequest.attributes;
+ assertEq(actualAttributes.length, expectedAttributes.length);
+ for (var j = 0; j < expectedAttributes.length; j++) {
+ assertEq(expectedAttributes[j]['key'], actualAttributes[j]['key']);
+ assertEq(expectedAttributes[j]['value'], actualAttributes[j]['value']);
}
}
}
@@ -25,71 +26,71 @@ function testRequestedModules(source, expected) {
testRequestedModules("", []);
testRequestedModules("import a from 'foo'", [
- { specifier: 'foo', assertions: null }
+ { specifier: 'foo', attributes: null }
]);
testRequestedModules("import a from 'foo'; import b from 'bar'", [
- { specifier: 'foo', assertions: null },
- { specifier: 'bar', assertions: null }
+ { specifier: 'foo', attributes: null },
+ { specifier: 'bar', attributes: null }
]);
testRequestedModules("import a from 'foo'; import b from 'bar'; import c from 'foo'", [
- { specifier: 'foo', assertions: null },
- { specifier: 'bar', assertions: null }
+ { specifier: 'foo', attributes: null },
+ { specifier: 'bar', attributes: null }
]);
testRequestedModules("export {} from 'foo'", [
- { specifier: 'foo', assertions: null }
+ { specifier: 'foo', attributes: null }
]);
testRequestedModules("export * from 'bar'",[
- { specifier: 'bar', assertions: null }
+ { specifier: 'bar', attributes: null }
]);
testRequestedModules("import a from 'foo'; export {} from 'bar'; export * from 'baz'", [
- { specifier: 'foo', assertions: null },
- { specifier: 'bar', assertions: null },
- { specifier: 'baz', assertions: null }
+ { specifier: 'foo', attributes: null },
+ { specifier: 'bar', attributes: null },
+ { specifier: 'baz', attributes: null }
]);
if (getRealmConfiguration("importAttributes")) {
- testRequestedModules("import a from 'foo' assert {}", [
- { specifier: 'foo', assertions: null },
+ testRequestedModules("import a from 'foo' with {}", [
+ { specifier: 'foo', attributes: null },
]);
- testRequestedModules("import a from 'foo' assert { type: 'js'}", [
- { specifier: 'foo', assertions: [ { type: 'js' } ] },
+ testRequestedModules("import a from 'foo' with { type: 'js'}", [
+ { specifier: 'foo', attributes: [ { key: 'type', value: 'js'} ] },
]);
- testRequestedModules("import a from 'foo' assert { unsupported: 'test'}", [
- { specifier: 'foo', assertions: null },
+ testRequestedModules("import a from 'foo' with { unsupported: 'test'}", [
+ { specifier: 'foo', attributes: [ { key: 'unsupported', value: 'test'} ] },
]);
- testRequestedModules("import a from 'foo' assert { unsupported: 'test', type: 'js', foo: 'bar' }", [
- { specifier: 'foo', assertions: [ { type: 'js' } ] },
+ testRequestedModules("import a from 'foo' with { unsupported: 'test', type: 'js', foo: 'bar' }", [
+ { specifier: 'foo', attributes: [ { key: 'unsupported', value: 'test'}, { key: 'type', value: 'js'}, { key: 'foo', value: 'bar'} ] },
]);
- testRequestedModules("import a from 'foo' assert { type: 'js1'}; export {} from 'bar' assert { type: 'js2'}; export * from 'baz' assert { type: 'js3'}", [
- { specifier: 'foo', assertions: [ { type: 'js1' } ] },
- { specifier: 'bar', assertions: [ { type: 'js2' } ] },
- { specifier: 'baz', assertions: [ { type: 'js3' } ] }
+ testRequestedModules("import a from 'foo' with { type: 'js1'}; export {} from 'bar' with { type: 'js2'}; export * from 'baz' with { type: 'js3'}", [
+ { specifier: 'foo', attributes: [ { key: 'type', value: 'js1'} ] },
+ { specifier: 'bar', attributes: [ { key: 'type', value: 'js2'} ] },
+ { specifier: 'baz', attributes: [ { key: 'type', value: 'js3'} ] }
]);
- testRequestedModules("export {} from 'foo' assert { type: 'js'}", [
- { specifier: 'foo', assertions: [ { type: 'js' } ] }
+ testRequestedModules("export {} from 'foo' with { type: 'js'}", [
+ { specifier: 'foo', attributes: [ { key: 'type', value: 'js'} ] }
]);
- testRequestedModules("export * from 'bar' assert { type: 'json'}",[
- { specifier: 'bar', assertions: [ { type: 'json' } ] }
+ testRequestedModules("export * from 'bar' with { type: 'json'}",[
+ { specifier: 'bar', attributes: [ { key: 'type', value: 'json'} ] }
]);
- testRequestedModules("import a from 'foo'; import b from 'bar' assert { type: 'json' };", [
- { specifier: 'foo', assertions: null },
- { specifier: 'bar', assertions: [ { type: 'json' } ] },
+ testRequestedModules("import a from 'foo'; import b from 'bar' with { type: 'json' };", [
+ { specifier: 'foo', attributes: null },
+ { specifier: 'bar', attributes: [ { key: 'type', value: 'json'} ] },
]);
- testRequestedModules("import b from 'bar' assert { type: 'json' }; import a from 'foo';", [
- { specifier: 'bar', assertions: [ { type: 'json' } ] },
- { specifier: 'foo', assertions: null },
+ testRequestedModules("import b from 'bar' with { type: 'json' }; import a from 'foo';", [
+ { specifier: 'bar', attributes: [ { key: 'type', value: 'json'} ] },
+ { specifier: 'foo', attributes: null },
]);
}