Commit 5b890419 authored by marja@chromium.org's avatar marja@chromium.org

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
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
parent cb6e1b45
......@@ -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
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment