53fdf9d192
eval() may introduce a scope which needs to be represented as a context at runtime, e.g., eval('var x; let y; ()=>y') introduces a variable y which needs to have a context allocated for it. However, when traversing upwards to find the declaration context for a variable which leaks, as the declaration of x does above, this context has to be understood to not be a declaration context in sloppy mode. This patch makes that distinction by introducing a different map for eval-introduced contexts. A dynamic search for the appropriate context will continue past an eval context to find the appropriate context. Marking contexts as eval contexts rather than function contexts required updates in each compiler backend. BUG=v8:5295, chromium:648719 Review-Url: https://codereview.chromium.org/2435023002 Cr-Commit-Position: refs/heads/master@{#41869}
27 lines
863 B
JavaScript
27 lines
863 B
JavaScript
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
var my_global = 0;
|
|
|
|
// The problem was that we allowed lazy functions inside evals, but did not
|
|
// force context allocation on the eval scope. Thus, foo was not context
|
|
// allocated since we didn't realize that a lazy function referred to it.
|
|
eval(`let foo = 1;
|
|
let maybe_lazy = function() { foo = 2; }
|
|
maybe_lazy();
|
|
my_global = foo;`);
|
|
assertEquals(2, my_global);
|
|
|
|
(function TestVarInStrictEval() {
|
|
"use strict";
|
|
eval(`var foo = 3;
|
|
let maybe_lazy = function() { foo = 4; }
|
|
maybe_lazy();
|
|
my_global = foo;`);
|
|
assertEquals(4, my_global);
|
|
})();
|
|
|
|
eval("let foo = 1; function lazy() { foo = 2; } lazy(); my_global = foo;");
|
|
assertEquals(my_global, 2);
|