Bug 1607050 - Parse await as an identifier in fields initializers r=anba
authorNicolò Ribaudo <nicolo.ribaudo@gmail.com>
Wed, 29 Jan 2020 07:33:39 +0000
changeset 512052 1de45bb038fca66a8413838e3118f3b47559f995
parent 512051 0d06c43eb924e3e733a6347a02f0750b112a19c3
child 512053 70615b052db52c0a7c4e9ff54aecb1b73d440f5f
push id37068
push usernerli@mozilla.com
push dateWed, 29 Jan 2020 15:51:04 +0000
treeherdermozilla-central@019ae805259f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanba
bugs1607050
milestone74.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 1607050 - Parse await as an identifier in fields initializers r=anba The proposal specifies class fields as follows: FieldDefinition[Yield, Await]: ClassElementName[?Yield, ?Await] Initializer[In, ~Yield, ~Await]opt This means that await shouldn't be parsed according to the context where the class is defined: it should always be parsed as an identifier inside initializers. Differential Revision: https://phabricator.services.mozilla.com/D58721
js/src/frontend/Parser.cpp
js/src/tests/non262/fields/await-identifier-module-1.js
js/src/tests/non262/fields/await-identifier-module-2.js
js/src/tests/non262/fields/await-identifier-module-3.js
js/src/tests/non262/fields/await-identifier-script.js
js/src/tests/non262/fields/browser.js
js/src/tests/non262/fields/shell.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -7603,19 +7603,22 @@ GeneralParser<ParseHandler, Unit>::field
   }
 
   pc_->functionScope().useAsVarScope(pc_);
 
   Node initializerExpr;
   TokenPos wholeInitializerPos;
   if (hasInitializer) {
     // Parse the expression for the field initializer.
-    initializerExpr = assignExpr(InAllowed, yieldHandling, TripledotProhibited);
-    if (!initializerExpr) {
-      return null();
+    {
+      AutoAwaitIsKeyword awaitHandling(this, AwaitIsName);
+      initializerExpr = assignExpr(InAllowed, YieldIsName, TripledotProhibited);
+      if (!initializerExpr) {
+        return null();
+      }
     }
 
     handler_.checkAndSetIsDirectRHSAnonFunction(initializerExpr);
 
     wholeInitializerPos = pos();
     wholeInitializerPos.begin = firstTokenPos.begin;
   } else {
     initializerExpr = handler_.newRawUndefinedLiteral(firstTokenPos);
new file mode 100644
--- /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 };
new file mode 100644
--- /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 };
new file mode 100644
--- /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 };
new file mode 100644
--- /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);
new file mode 100644
new file mode 100644