ladybird/Libraries/LibJS/Bytecode
Andreas Kling 5674f8bbe0 LibJS: Limit eval() deoptimization to the containing function scope
Previously, when direct eval() was called, we would mark the entire
environment chain as "permanently screwed by eval", disabling variable
access caching all the way up to the global scope.

This was overly conservative. According to the ECMAScript specification,
a sloppy direct eval() can only inject var declarations into its
containing function's variable environment - it cannot inject variables
into parent function scopes.

This patch makes two changes:

1. Stop propagating the "screwed by eval" flag at function boundaries.
   When set_permanently_screwed_by_eval() hits a FunctionEnvironment or
   GlobalEnvironment, it no longer continues to outer environments.

2. Check each environment during cache lookup traversal. If any
   environment in the path is marked as screwed, we bail to the slow
   path. This catches the case where we're inside a function with eval
   and have a cached coordinate pointing to an outer scope.

The second change is necessary because eval can create local variables
that shadow outer bindings. When looking up a variable from inside a
function that called eval, we can't trust cached coordinates that point
to outer scopes, since eval may have created a closer binding.

This improves performance for code with nested functions where an inner
function uses eval but parent functions perform many variable accesses.
The parent functions can now use cached environment coordinates.

All 29 new tests verify behavior matches V8.
2026-01-27 10:58:39 +01:00
..
ASTCodegen.cpp LibJS: Constant fold LogicalExpression 2026-01-22 08:47:18 +01:00
BasicBlock.cpp LibJS: Stop worrying about Instruction destructors 2025-11-21 09:46:03 +01:00
BasicBlock.h LibJS: Replace source map HashMap with sorted Vector 2026-01-26 19:37:42 +01:00
BuiltinAbstractOperationsEnabled.h LibJS: Introduce NativeJavaScriptBackedFunction 2025-11-30 11:54:54 +01:00
Builtins.cpp Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Builtins.h LibJS: Skip generic call when using regexp builtins in StringPrototype 2025-12-13 13:51:12 -06:00
Bytecode.def LibJS: Add shape caching for object literal instantiation 2026-01-10 00:56:51 +01:00
CodeGenerationError.cpp Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
CodeGenerationError.h LibJS: Revert Enable EXPLICIT_SYMBOL_EXPORT 2025-07-22 11:51:29 -04:00
Executable.cpp LibJS: Replace source map HashMap with sorted Vector 2026-01-26 19:37:42 +01:00
Executable.h LibJS: Replace source map HashMap with sorted Vector 2026-01-26 19:37:42 +01:00
FormatOperand.h LibJS: Flatten Operand to 32-bit index in bytecode instruction stream 2025-12-09 21:44:13 -06:00
Generator.cpp LibJS: Replace source map HashMap with sorted Vector 2026-01-26 19:37:42 +01:00
Generator.h LibJS: Narrow bytecode source map offsets from size_t to u32 2026-01-26 19:37:42 +01:00
IdentifierTable.cpp LibJS+LibWeb+WebContent: Port JS::PropertyKey to UTF-16 2025-08-05 07:07:15 -04:00
IdentifierTable.h LibJS: Give Interpreter a direct pointer to the identifier table 2025-10-07 23:50:51 +02:00
Instruction.cpp LibJS: Flatten Operand to 32-bit index in bytecode instruction stream 2025-12-09 21:44:13 -06:00
Instruction.h LibJS: Add % (modulo) fast path in bytecode interpreter 2026-01-09 09:16:50 +01:00
Interpreter.cpp LibJS: Limit eval() deoptimization to the containing function scope 2026-01-27 10:58:39 +01:00
Interpreter.h LibJS: Cache fully-formed PropertyKeys in Executable 2025-12-11 14:34:45 -06:00
Label.cpp Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Label.h LibJS: Revert Enable EXPLICIT_SYMBOL_EXPORT 2025-07-22 11:51:29 -04:00
Operand.h LibJS: Flatten Operand to 32-bit index in bytecode instruction stream 2025-12-09 21:44:13 -06:00
PropertyAccess.h LibJS: Take snapshot of prototype chain validity later in GetById 2026-01-09 09:16:50 +01:00
PropertyKeyTable.cpp LibJS: Cache fully-formed PropertyKeys in Executable 2025-12-11 14:34:45 -06:00
PropertyKeyTable.h LibJS+LibWeb: Add missing GC marking visits 2026-01-07 12:48:58 +01:00
PutKind.h LibJS: Rename Bytecode::Op::PropertyKind => Bytecode::PutKind 2025-10-11 20:08:58 +02:00
RegexTable.cpp LibJS: Don't rerun regexp optimizer every time a regexp literal is used 2025-12-12 11:43:35 -06:00
RegexTable.h LibJS: Don't rerun regexp optimizer every time a regexp literal is used 2025-12-12 11:43:35 -06:00
Register.h LibJS: Revert Enable EXPLICIT_SYMBOL_EXPORT 2025-07-22 11:51:29 -04:00
ScopedOperand.cpp LibJS: Flatten Operand to 32-bit index in bytecode instruction stream 2025-12-09 21:44:13 -06:00
ScopedOperand.h LibJS: Revert Enable EXPLICIT_SYMBOL_EXPORT 2025-07-22 11:51:29 -04:00
StringTable.cpp LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00
StringTable.h LibJS+LibWeb: Port interned bytecode strings to UTF-16 2025-08-14 10:27:08 +02:00