From b2bded390ac8755e499764dacec9fa51a9404693 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 5 Oct 2021 00:02:26 +0100 Subject: [PATCH] LibJS: Stop iterating lexically declared names once 'arguments' is found In ECMAScriptFunctionObject::function_declaration_instantiation() we iterate over all lexically declared names of the function scope body to determine whether any of them is named 'arguments', because we don't need to create an arguments object in that case. We can also stop at that point, because the decision won't change anymore. --- Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index 7896db8de3..c6112d3813 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -179,8 +179,10 @@ ThrowCompletionOr ECMAScriptFunctionObject::function_declaration_instantia if (!has_parameter_expressions && arguments_object_needed) { scope_body->for_each_lexically_declared_name([&](auto const& name) { - if (name == arguments_name) + if (name == arguments_name) { arguments_object_needed = false; + return IterationDecision::Break; + } return IterationDecision::Continue; }); }