Bug 1314128 - Do not parse await expression in module. r=till
authorTooru Fujisawa <arai_a@mac.com>
Tue, 01 Nov 2016 16:53:50 +0900
changeset 320406 d2526689ef032790ef20dd129e054b5bbc60b458
parent 320405 4561836d44dcadefc813936a194fb42567a0ab2b
child 320407 c49ec67995bcee88868679ff1e8410bb980393ef
push id83373
push userarai_a@mac.com
push dateTue, 01 Nov 2016 07:54:41 +0000
treeherdermozilla-inbound@d2526689ef03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1314128
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1314128 - Do not parse await expression in module. r=till
js/src/frontend/Parser.cpp
js/src/tests/ecma_7/AsyncFunctions/syntax-modules.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -7952,16 +7952,23 @@ Parser<ParseHandler>::unaryExpr(YieldHan
                 return null();
             pc->sc()->setBindingsAccessedDynamically();
         }
 
         return handler.newDelete(begin, expr);
       }
 
       case TOK_AWAIT: {
+        if (!pc->isAsync()) {
+            // TOK_AWAIT can be returned in module, even if it's not inside
+            // async function.
+            report(ParseError, false, null(), JSMSG_RESERVED_ID, "await");
+            return null();
+        }
+
         TokenKind nextSameLine = TOK_EOF;
         if (!tokenStream.peekTokenSameLine(&nextSameLine, TokenStream::Operand))
             return null();
         if (nextSameLine != TOK_EOL) {
             Node kid = unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked);
             if (!kid)
                 return null();
             pc->lastAwaitOffset = begin;
--- a/js/src/tests/ecma_7/AsyncFunctions/syntax-modules.js
+++ b/js/src/tests/ecma_7/AsyncFunctions/syntax-modules.js
@@ -2,17 +2,22 @@ var BUGNUMBER = 1185106;
 var summary = "async/await syntax in module";
 
 print(BUGNUMBER + ": " + summary);
 
 if (typeof parseModule === "function") {
     parseModule("async function f() { await 3; }");
     parseModule("async function f() { await 3; }");
     assertThrows(() => parseModule("var await = 5;"), SyntaxError);
+    assertThrows(() => parseModule("await;"), SyntaxError);
+    assertThrows(() => parseModule("await 5;"), SyntaxError);
+    assertThrows(() => parseModule("function f() { await 5; }"), SyntaxError);
+    assertThrows(() => parseModule("() => { await 5; }"), SyntaxError);
     assertThrows(() => parseModule("export var await;"), SyntaxError);
+    assertThrows(() => parseModule("await => 1;"), SyntaxError);
     assertThrows(() => parseModule("async function f() { function g() { await 3; } }"), SyntaxError);
 
     if (typeof Reflect !== "undefined" && Reflect.parse) {
         assertThrows(() => Reflect.parse("export default async function() { yield; }", { target: "module" }), SyntaxError);
         assertThrows(() => Reflect.parse("export default async function() { yield = 1; }", { target: "module" }), SyntaxError);
     }
 }