mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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
13 lines
310 B
JavaScript
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();
|