diff options
Diffstat (limited to 'js/src/tests/non262/fields')
-rw-r--r-- | js/src/tests/non262/fields/await-identifier-module-1.js | 3 | ||||
-rw-r--r-- | js/src/tests/non262/fields/await-identifier-module-2.js | 3 | ||||
-rw-r--r-- | js/src/tests/non262/fields/await-identifier-module-3.js | 3 | ||||
-rw-r--r-- | js/src/tests/non262/fields/await-identifier-script.js | 22 | ||||
-rw-r--r-- | js/src/tests/non262/fields/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/non262/fields/bug1587574.js | 14 | ||||
-rw-r--r-- | js/src/tests/non262/fields/init-order.js | 25 | ||||
-rw-r--r-- | js/src/tests/non262/fields/numeric-fields.js | 14 | ||||
-rw-r--r-- | js/src/tests/non262/fields/scopes.js | 11 | ||||
-rw-r--r-- | js/src/tests/non262/fields/shell.js | 0 | ||||
-rw-r--r-- | js/src/tests/non262/fields/unimplemented.js | 57 |
11 files changed, 152 insertions, 0 deletions
diff --git a/js/src/tests/non262/fields/await-identifier-module-1.js b/js/src/tests/non262/fields/await-identifier-module-1.js new file mode 100644 index 0000000000..71e1f51b78 --- /dev/null +++ b/js/src/tests/non262/fields/await-identifier-module-1.js @@ -0,0 +1,3 @@ +// |reftest| error:SyntaxError module + +async () => class { [await] = 1 }; diff --git a/js/src/tests/non262/fields/await-identifier-module-2.js b/js/src/tests/non262/fields/await-identifier-module-2.js new file mode 100644 index 0000000000..1ad442d4dd --- /dev/null +++ b/js/src/tests/non262/fields/await-identifier-module-2.js @@ -0,0 +1,3 @@ +// |reftest| error:SyntaxError module + +async () => class { x = await }; diff --git a/js/src/tests/non262/fields/await-identifier-module-3.js b/js/src/tests/non262/fields/await-identifier-module-3.js new file mode 100644 index 0000000000..3b0400dc07 --- /dev/null +++ b/js/src/tests/non262/fields/await-identifier-module-3.js @@ -0,0 +1,3 @@ +// |reftest| error:SyntaxError module + +async () => class { x = await 1 }; diff --git a/js/src/tests/non262/fields/await-identifier-script.js b/js/src/tests/non262/fields/await-identifier-script.js new file mode 100644 index 0000000000..a426fd9c18 --- /dev/null +++ b/js/src/tests/non262/fields/await-identifier-script.js @@ -0,0 +1,22 @@ +var await = 1; + +async function getClass() { + return class { + x = await; + }; +} + +getClass().then(cl => { + assertEq(new cl().x, 1); +}); + +assertEq(raisesException(SyntaxError)(` +async () => class { [await] = 1 }; +`), true); + +assertEq(raisesException(SyntaxError)(` + async () => class { x = await 1 }; +`), true); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/fields/browser.js b/js/src/tests/non262/fields/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/fields/browser.js diff --git a/js/src/tests/non262/fields/bug1587574.js b/js/src/tests/non262/fields/bug1587574.js new file mode 100644 index 0000000000..547f4e1382 --- /dev/null +++ b/js/src/tests/non262/fields/bug1587574.js @@ -0,0 +1,14 @@ +// Don't Crash +var testStr = ` +class C extends Object { + constructor() { + eval(\`a => b => { + class Q { f = 1; } // inhibits lazy parsing + super(); + }\`); + } +} +new C;` +assertEq(raisesException(ReferenceError)(testStr), true); + +reportCompare(true, true); diff --git a/js/src/tests/non262/fields/init-order.js b/js/src/tests/non262/fields/init-order.js new file mode 100644 index 0000000000..6679a65e7b --- /dev/null +++ b/js/src/tests/non262/fields/init-order.js @@ -0,0 +1,25 @@ +function g1() { + throw 10; +} + +function g2() { + throw 20; +} + +class A { + #x = "hello" + g1(); + constructor(o = g2()) { + } +}; + +var thrown; +try { + new A; +} catch (e) { + thrown = e; +} + +assertEq(thrown, 10); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/fields/numeric-fields.js b/js/src/tests/non262/fields/numeric-fields.js new file mode 100644 index 0000000000..9bd8d4abce --- /dev/null +++ b/js/src/tests/non262/fields/numeric-fields.js @@ -0,0 +1,14 @@ +// Number field names. +class C { + 128 = class {}; +} +assertEq(new C()[128].name, "128"); + +// Bigint field names. +class D { + 128n = class {}; +} +assertEq(new D()[128].name, "128"); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/fields/scopes.js b/js/src/tests/non262/fields/scopes.js new file mode 100644 index 0000000000..39ff31c44a --- /dev/null +++ b/js/src/tests/non262/fields/scopes.js @@ -0,0 +1,11 @@ +(function({ + k = class i { + [_ => i]() + {} + } +} = {}) { + var j = 0; +})() + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/fields/shell.js b/js/src/tests/non262/fields/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/fields/shell.js diff --git a/js/src/tests/non262/fields/unimplemented.js b/js/src/tests/non262/fields/unimplemented.js new file mode 100644 index 0000000000..49a09468ec --- /dev/null +++ b/js/src/tests/non262/fields/unimplemented.js @@ -0,0 +1,57 @@ +// Field syntax doesn't crash the engine when fields are disabled. + +// Are fields enabled? +let fieldsEnabled = false; +try { + Function("class C { x; }"); + fieldsEnabled = true; +} catch (exc) { + assertEq(exc instanceof SyntaxError, true); +} + +// If not, run these tests. (Many other tests cover actual behavior of the +// feature when enabled.) +if (!fieldsEnabled) { + let source = `class C { + x + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + x = 0; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + 0 = 0; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + [0] = 0; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + "hi" = 0; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + "hi" = 0; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + d = function(){}; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); + + source = `class C { + d = class D { x = 0; }; + }`; + assertThrowsInstanceOf(() => Function(source), SyntaxError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |