LibJS: Elide empty lexical environment when direct eval() is present

Direct eval() always creates a new lexical environment, so we don't have
to worry about those here. The var environments still need special care.
This commit is contained in:
Andreas Kling 2025-03-20 08:48:28 -05:00 committed by Andreas Kling
commit 842a189c2e
Notes: github-actions[bot] 2025-03-20 17:52:20 +00:00

View file

@ -164,8 +164,8 @@ CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(E
}
if (!function.m_strict) {
bool can_elide_declarative_environment = !function.m_contains_direct_call_to_eval && (!scope_body || !scope_body->has_non_local_lexical_declarations());
if (!can_elide_declarative_environment) {
bool can_elide_lexical_environment = !scope_body || !scope_body->has_non_local_lexical_declarations();
if (!can_elide_lexical_environment) {
emit<Op::CreateLexicalEnvironment>(function.m_lex_environment_bindings_count);
}
}