Bug 1611777 - Part 1: Report syntax error for optional property access in self-hosting code. r=yulia
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 29 Jan 2020 16:22:09 +0000
changeset 512092 bdb8620ff7f53ce13ec9166338685221e10c4f16
parent 512091 f567747993a768266230a07deec085c690e8fa37
child 512093 45f7fa06cc3c87cc2896668ee58a7b4a738520f0
push id37072
push usercsabou@mozilla.com
push dateThu, 30 Jan 2020 15:44:43 +0000
treeherdermozilla-central@f97c48da9cee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1611777
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 1611777 - Part 1: Report syntax error for optional property access in self-hosting code. r=yulia We already assert that this case isn't allowed in the bytecode emitter. Also report a syntax error to match normal property access. Differential Revision: https://phabricator.services.mozilla.com/D61146
js/src/frontend/FullParseHandler.h
js/src/frontend/Parser.cpp
js/src/frontend/SyntaxParseHandler.h
--- a/js/src/frontend/FullParseHandler.h
+++ b/js/src/frontend/FullParseHandler.h
@@ -72,16 +72,21 @@ class FullParseHandler {
 
   using NullNode = std::nullptr_t;
 
   bool isPropertyAccess(Node node) {
     return node->isKind(ParseNodeKind::DotExpr) ||
            node->isKind(ParseNodeKind::ElemExpr);
   }
 
+  bool isOptionalPropertyAccess(Node node) {
+    return node->isKind(ParseNodeKind::OptionalDotExpr) ||
+           node->isKind(ParseNodeKind::OptionalElemExpr);
+  }
+
   bool isFunctionCall(Node node) {
     // Note: super() is a special form, *not* a function call.
     return node->isKind(ParseNodeKind::CallExpr);
   }
 
   static bool isUnparenthesizedDestructuringPattern(Node node) {
     return !node->isInParens() && (node->isKind(ParseNodeKind::ObjectExpr) ||
                                    node->isKind(ParseNodeKind::ArrayExpr));
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -9500,17 +9500,18 @@ typename ParseHandler::Node GeneralParse
   return handler_.newSetThis(thisName, superCall);
 }
 
 template <class ParseHandler, typename Unit>
 typename ParseHandler::Node GeneralParser<ParseHandler, Unit>::memberCall(
     TokenKind tt, Node lhs, YieldHandling yieldHandling,
     PossibleError* possibleError /* = nullptr */,
     OptionalKind optionalKind /* = OptionalKind::NonOptional */) {
-  if (options().selfHostingMode && handler_.isPropertyAccess(lhs)) {
+  if (options().selfHostingMode && (handler_.isPropertyAccess(lhs) ||
+                                    handler_.isOptionalPropertyAccess(lhs))) {
     error(JSMSG_SELFHOSTED_METHOD_CALL);
     return null();
   }
 
   MOZ_ASSERT(tt == TokenKind::LeftParen || tt == TokenKind::TemplateHead ||
                  tt == TokenKind::NoSubsTemplate,
              "Unexpected token kind for member call");
 
--- a/js/src/frontend/SyntaxParseHandler.h
+++ b/js/src/frontend/SyntaxParseHandler.h
@@ -150,16 +150,20 @@ class SyntaxParseHandler {
   bool isNonArrowFunctionExpression(Node node) const {
     return node == NodeFunctionExpression;
   }
 
   bool isPropertyAccess(Node node) {
     return node == NodeDottedProperty || node == NodeElement;
   }
 
+  bool isOptionalPropertyAccess(Node node) {
+    return node == NodeOptionalDottedProperty || node == NodeOptionalElement;
+  }
+
   bool isFunctionCall(Node node) {
     // Note: super() is a special form, *not* a function call.
     return node == NodeFunctionCall;
   }
 
   static bool isUnparenthesizedDestructuringPattern(Node node) {
     return node == NodeUnparenthesizedArray ||
            node == NodeUnparenthesizedObject;