From f61a9f2dc5c9dfbde87ef4920c7a8beb0be5c7ce Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 27 Jun 2021 00:37:07 +0200 Subject: [PATCH] LibJS: Don't extend `arguments` object to match the parameter count The `arguments` object should only have the *arguments* as numeric properties, not the *parameters*. Given this function: function foo(a, b) { return arguments.length; } Calling foo() with no arguments now correctly returns 0 instead of 2. --- Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp b/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp index fd02d8a107..3d00c4bd4a 100644 --- a/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/ScriptFunction.cpp @@ -170,9 +170,6 @@ Value ScriptFunction::execute_function_body() argument_value = js_undefined(); } - if (i >= execution_context_arguments.size()) - execution_context_arguments.resize(i + 1); - execution_context_arguments[i] = argument_value; vm.assign(param, argument_value, global_object(), true, vm.lexical_environment()); });