Chromium Code Reviews| Index: src/preparser.cc |
| diff --git a/src/preparser.cc b/src/preparser.cc |
| index c0dcc0b4a1df3bdc9512c22341276be220e2468a..809e78308b3cc200ba2f8ecf76dc974e3a51ab66 100644 |
| --- a/src/preparser.cc |
| +++ b/src/preparser.cc |
| @@ -83,6 +83,7 @@ void PreParser::ReportUnexpectedToken(i::Token::Value token) { |
| return ReportMessageAt(source_location.beg_pos, source_location.end_pos, |
| "unexpected_token_string", NULL); |
| case i::Token::IDENTIFIER: |
| + case i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD: |
| return ReportMessageAt(source_location.beg_pos, source_location.end_pos, |
| "unexpected_token_identifier", NULL); |
| default: |
| @@ -790,7 +791,7 @@ PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression( |
| Expression result = kUnknownExpression; |
| if (peek() == i::Token::FUNCTION) { |
| Consume(i::Token::FUNCTION); |
| - if (peek() == i::Token::IDENTIFIER) { |
| + if (peek_any_identifier()) { |
| ParseIdentifier(CHECK_OK); |
| } |
| result = ParseFunctionLiteral(CHECK_OK); |
| @@ -858,7 +859,8 @@ PreParser::Expression PreParser::ParsePrimaryExpression(bool* ok) { |
| break; |
| } |
| - case i::Token::IDENTIFIER: { |
| + case i::Token::IDENTIFIER: |
| + case i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD: { |
| ParseIdentifier(CHECK_OK); |
| result = kIdentifierExpression; |
| break; |
| @@ -946,7 +948,8 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) { |
| while (peek() != i::Token::RBRACE) { |
| i::Token::Value next = peek(); |
| switch (next) { |
| - case i::Token::IDENTIFIER: { |
| + case i::Token::IDENTIFIER: |
| + case i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD: { |
|
Lasse Reichstein
2011/02/03 11:42:48
If it's a future reserved word, we know that it's
Peter Hallam
2011/02/04 18:32:41
True, however this way the code in the preparser i
|
| bool is_getter = false; |
| bool is_setter = false; |
| ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); |
| @@ -954,6 +957,7 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) { |
| i::Token::Value name = Next(); |
| bool is_keyword = i::Token::IsKeyword(name); |
| if (name != i::Token::IDENTIFIER && |
| + name != i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD && |
| name != i::Token::NUMBER && |
| name != i::Token::STRING && |
| !is_keyword) { |
| @@ -1151,7 +1155,9 @@ PreParser::Expression PreParser::GetStringSymbol() { |
| PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { |
| - Expect(i::Token::IDENTIFIER, ok); |
| + if (!Check(i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD)) { |
| + Expect(i::Token::IDENTIFIER, ok); |
| + } |
| if (!*ok) return kUnknownIdentifier; |
| return GetIdentifierSymbol(); |
| } |
| @@ -1166,7 +1172,8 @@ PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { |
| i::StrLength(keyword))); |
| return kUnknownExpression; |
| } |
| - if (next == i::Token::IDENTIFIER) { |
| + if (next == i::Token::IDENTIFIER || |
| + next == i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD) { |
| return GetIdentifierSymbol(); |
| } |
| *ok = false; |
| @@ -1175,19 +1182,24 @@ PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { |
| // This function reads an identifier and determines whether or not it |
| -// is 'get' or 'set'. The reason for not using ParseIdentifier and |
| -// checking on the output is that this involves heap allocation which |
| -// we can't do during preparsing. |
| +// is 'get' or 'set'. The reason for not using the result of ParseIdentifier |
| +// is that this involves heap allocation which we can't do during preparsing. |
| PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get, |
| bool* is_set, |
| bool* ok) { |
| - Expect(i::Token::IDENTIFIER, CHECK_OK); |
| + PreParser::Identifier result = ParseIdentifier(CHECK_OK); |
| if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) { |
| const char* token = scanner_->literal_ascii_string().start(); |
| *is_get = strncmp(token, "get", 3) == 0; |
| *is_set = !*is_get && strncmp(token, "set", 3) == 0; |
| } |
| - return GetIdentifierSymbol(); |
| + return result; |
| +} |
| + |
| +bool PreParser::peek_any_identifier() { |
| + i::Token::Value next = peek(); |
| + return next == i::Token::IDENTIFIER || |
| + next == i::Token::IDENTIFIER_OR_FUTURE_RESERVED_WORD; |
| } |
| #undef CHECK_OK |