Index: src/parsing/preparser.cc |
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc |
index acb6b33750d4597de19b65bd0a39d7f7ddde7348..a9af4a955884511de1fc0e3eabc3953c0baa0073 100644 |
--- a/src/parsing/preparser.cc |
+++ b/src/parsing/preparser.cc |
@@ -956,15 +956,29 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
} |
} else { |
int lhs_beg_pos = peek_position(); |
- Expression lhs = ParseExpression(false, CHECK_OK); |
+ ExpressionClassifier classifier; |
+ Expression lhs = ParseExpression(false, &classifier, CHECK_OK); |
int lhs_end_pos = scanner()->location().end_pos; |
is_let_identifier_expression = |
lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); |
- if (CheckInOrOf(&mode, ok)) { |
- if (!*ok) return Statement::Default(); |
- lhs = CheckAndRewriteReferenceExpression( |
- lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, |
- kSyntaxError, CHECK_OK); |
+ bool is_for_each = CheckInOrOf(&mode, ok); |
+ if (!*ok) return Statement::Default(); |
+ bool is_destructuring = is_for_each && |
+ allow_harmony_destructuring_assignment() && |
+ (lhs->IsArrayLiteral() || lhs->IsObjectLiteral()); |
+ |
+ if (is_destructuring) { |
+ ValidateAssignmentPattern(&classifier, CHECK_OK); |
+ } else { |
+ ValidateExpression(&classifier, CHECK_OK); |
+ } |
+ |
+ if (is_for_each) { |
+ if (!is_destructuring) { |
+ lhs = CheckAndRewriteReferenceExpression( |
+ lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, |
+ kSyntaxError, CHECK_OK); |
+ } |
ParseExpression(true, CHECK_OK); |
Expect(Token::RPAREN, CHECK_OK); |
ParseSubStatement(CHECK_OK); |