Bug 1345960 - Handle shorthand property and destructuring with async keyword properly. r=shu a=gchang
authorTooru Fujisawa <arai_a@mac.com>
Fri, 10 Mar 2017 13:21:35 +0900
changeset 395125 bf077c4f7cb2bd2e3517364bc5ebb9d0417ef5b3
parent 395124 8acbaea575e2bc8c14bdeb251a040f1290b8b240
child 395126 c0bf6c139974a4c1f4ce59d88971758f6ab85557
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu, gchang
bugs1345960
milestone54.0a2
Bug 1345960 - Handle shorthand property and destructuring with async keyword properly. r=shu a=gchang
js/src/frontend/Parser.cpp
js/src/tests/ecma_2017/AsyncFunctions/property.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -9248,24 +9248,39 @@ Parser<ParseHandler>::propertyName(Yield
     bool isAsync = false;
     if (ltok == TOK_MUL) {
         isGenerator = true;
         if (!tokenStream.getToken(&ltok))
             return null();
     }
 
     if (ltok == TOK_ASYNC) {
-        TokenKind tt;
-        if (!tokenStream.getToken(&tt))
-            return null();
-        if (tt != TOK_LP && tt != TOK_COLON && tt != TOK_RC && tt != TOK_ASSIGN) {
+        // AsyncMethod[Yield, Await]:
+        //   async [no LineTerminator here] PropertyName[?Yield, ?Await] ...
+        //
+        // PropertyName:
+        //   LiteralPropertyName
+        //   ComputedPropertyName[?Yield, ?Await]
+        //
+        // LiteralPropertyName:
+        //   IdentifierName
+        //   StringLiteral
+        //   NumericLiteral
+        //
+        // ComputedPropertyName[Yield, Await]:
+        //   [ ...
+        TokenKind tt = TOK_EOF;
+        if (!tokenStream.peekTokenSameLine(&tt))
+            return null();
+        if (tt == TOK_STRING || tt == TOK_NUMBER || tt == TOK_LB ||
+            TokenKindIsPossibleIdentifierName(tt))
+        {
             isAsync = true;
+            tokenStream.consumeKnownToken(tt);
             ltok = tt;
-        } else {
-            tokenStream.ungetToken();
         }
     }
 
     if (isAsync && isGenerator) {
         error(JSMSG_ASYNC_GENERATOR);
         return null();
     }
 
--- a/js/src/tests/ecma_2017/AsyncFunctions/property.js
+++ b/js/src/tests/ecma_2017/AsyncFunctions/property.js
@@ -30,10 +30,20 @@ print(BUGNUMBER + ": " + summary);
   assertEq(async, 13);
 }
 
 {
   let { async: a = 14 } = {};
   assertEq(a, 14);
 }
 
+{
+  let { async, other } = { async: 15, other: 16 };
+  assertEq(async, 15);
+  assertEq(other, 16);
+
+  let a = { async, other };
+  assertEq(a.async, 15);
+  assertEq(a.other, 16);
+}
+
 if (typeof reportCompare === "function")
     reportCompare(true, true);