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

Unified Diff: src/preparser.cc

Issue 713413003: harmony-scoping: better error messages for let declarations in sloppy mode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Patch for landing Created 6 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/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index 1a2ddb61c560fa942bddf53381013be754d2a4bf..6b0d7d9d6d0f57580e897df67b3cc4f967902829 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -509,6 +509,13 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
// accept "native function" in the preparser.
}
// Parsed expression statement.
+ // Detect attempts at 'let' declarations in sloppy mode.
+ if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY &&
+ expr.IsIdentifier() && expr.AsIdentifier().IsLet()) {
+ ReportMessage("lexical_strict_mode", NULL);
+ *ok = false;
+ return Statement::Default();
+ }
ExpectSemicolon(CHECK_OK);
return Statement::ExpressionStatement(expr);
}
@@ -688,6 +695,7 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK);
+ bool is_let_identifier_expression = false;
if (peek() != Token::SEMICOLON) {
if (peek() == Token::VAR || peek() == Token::CONST ||
(peek() == Token::LET && strict_mode() == STRICT)) {
@@ -709,6 +717,8 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
} else {
Expression lhs = ParseExpression(false, CHECK_OK);
+ is_let_identifier_expression =
+ lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
if (CheckInOrOf(lhs.IsIdentifier())) {
ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
@@ -720,6 +730,13 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
// Parsed initializer at this point.
+ // Detect attempts at 'let' declarations in sloppy mode.
+ if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY &&
+ is_let_identifier_expression) {
+ ReportMessage("lexical_strict_mode", NULL);
+ *ok = false;
+ return Statement::Default();
+ }
Expect(Token::SEMICOLON, CHECK_OK);
if (peek() != Token::SEMICOLON) {
« no previous file with comments | « src/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698