diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/async-functions/syntax-arrow.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/async-functions/syntax-arrow.js | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/js/src/tests/non262/async-functions/syntax-arrow.js b/js/src/tests/non262/async-functions/syntax-arrow.js new file mode 100644 index 0000000000..a2c96e7dd9 --- /dev/null +++ b/js/src/tests/non262/async-functions/syntax-arrow.js @@ -0,0 +1,104 @@ +var BUGNUMBER = 1185106; +var summary = "async arrow function syntax"; + +print(BUGNUMBER + ": " + summary); + +if (typeof Reflect !== "undefined" && Reflect.parse) { + // Parameters. + Reflect.parse("async () => 1"); + Reflect.parse("async a => 1"); + Reflect.parse("async (a) => 1"); + Reflect.parse("async async => 1"); + Reflect.parse("async (async) => 1"); + Reflect.parse("async ([a]) => 1"); + Reflect.parse("async ([a, b]) => 1"); + Reflect.parse("async ({a}) => 1"); + Reflect.parse("async ({a, b}) => 1"); + + assertThrowsInstanceOf(() => Reflect.parse("async await => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async (await) => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async ([await]) => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async ({await}) => 1"), SyntaxError); + + assertThrowsInstanceOf(() => Reflect.parse("async (a=await) => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async ([a=await]) => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async ({a=await}) => 1"), SyntaxError); + + assertThrowsInstanceOf(() => Reflect.parse("async (a=await 1) => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async ([a=await 1]) => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async ({a=await 1}) => 1"), SyntaxError); + + assertThrowsInstanceOf(() => Reflect.parse("async [a] => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async [a, b] => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async {a} => 1"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async {a: b} => 1"), SyntaxError); + + // Expression body. + Reflect.parse("async a => a == b"); + + // Expression body with nested async function. + Reflect.parse("async a => async"); + Reflect.parse("async a => async b => c"); + Reflect.parse("async a => async function() {}"); + Reflect.parse("async a => async function b() {}"); + + assertThrowsInstanceOf(() => Reflect.parse("async a => async b"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async a => async function"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async a => async function()"), SyntaxError); + + // Expression body with `await`. + Reflect.parse("async a => await 1"); + Reflect.parse("async a => await await 1"); + Reflect.parse("async a => await await await 1"); + + assertThrowsInstanceOf(() => Reflect.parse("async a => await"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("async a => await await"), SyntaxError); + + // `await` is Unary Expression and it cannot have `async` function as an + // operand. + assertThrowsInstanceOf(() => Reflect.parse("async a => await async X => Y"), SyntaxError); + Reflect.parse("async a => await (async X => Y)"); + // But it can have `async` identifier as an operand. + Reflect.parse("async async => await async"); + + // Block body. + Reflect.parse("async X => {yield}"); + + // `yield` handling. + Reflect.parse("async X => yield"); + Reflect.parse("async yield => X"); + Reflect.parse("async yield => yield"); + Reflect.parse("async X => {yield}"); + + Reflect.parse("async X => {yield}"); + Reflect.parse("async yield => {X}"); + Reflect.parse("async yield => {yield}"); + Reflect.parse("function* g() { async X => yield }"); + + assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async yield => X"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async (yield) => X"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async X => yield"), SyntaxError); + assertThrowsInstanceOf(() => Reflect.parse("'use strict'; async X => {yield}"), SyntaxError); + + assertThrows(() => Reflect.parse("function* g() { async yield => X }")); + assertThrows(() => Reflect.parse("function* g() { async (yield) => X }")); + assertThrows(() => Reflect.parse("function* g() { async ([yield]) => X }")); + assertThrows(() => Reflect.parse("function* g() { async ({yield}) => X }")); + + // Not async functions. + Reflect.parse("async ()"); + Reflect.parse("async (a)"); + Reflect.parse("async (async)"); + Reflect.parse("async ([a])"); + Reflect.parse("async ([a, b])"); + Reflect.parse("async ({a})"); + Reflect.parse("async ({a, b})"); + + // Async arrow function is assignment expression. + Reflect.parse("a ? async () => {1} : b"); + Reflect.parse("a ? b : async () => {1}"); + assertThrowsInstanceOf(() => Reflect.parse("async () => {1} ? a : b"), SyntaxError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |