Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1106)

Unified Diff: src/preparser.h

Issue 1429983002: [es6] early error when Identifier is an escaped reserved word (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/messages.h ('k') | src/scanner.h » ('j') | src/scanner.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 788ed431fe0ac3d0193002c63e42718e68f9ef69..4703a9a0b6045e363393002f6038a3e11dfcab84 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -684,6 +684,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(
@@ -2016,6 +2017,11 @@ void ParserBase<Traits>::GetUnexpectedTokenMessage(
*message = MessageTemplate::kUnexpectedTemplateString;
*arg = nullptr;
break;
+ case Token::ESCAPED_STRICT_RESERVED_WORD:
+ case Token::ESCAPED_KEYWORD:
+ *message = MessageTemplate::kInvalidEscapedReservedWord;
+ *arg = nullptr;
+ break;
default:
const char* name = Token::String(token);
DCHECK(name != NULL);
@@ -2067,6 +2073,14 @@ typename ParserBase<Traits>::IdentifierT
ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
bool* ok) {
Token::Value next = Next();
+ if (next == Token::ESCAPED_STRICT_RESERVED_WORD) {
+ if (is_strict(language_mode())) {
+ ReportUnexpectedToken(next);
+ *ok = false;
+ return Traits::EmptyIdentifier();
+ }
+ next = Token::IDENTIFIER;
+ }
if (next == Token::IDENTIFIER) {
IdentifierT name = this->GetSymbol(scanner());
// When this function is used to read a formal parameter, we don't always
@@ -2161,7 +2175,9 @@ ParserBase<Traits>::ParseIdentifierName(bool* ok) {
Token::Value next = Next();
if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD &&
next != Token::LET && next != Token::STATIC && next != Token::YIELD &&
- next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
+ next != Token::FUTURE_STRICT_RESERVED_WORD &&
+ next != Token::ESCAPED_KEYWORD &&
+ next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
this->ReportUnexpectedToken(next);
*ok = false;
return Traits::EmptyIdentifier();
@@ -2288,6 +2304,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::LET:
case Token::STATIC:
case Token::YIELD:
+ case Token::ESCAPED_STRICT_RESERVED_WORD:
case Token::FUTURE_STRICT_RESERVED_WORD: {
// Using eval or arguments in this context is OK even in strict mode.
IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK);
@@ -2564,7 +2581,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,
rossberg 2015/11/06 13:31:05 There are so many flags now that it's worth turnin
caitp (gmail) 2015/11/06 16:10:30 I've started to do this, but it's a pretty substan
- 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();
@@ -2605,11 +2623,18 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
return expression;
}
+ case Token::ESCAPED_KEYWORD:
+ *is_escaped_keyword = true;
+ *is_identifier = true;
rossberg 2015/11/06 13:31:04 Why does an escaped keyword qualify as an identifi
caitp (gmail) 2015/11/06 16:10:30 Yeah, I guess --- the thing is, the error is only
+ *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK);
+ break;
+
case Token::STATIC:
*is_static = true;
// Fall through.
default:
+ *is_identifier = true;
*name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK);
break;
}
@@ -2638,8 +2663,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) {
@@ -2663,16 +2691,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) {
rossberg 2015/11/06 13:31:05 See above, I'm confused, which case would this cov
caitp (gmail) 2015/11/06 19:08:06 originally, I had wanted to report a slightly diff
+ classifier->RecordExpressionError(
rossberg 2015/11/06 13:31:05 Wouldn't this be an error unconditionally? In whic
caitp (gmail) 2015/11/06 19:08:06 it always is, the original idea was just to use a
+ 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());
@@ -2754,8 +2794,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,
« no previous file with comments | « src/messages.h ('k') | src/scanner.h » ('j') | src/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698