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

Unified Diff: src/preparser.cc

Issue 671913002: harmony-scoping: Allow 'const' iteration variables in strict mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove assertion (checked downstream) Created 6 years, 2 months 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/preparser.h ('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 987900a20d5844ebfef3e17d93fcd4c43f9503ea..316f129cc12bda987fc9e174319d68f0f36b307d 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -409,6 +409,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
// ConstBinding ::
// BindingPattern '=' AssignmentExpression
bool require_initializer = false;
+ bool is_strict_const = false;
if (peek() == Token::VAR) {
Consume(Token::VAR);
} else if (peek() == Token::CONST) {
@@ -430,7 +431,8 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
*ok = false;
return Statement::Default();
}
- require_initializer = true;
+ is_strict_const = true;
+ require_initializer = var_context != kForStatement;
} else {
Scanner::Location location = scanner()->peek_location();
ReportMessageAt(location, "strict_const");
@@ -460,7 +462,9 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
if (nvars > 0) Consume(Token::COMMA);
ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
nvars++;
- if (peek() == Token::ASSIGN || require_initializer) {
+ if (peek() == Token::ASSIGN || require_initializer ||
+ // require initializers for multiple consts.
+ (is_strict_const && peek() == Token::COMMA)) {
Expect(Token::ASSIGN, CHECK_OK);
ParseAssignmentExpression(var_context != kForStatement, CHECK_OK);
if (decl_props != NULL) *decl_props = kHasInitializers;
@@ -678,13 +682,14 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
if (peek() != Token::SEMICOLON) {
if (peek() == Token::VAR || peek() == Token::CONST ||
(peek() == Token::LET && strict_mode() == STRICT)) {
- bool is_let = peek() == Token::LET;
+ bool is_lexical = peek() == Token::LET ||
+ (peek() == Token::CONST && strict_mode() == STRICT);
int decl_count;
VariableDeclarationProperties decl_props = kHasNoInitializers;
ParseVariableDeclarations(
kForStatement, &decl_props, &decl_count, CHECK_OK);
bool has_initializers = decl_props == kHasInitializers;
- bool accept_IN = decl_count == 1 && !(is_let && has_initializers);
+ bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers);
bool accept_OF = !has_initializers;
if (accept_IN && CheckInOrOf(accept_OF)) {
ParseExpression(true, CHECK_OK);
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698