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

Unified Diff: src/parsing/parser.cc

Issue 2343823002: [parser] Fix tail calls in for in/of loops (Closed)
Patch Set: Better rebase Created 4 years, 3 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 | test/mjsunit/es6/tail-call.js » ('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 7e4086283f91e0873a92d1a21e2762f2c7bf4858..54db959ee0c8ad040b415dbaedad147c64ad1fd6 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -2609,17 +2609,27 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::RPAREN, CHECK_OK);
- // For legacy compat reasons, give for loops similar treatment to
- // if statements in allowing a function declaration for a body
- Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
- Statement* final_loop = InitializeForEachStatement(
- loop, expression, enumerable, body, each_keyword_position);
+ {
+ ReturnExprScope no_tail_calls(function_state_,
+ ReturnExprContext::kInsideForInOfBody);
+ BlockState block_state(&scope_state_);
+ block_state.set_start_position(scanner()->location().beg_pos);
- Scope* for_scope = for_state.FinalizedBlockScope();
- DCHECK_NULL(for_scope);
- USE(for_scope);
- return final_loop;
+ // For legacy compat reasons, give for loops similar treatment to
+ // if statements in allowing a function declaration for a body
+ Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
+ block_state.set_end_position(scanner()->location().end_pos);
+ Statement* final_loop = InitializeForEachStatement(
+ loop, expression, enumerable, body, each_keyword_position);
+ Scope* for_scope = for_state.FinalizedBlockScope();
+ DCHECK_NULL(for_scope);
+ USE(for_scope);
+ Scope* block_scope = block_state.FinalizedBlockScope();
+ DCHECK_NULL(block_scope);
+ USE(block_scope);
+ return final_loop;
+ }
} else {
init = factory()->NewExpressionStatement(expression, lhs_beg_pos);
}
« no previous file with comments | « no previous file | test/mjsunit/es6/tail-call.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698