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

Unified Diff: src/parsing/parser.cc

Issue 1602823003: [parser] Disallow Expression in for..of statements (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporating latest review feedback Created 4 years, 11 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 | « no previous file | src/parsing/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 0048b8da698b718cc01671f52ab659b905427c2e..f5a95acd19907a8a54cf3e12a6aaca1a7543b086 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -3676,7 +3676,15 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
factory()->NewForEachStatement(mode, labels, stmt_pos);
Target target(&this->target_stack_, loop);
- Expression* enumerable = ParseExpression(true, CHECK_OK);
+ Expression* enumerable;
+ if (mode == ForEachStatement::ITERATE) {
+ ExpressionClassifier classifier;
+ enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
+ enumerable = ParserTraits::RewriteNonPattern(enumerable, &classifier,
+ CHECK_OK);
+ } else {
+ enumerable = ParseExpression(true, CHECK_OK);
+ }
Expect(Token::RPAREN, CHECK_OK);
@@ -3791,7 +3799,16 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
factory()->NewForEachStatement(mode, labels, stmt_pos);
Target target(&this->target_stack_, loop);
- Expression* enumerable = ParseExpression(true, CHECK_OK);
+ Expression* enumerable;
+ if (mode == ForEachStatement::ITERATE) {
+ ExpressionClassifier classifier;
+ enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
+ enumerable = ParserTraits::RewriteNonPattern(enumerable, &classifier,
+ CHECK_OK);
+ } else {
+ enumerable = ParseExpression(true, CHECK_OK);
+ }
+
Expect(Token::RPAREN, CHECK_OK);
// Make a block around the statement in case a lexical binding
« no previous file with comments | « no previous file | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698