From: marja@chromium.org Date: Fri, 7 Feb 2014 08:45:28 +0000 (+0000) Subject: Unify PreParser::ParseIdentifierName and Parser::ParseIdentifierName. X-Git-Tag: upstream/4.7.83~10825 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b890419f54735a05420f3d8fbf4146200a6434b;p=platform%2Fupstream%2Fv8.git 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 --- diff --git a/src/preparser.cc b/src/preparser.cc index b1f2348..4182c8c 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(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 diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index 9768e30..d79f594 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); +}