Commit ccbda511 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[parser] Skipping inner funcs: fix saving / restoring data for hidden scopes.

In the failing case (see test), the loop variable (which should be context
allocated) is in a hidden scope, so we need to save and restore data for hidden
scopes too.

The !is_hidden() check was overly limiting - NeedsScopeData already handles the
"hidden leaf scope" case which is the one we want to avoid.

(Btw, this also means that the previous assumption "variables in hidden scopes
are not context allocated" was wrong.)

BUG=v8:5516

Change-Id: I1c6116654b19ef0cfd64e8a743b46af683a9fcd5
Reviewed-on: https://chromium-review.googlesource.com/544938
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarDaniel Vogelheim <vogelheim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46136}
parent 54b42a55
......@@ -87,11 +87,9 @@ void PreParsedScopeData::SaveData(Scope* scope) {
SaveDataForVariable(function);
}
}
if (!scope->is_hidden()) {
for (Variable* var : *scope->locals()) {
if (IsDeclaredVariableMode(var->mode())) {
SaveDataForVariable(var);
}
for (Variable* var : *scope->locals()) {
if (IsDeclaredVariableMode(var->mode())) {
SaveDataForVariable(var);
}
}
......@@ -178,11 +176,9 @@ void PreParsedScopeData::RestoreData(Scope* scope, uint32_t* index_ptr) const {
RestoreDataForVariable(function, index_ptr);
}
}
if (!scope->is_hidden()) {
for (Variable* var : *scope->locals()) {
if (var->mode() == VAR || var->mode() == LET || var->mode() == CONST) {
RestoreDataForVariable(var, index_ptr);
}
for (Variable* var : *scope->locals()) {
if (var->mode() == VAR || var->mode() == LET || var->mode() == CONST) {
RestoreDataForVariable(var, index_ptr);
}
}
......
......@@ -113,3 +113,12 @@ function TestUsingNamedExpressionName2() {
f();
}
TestUsingNamedExpressionName2();
function TestSkippedFunctionInsideLoopInitializer() {
let saved_func;
for (let i = 0, f = function() { return i }; i < 1; ++i) {
saved_func = f;
}
assertEquals(0, saved_func());
}
TestSkippedFunctionInsideLoopInitializer();
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