Unify PreParser::ParseIdentifierName and Parser::ParseIdentifierName.
authormarja@chromium.org <marja@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 7 Feb 2014 08:45:28 +0000 (08:45 +0000)
committermarja@chromium.org <marja@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 7 Feb 2014 08:45:28 +0000 (08:45 +0000)
No special handling for keywords is needed, since the literal ascii strings for
them work too (see how Parser did it).

BUG=3126
LOG=N
R=ulan@chromium.org

Review URL: https://codereview.chromium.org/152853006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19184 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/preparser.cc
test/cctest/test-parsing.cc

index b1f2348..4182c8c 100644 (file)
@@ -1536,19 +1536,15 @@ void PreParser::StrictModeIdentifierViolation(Scanner::Location location,
 
 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) {
   Token::Value next = Next();
-  if (Token::IsKeyword(next)) {
-    int pos = position();
-    const char* keyword = Token::String(next);
-    log_->LogAsciiSymbol(pos, Vector<const char>(keyword, StrLength(keyword)));
+  if (next != Token::IDENTIFIER &&
+      next != Token::FUTURE_RESERVED_WORD &&
+      next != Token::FUTURE_STRICT_RESERVED_WORD &&
+      !Token::IsKeyword(next)) {
+    ReportUnexpectedToken(next);
+    *ok = false;
     return Identifier::Default();
   }
-  if (next == Token::IDENTIFIER ||
-      next == Token::FUTURE_RESERVED_WORD ||
-      next == Token::FUTURE_STRICT_RESERVED_WORD) {
-    return GetIdentifierSymbol();
-  }
-  *ok = false;
-  return Identifier::Default();
+  return GetIdentifierSymbol();
 }
 
 #undef CHECK_OK
index 9768e30..d79f594 100644 (file)
@@ -1831,3 +1831,46 @@ TEST(NoErrorsParenthesizedDirectivePrologue) {
 
   RunParserSyncTest(context_data, statement_data, kSuccess);
 }
+
+
+TEST(ErrorsNotAnIdentifierName) {
+  const char* context_data[][2] = {
+    { "", ""},
+    { "\"use strict\";", ""},
+    { NULL, NULL }
+  };
+
+  const char* statement_data[] = {
+    "var foo = {}; foo.{;",
+    "var foo = {}; foo.};",
+    "var foo = {}; foo.=;",
+    "var foo = {}; foo.888;",
+    "var foo = {}; foo.-;",
+    "var foo = {}; foo.--;",
+    NULL
+  };
+
+  RunParserSyncTest(context_data, statement_data, kError);
+}
+
+
+TEST(NoErrorsIdentifierNames) {
+  // Keywords etc. are valid as property names.
+  const char* context_data[][2] = {
+    { "", ""},
+    { "\"use strict\";", ""},
+    { NULL, NULL }
+  };
+
+  const char* statement_data[] = {
+    "var foo = {}; foo.if;",
+    "var foo = {}; foo.yield;",
+    "var foo = {}; foo.super;",
+    "var foo = {}; foo.interface;",
+    "var foo = {}; foo.eval;",
+    "var foo = {}; foo.arguments;",
+    NULL
+  };
+
+  RunParserSyncTest(context_data, statement_data, kSuccess);
+}