Files
ladybird/Tests/LibJS/Bytecode/input/eval-scope-optimization.js
Andreas Kling 871d93355b LibJS: Stop propagating is_inside_scope_with_eval across functions
Previously, when a nested function contained eval(), the parser would
mark all identifiers in parent functions as "inside scope with eval".
This prevented those identifiers from being marked as global, forcing
them to use GetBinding instead of GetGlobal.

However, eval() can only inject variables into its containing function's
scope, not into parent function scopes. So a parent function's reference
to a global like `Number` should still be able to use GetGlobal even if
a nested function contains eval().

This change adds a new flag `m_eval_in_current_function` that propagates
through block scopes within the same function but stops at function
boundaries. This flag is used for marking identifiers, while the
existing `m_screwed_by_eval_in_scope_chain` continues to propagate
across functions for local variable deoptimization (since eval can
access closure variables).

Before: `new Number(42)` in outer() with eval in inner() -> GetBinding
After:  `new Number(42)` in outer() with eval in inner() -> GetGlobal
2026-01-27 10:58:39 +01:00

13 lines
310 B
JavaScript

// Test that eval in a nested function doesn't prevent the parent function
// from using GetGlobal for global identifiers.
// The parent function should use GetGlobal for Number, not GetBinding.
function outer() {
function inner() {
eval("var x = 1");
}
return new Number(42);
}
outer();