Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 8bbd9e688ccb6adcf2b8e80a890e17fb5c4e71e8..5c66b7c9acd6479399dd11c855abb86feac81a48 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -654,6 +654,20 @@ class ParserBase : public Traits { |
| scanner()->peek_location(), message, arg); |
| } |
| + bool IsNextEscapedReservedWord() { |
| + return scanner()->IsNextEscapedReservedWord(language_mode(), |
| + this->is_generator()); |
| + } |
| + |
| + void CheckNextEscapedKeyword(bool* ok) { |
| + if (IsNextEscapedReservedWord()) { |
| + Next(); |
|
caitp (gmail)
2015/11/04 05:03:37
Next() added to prevent a DCHECK() from crashing t
|
| + ReportMessageAt(scanner()->location(), |
| + MessageTemplate::kInvalidEscapedReservedWord); |
| + *ok = false; |
| + } |
| + } |
| + |
| // Recursive descent functions: |
| // Parses an identifier that is valid for the current scope, in particular it |
| @@ -685,6 +699,7 @@ class ParserBase : public Traits { |
| ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); |
| ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| bool* is_static, bool* is_computed_name, |
| + bool* is_identifier, bool* is_escaped_keyword, |
| ExpressionClassifier* classifier, bool* ok); |
| ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
| ObjectLiteralPropertyT ParsePropertyDefinition( |
| @@ -2268,6 +2283,14 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| break; |
| case Token::IDENTIFIER: |
| + if (IsNextEscapedReservedWord()) { |
| + classifier->RecordExpressionError( |
| + scanner()->peek_location(), |
| + MessageTemplate::kInvalidEscapedReservedWord); |
| + classifier->RecordBindingPatternError( |
| + scanner()->peek_location(), |
| + MessageTemplate::kInvalidEscapedReservedWord); |
| + } |
| case Token::LET: |
| case Token::STATIC: |
| case Token::YIELD: |
| @@ -2547,7 +2570,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral( |
| template <class Traits> |
| typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
| IdentifierT* name, bool* is_get, bool* is_set, bool* is_static, |
| - bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { |
| + bool* is_computed_name, bool* is_identifier, bool* is_escaped_keyword, |
| + ExpressionClassifier* classifier, bool* ok) { |
| Token::Value token = peek(); |
| int pos = peek_position(); |
| @@ -2593,6 +2617,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
| // Fall through. |
| default: |
| + *is_identifier = true; |
| + *is_escaped_keyword = IsNextEscapedReservedWord(); |
| *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
| break; |
| } |
| @@ -2621,8 +2647,11 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| Token::Value name_token = peek(); |
| int next_beg_pos = scanner()->peek_location().beg_pos; |
| int next_end_pos = scanner()->peek_location().end_pos; |
| + bool is_identifier = false; |
| + bool is_escaped_keyword = false; |
| ExpressionT name_expression = ParsePropertyName( |
| - &name, &is_get, &is_set, &name_is_static, is_computed_name, classifier, |
| + &name, &is_get, &is_set, &name_is_static, is_computed_name, |
| + &is_identifier, &is_escaped_keyword, classifier, |
| CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| if (fni_ != nullptr && !*is_computed_name) { |
| @@ -2646,16 +2675,28 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| *is_computed_name); |
| } |
| - if (Token::IsIdentifier(name_token, language_mode(), |
| - this->is_generator()) && |
| - (peek() == Token::COMMA || peek() == Token::RBRACE || |
| - peek() == Token::ASSIGN)) { |
| + if (is_identifier && (peek() == Token::COMMA || peek() == Token::RBRACE || |
| + peek() == Token::ASSIGN)) { |
| // PropertyDefinition |
| // IdentifierReference |
| // CoverInitializedName |
| // |
| // CoverInitializedName |
| // IdentifierReference Initializer? |
| + if (!Token::IsIdentifier(name_token, language_mode(), |
| + this->is_generator())) { |
| + ReportUnexpectedTokenAt(scanner()->location(), name_token); |
| + *ok = false; |
| + return this->EmptyObjectLiteralProperty(); |
| + } |
| + if (is_escaped_keyword) { |
| + classifier->RecordExpressionError( |
| + scanner()->location(), |
| + MessageTemplate::kInvalidEscapedReservedWord); |
| + classifier->RecordBindingPatternError( |
| + scanner()->location(), |
| + MessageTemplate::kInvalidEscapedReservedWord); |
| + } |
| if (classifier->duplicate_finder() != nullptr && |
| scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
| classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
| @@ -2737,8 +2778,8 @@ ParserBase<Traits>::ParsePropertyDefinition( |
| name_token = peek(); |
| name_expression = ParsePropertyName( |
| - &name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
| - CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| + &name, &dont_care, &dont_care, &dont_care, is_computed_name, &dont_care, |
| + &dont_care, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
| if (!*is_computed_name) { |
| checker->CheckProperty(name_token, kAccessorProperty, is_static, |