Revision: 19184
Author: [email protected]
Date: Fri Feb 7 08:45:28 2014 UTC
Log: 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]
Review URL: https://codereview.chromium.org/152853006
http://code.google.com/p/v8/source/detail?r=19184
Modified:
/branches/bleeding_edge/src/preparser.cc
/branches/bleeding_edge/test/cctest/test-parsing.cc
=======================================
--- /branches/bleeding_edge/src/preparser.cc Thu Feb 6 15:10:21 2014 UTC
+++ /branches/bleeding_edge/src/preparser.cc Fri Feb 7 08:45:28 2014 UTC
@@ -1536,19 +1536,15 @@
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
=======================================
--- /branches/bleeding_edge/test/cctest/test-parsing.cc Thu Feb 6 13:12:10
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-parsing.cc Fri Feb 7 08:45:28
2014 UTC
@@ -1831,3 +1831,46 @@
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.