mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +02:00
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:
committed by
Andreas Kling
parent
842a189c2e
commit
49d2a8df23
Notes:
github-actions[bot]
2025-03-20 17:52:13 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/49d2a8df23b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4017
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user