Commit 10b9c019 authored by Caitlin Potter's avatar Caitlin Potter Committed by Commit Bot

[parser] avoid for-loop desugaring unless loop var may be captured

In https://chromium-review.googlesource.com/c/472247/, I avoided
running DesugarLexicalBindingsInForStatement() if there were no lexical
loop variables, the function was not resumable, and the variables are
not captured by eval or a function declaration.

I think it's now possible to limit this further, and only do the more
extensive desugaring if there's a function declaration / eval() call
in the loop body. `yield` and `await` are not an issue as those loop
variables are written to the register file and not lost.

This change just removes the `is_resumable()` condition. If it passes
tests, I think it's safe.

BUG=v8:4762, v8:5460, v8:6579

Change-Id: I92d0308ad9401c1338411bc9ae9021f978803d3a
Reviewed-on: https://chromium-review.googlesource.com/563587
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46536}
parent e4b3f6a7
......@@ -5830,7 +5830,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStandardForLoop(
scope()->set_end_position(scanner()->location().end_pos);
inner_scope->set_end_position(scanner()->location().end_pos);
if (bound_names_are_lexical && for_info->bound_names.length() > 0 &&
(is_resumable() || function_state_->contains_function_or_eval())) {
function_state_->contains_function_or_eval()) {
scope()->set_is_hidden();
return impl()->DesugarLexicalBindingsInForStatement(
loop, init, cond, next, body, body_range, inner_scope, *for_info,
......
......@@ -276,13 +276,14 @@ function *gen10() {
g = gen10();
g.next();
CheckScopeChain([debug.ScopeType.Block,
debug.ScopeType.Block,
debug.ScopeType.Local,
debug.ScopeType.Script,
debug.ScopeType.Global], g);
CheckScopeContent({i: 0}, 0, g);
CheckScopeContent({i: 0}, 1, g);
g.next();
CheckScopeContent({i: 1}, 0, g);
CheckScopeContent({i: 1}, 1, g);
// Nested generators.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment