LibJS: Elide empty lexical environments for parameter evaluation

If all the parameter default values end up in locals, the lexical
environment we create to hold them would never be used for anything,
and so we can elide it and avoid the GC work.
This commit is contained in:
Andreas Kling 2025-03-20 08:51:45 -05:00 committed by Andreas Kling
parent 842a189c2e
commit 49d2a8df23
Notes: github-actions[bot] 2025-03-20 17:52:13 +00:00

View file

@ -33,7 +33,15 @@ Generator::Generator(VM& vm, GC::Ptr<ECMAScriptFunctionObject const> function, M
CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(ECMAScriptFunctionObject const& function)
{
if (function.m_has_parameter_expressions) {
emit<Op::CreateLexicalEnvironment>();
bool has_non_local_parameters = false;
for (auto const& parameter_name : function.m_parameter_names) {
if (parameter_name.value == ECMAScriptFunctionObject::ParameterIsLocal::No) {
has_non_local_parameters = true;
break;
}
}
if (has_non_local_parameters)
emit<Op::CreateLexicalEnvironment>();
}
for (auto const& parameter_name : function.m_parameter_names) {