Commit e87e82b8 authored by marja's avatar marja Committed by Commit bot

Force ctxt allocation in eval scopes.

This is another attempt at solving v8:5736; the previous one (r 41723)
regressed code load.

BUG=v8:5736
R=adamk@chromium.org

Review-Url: https://codereview.chromium.org/2583163002
Cr-Commit-Position: refs/heads/master@{#42049}
parent 5c6e79e1
......@@ -1178,7 +1178,10 @@ bool Scope::AllowsLazyParsingWithoutUnresolvedVariables(
// the parse, since context allocation of those variables is already
// guaranteed to be correct.
for (const Scope* s = this; s != outer; s = s->outer_scope_) {
if (s->is_eval_scope()) return false;
// Eval forces context allocation on all outer scopes, so we don't need to
// look at those scopes. Sloppy eval makes top-level non-lexical variables
// dynamic, whereas strict-mode requires context allocation.
if (s->is_eval_scope()) return is_sloppy(s->language_mode());
// Catch scopes force context allocation of all variables.
if (s->is_catch_scope()) continue;
// With scopes do not introduce variables that need allocation.
......@@ -1887,7 +1890,10 @@ bool Scope::MustAllocateInContext(Variable* var) {
if (has_forced_context_allocation()) return true;
if (var->mode() == TEMPORARY) return false;
if (is_catch_scope()) return true;
if (is_script_scope() && IsLexicalVariableMode(var->mode())) return true;
if ((is_script_scope() || is_eval_scope()) &&
IsLexicalVariableMode(var->mode())) {
return true;
}
return var->has_forced_context_allocation() || inner_scope_calls_eval_;
}
......
......@@ -24,3 +24,11 @@ assertEquals(2, my_global);
eval("let foo = 1; function lazy() { foo = 2; } lazy(); my_global = foo;");
assertEquals(my_global, 2);
// Lexical variable inside a subscope in eval.
eval(`{ let foo = 5;
function not_lazy() { foo = 6; }
not_lazy();
my_global = foo;
}`);
assertEquals(my_global, 6);
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