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

Unified Diff: src/preparser.cc

Issue 7837028: Let bound iteration variables in for-loops (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Created 9 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
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index 9f8e1eecc2fb59b134a244c69877c378aa6b786e..2554895858201a74dc0997549295006deba3db6b 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -312,6 +312,7 @@ PreParser::Statement PreParser::ParseVariableStatement(
Statement result = ParseVariableDeclarations(var_context,
NULL,
+ NULL,
CHECK_OK);
ExpectSemicolon(CHECK_OK);
return result;
@@ -325,6 +326,7 @@ PreParser::Statement PreParser::ParseVariableStatement(
// of 'for-in' loops.
PreParser::Statement PreParser::ParseVariableDeclarations(
VariableDeclarationContext var_context,
+ VariableDeclarationProperties* decl_props,
int* num_decl,
bool* ok) {
// VariableDeclarations ::
@@ -375,6 +377,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
if (peek() == i::Token::ASSIGN) {
Expect(i::Token::ASSIGN, CHECK_OK);
ParseAssignmentExpression(var_context != kForStatement, CHECK_OK);
+ if (decl_props != NULL) *decl_props = kHasInitializers;
}
} while (peek() == i::Token::COMMA);
@@ -569,9 +572,14 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
if (peek() != i::Token::SEMICOLON) {
if (peek() == i::Token::VAR || peek() == i::Token::CONST ||
peek() == i::Token::LET) {
+ bool is_let = peek() == i::Token::LET;
int decl_count;
- ParseVariableDeclarations(kForStatement, &decl_count, CHECK_OK);
- if (peek() == i::Token::IN && decl_count == 1) {
+ VariableDeclarationProperties decl_props = kHasNoInitializers;
+ ParseVariableDeclarations(
+ kForStatement, &decl_props, &decl_count, CHECK_OK);
+ bool accept_IN = decl_count == 1 &&
+ !(is_let && decl_props == kHasInitializers);
+ if (peek() == i::Token::IN && accept_IN) {
Expect(i::Token::IN, CHECK_OK);
ParseExpression(true, CHECK_OK);
Expect(i::Token::RPAREN, CHECK_OK);

Powered by Google App Engine
This is Rietveld 408576698