Index: src/preparser.h |
diff --git a/src/preparser.h b/src/preparser.h |
index 8bbd9e688ccb6adcf2b8e80a890e17fb5c4e71e8..6e70b225f053b2d04d530e1922ae4fc48db4fac0 100644 |
--- a/src/preparser.h |
+++ b/src/preparser.h |
@@ -654,6 +654,19 @@ class ParserBase : public Traits { |
scanner()->peek_location(), message, arg); |
} |
+ bool IsNextEscapedReservedWord() { |
+ return scanner()->IsNextEscapedReservedWord( |
+ language_mode(), this->is_generator(), allow_harmony_sloppy_let()); |
caitp (gmail)
2015/11/03 17:19:12
It would be really helpful if there was an easier
|
+ } |
+ |
+ void CheckNextEscapedKeyword(bool* ok) { |
+ if (IsNextEscapedReservedWord()) { |
caitp (gmail)
2015/11/03 17:19:13
Just used to shrink a bit of code in parser.cc / p
|
+ ReportMessageAt(scanner()->peek_location(), |
+ MessageTemplate::kInvalidEscapedReservedWord); |
+ *ok = false; |
+ } |
+ } |
+ |
// Recursive descent functions: |
// Parses an identifier that is valid for the current scope, in particular it |
@@ -685,6 +698,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, |
caitp (gmail)
2015/11/03 17:19:12
I originally wrote a second method for testing thi
|
ExpressionClassifier* classifier, bool* ok); |
ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
ObjectLiteralPropertyT ParsePropertyDefinition( |
@@ -2268,6 +2282,14 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
break; |
case Token::IDENTIFIER: |
+ if (IsNextEscapedReservedWord()) { |
caitp (gmail)
2015/11/03 17:19:12
IdentifierReference --- Escaped reserved words are
|
+ 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 +2569,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_id, bool* is_escaped_keyword, |
adamk
2015/11/03 23:00:57
Please keep the "is_identifier" name here as in th
caitp (gmail)
2015/11/04 04:49:24
Done.
|
+ ExpressionClassifier* classifier, bool* ok) { |
Token::Value token = peek(); |
int pos = peek_position(); |
@@ -2593,6 +2616,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
// Fall through. |
default: |
+ *is_id = true; |
+ *is_escaped_keyword = IsNextEscapedReservedWord(); |
*name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
break; |
} |
@@ -2621,8 +2646,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_ident = false; |
adamk
2015/11/03 23:00:57
Please use "is_identifier" here too for consistenc
caitp (gmail)
2015/11/04 04:49:24
Done.
|
+ 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_ident, |
+ &is_escaped_keyword, classifier, |
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
if (fni_ != nullptr && !*is_computed_name) { |
@@ -2646,16 +2674,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_ident && (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()); |
@@ -2738,7 +2778,7 @@ ParserBase<Traits>::ParsePropertyDefinition( |
name_expression = ParsePropertyName( |
&name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, |
- CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
+ &dont_care, &dont_care, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
caitp (gmail)
2015/11/03 17:19:13
MethodDefinitions and accessors use the PropertyNa
|
if (!*is_computed_name) { |
checker->CheckProperty(name_token, kAccessorProperty, is_static, |