Reviewers: ulan,

Message:
Committed patchset #1 manually as r19184 (presubmit successful).

Description:
Unify PreParser::ParseIdentifierName and Parser::ParseIdentifierName.

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
[email protected]

Committed: https://code.google.com/p/v8/source/detail?r=19184

Please review this at https://codereview.chromium.org/152853006/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+50, -11 lines):
  M src/preparser.cc
  M test/cctest/test-parsing.cc


Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index b1f2348701c8d2b1bd42a0d7a9a6aa221f1c62e0..4182c8c247b0559e145d3aef94393040061bf3b9 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -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: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 9768e30a55a6eac19f666e03f98a8a4c65f77d8d..d79f59464741121a09b086b8f2ebc5abccb8bb61 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -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);
+}


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to