mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +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
11 lines
250 B
JavaScript
11 lines
250 B
JavaScript
// Test that eval in the same function prevents using GetGlobal
|
|
// for potentially shadowable identifiers.
|
|
// The function should use GetBinding for Number, not GetGlobal.
|
|
|
|
function foo() {
|
|
eval("var x = 1");
|
|
return new Number(42);
|
|
}
|
|
|
|
foo();
|