Bug 1185106 - Part 10.3: Add parser test for async arrow function. r=efaust,till draft
authorTooru Fujisawa <arai_a@mac.com>
Sun, 28 Aug 2016 23:58:30 +0900
changeset 430945 e5b0b573c32495ce13e17a56ef3bbac54e9ae17b
parent 430944 e96660f72e30612b727784e909a16f0b3e2e0c34
child 430946 266e4d69e518917b87cbf5788f73e04345d146b6
push id33945
push userarai_a@mac.com
push dateFri, 28 Oct 2016 11:34:02 +0000
reviewersefaust, till
bugs1185106
milestone52.0a1
Bug 1185106 - Part 10.3: Add parser test for async arrow function. r=efaust,till MozReview-Commit-ID: 1HCDc8Z1BJU
js/src/jit-test/lib/syntax.js
js/src/tests/ecma_7/AsyncFunctions/syntax-arrow.js
js/src/tests/ecma_7/AsyncFunctions/syntax.js
js/src/tests/js1_8_5/reflect-parse/async.js
--- a/js/src/jit-test/lib/syntax.js
+++ b/js/src/jit-test/lib/syntax.js
@@ -1303,10 +1303,65 @@ function test_syntax(postfixes, check_er
     test("class X { async m() {} ");
 
     test("class X { static async ");
     test("class X { static async m ");
     test("class X { static async m( ");
     test("class X { static async m() ");
     test("class X { static async m() { ");
     test("class X { static async m() {} ");
+
+    // async/await arrow
+
+    test("(async a ");
+    test("(async a => ");
+    test("(async a => b ");
+    test("(async a => b) ");
+
+    test("(async a => { ");
+    test("(async a => { b ");
+    test("(async a => { b } ");
+    test("(async a => { b }) ");
+
+    test("(async ( ");
+    test("(async (a ");
+    test("(async (a) ");
+    test("(async (a) => ");
+    test("(async (a) => b ");
+    test("(async (a) => b) ");
+    test("(async (a, ");
+    test("(async (a, b ");
+    test("(async (a, b) ");
+    test("(async (a, b) => ");
+    test("(async (a, b) => b ");
+    test("(async (a, b) => b) ");
+
+    test("(async ([ ");
+    test("(async ([a ");
+    test("(async ([a] ");
+    test("(async ([a]) ");
+    test("(async ([a]) => ");
+    test("(async ([a]) => b ");
+    test("(async ([a]) => b) ");
+    test("(async ([a, ");
+    test("(async ([a, b ");
+    test("(async ([a, b] ");
+    test("(async ([a, b]) ");
+    test("(async ([a, b]) => ");
+    test("(async ([a, b]) => b ");
+    test("(async ([a, b]) => b) ");
+
+    test("(async ({ ");
+    test("(async ({a ");
+    test("(async ({a} ");
+    test("(async ({a}) ");
+    test("(async ({a}) => ");
+    test("(async ({a}) => b ");
+    test("(async ({a}) => b) ");
+    test("(async ({a, ");
+    test("(async ({a, b ");
+    test("(async ({a, b} ");
+    test("(async ({a, b}) ");
+    test("(async ({a, b}) => ");
+    test("(async ({a, b}) => b ");
+    test("(async ({a, b}) => b) ");
   }
 }
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_7/AsyncFunctions/syntax-arrow.js
@@ -0,0 +1,104 @@
+var BUGNUMBER = 1185106;
+var summary = "async arrow function syntax";
+
+print(BUGNUMBER + ": " + summary);
+
+if (asyncFunctionsEnabled() && 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");
+
+    assertThrows(() => Reflect.parse("async await => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async (await) => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async ([await]) => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async ({await}) => 1"), SyntaxError);
+
+    assertThrows(() => Reflect.parse("async (a=await) => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async ([a=await]) => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async ({a=await}) => 1"), SyntaxError);
+
+    assertThrows(() => Reflect.parse("async (a=await 1) => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async ([a=await 1]) => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async ({a=await 1}) => 1"), SyntaxError);
+
+    assertThrows(() => Reflect.parse("async [a] => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async [a, b] => 1"), SyntaxError);
+    assertThrows(() => Reflect.parse("async {a} => 1"), SyntaxError);
+    assertThrows(() => 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() {}");
+
+    assertThrows(() => Reflect.parse("async a => async b"), SyntaxError);
+    assertThrows(() => Reflect.parse("async a => async function"), SyntaxError);
+    assertThrows(() => 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");
+
+    assertThrows(() => Reflect.parse("async a => await"), SyntaxError);
+    assertThrows(() => Reflect.parse("async a => await await"), SyntaxError);
+
+    // `await` is Unary Expression and it cannot have `async` function as an
+    // operand.
+    assertThrows(() => 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 }");
+
+    assertThrows(() => Reflect.parse("'use strict'; async yield => X"), SyntaxError);
+    assertThrows(() => Reflect.parse("'use strict'; async (yield) => X"), SyntaxError);
+    assertThrows(() => Reflect.parse("'use strict'; async X => yield"), SyntaxError);
+    assertThrows(() => 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}");
+    assertThrows(() => Reflect.parse("async () => {1} ? a : b"), SyntaxError);
+}
+
+if (typeof reportCompare === "function")
+    reportCompare(true, true);
--- a/js/src/tests/ecma_7/AsyncFunctions/syntax.js
+++ b/js/src/tests/ecma_7/AsyncFunctions/syntax.js
@@ -2,16 +2,17 @@ var BUGNUMBER = 1185106;
 var summary = "async/await syntax";
 
 print(BUGNUMBER + ": " + summary);
 
 if (asyncFunctionsEnabled() && typeof Reflect !== "undefined" && Reflect.parse) {
     assertEq(Reflect.parse("function a() {}").body[0].async, false);
     assertEq(Reflect.parse("function* a() {}").body[0].async, false);
     assertEq(Reflect.parse("async function a() {}").body[0].async, true);
+    assertEq(Reflect.parse("() => {}").body[0].async, undefined);
 
     // Async generators are not allowed (with regards to spec)
     assertThrows(() => Reflect.parse("async function* a() {}"), SyntaxError);
 
     // No line terminator after async
     assertEq(Reflect.parse("async\nfunction a(){}").body[0].expression.name, "async");
 
     // Async function expressions
--- a/js/src/tests/js1_8_5/reflect-parse/async.js
+++ b/js/src/tests/js1_8_5/reflect-parse/async.js
@@ -12,16 +12,21 @@ function asyncFunctionsEnabled() {
 if (asyncFunctionsEnabled()) {
     // async function declaration.
     assertDecl("async function foo() {}", asyncFunDecl(ident("foo"), [], blockStmt([])));
 
     // async function expression.
     assertExpr("(async function() {})", asyncFunExpr(null, [], blockStmt([])));
     assertExpr("(async function foo() {})", asyncFunExpr(ident("foo"), [], blockStmt([])));
 
+    // async arrow.
+    assertExpr("async a => 1", asyncArrowExpr(true, [ident("a")], literal(1)));
+    assertExpr("async a => { 1 }", asyncArrowExpr(false, [ident("a")], blockStmt([exprStmt(literal(1))])));
+    assertExpr("async a => { return 1 }", asyncArrowExpr(false, [ident("a")], blockStmt([returnStmt(literal(1))])));
+
     // async method.
     assertExpr("({ async foo() {} })", objExpr([{ key: ident("foo"), value: asyncFunExpr(ident("foo"), [], blockStmt([]))}]));
 
     assertStmt("class C { async foo() {} }", classStmt(ident("C"), null, [classMethod(ident("foo"), asyncFunExpr(ident("foo"), [], blockStmt([])), "method", false)]));
     assertStmt("class C { static async foo() {} }", classStmt(ident("C"), null, [classMethod(ident("foo"), asyncFunExpr(ident("foo"), [], blockStmt([])), "method", true)]));
 
     // await expression.
     assertDecl("async function foo() { await bar }", asyncFunDecl(ident("foo"), [], blockStmt([exprStmt(unExpr("await", ident("bar")))])));