diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h index a89d12157f..fb416cdd7c 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h @@ -25,7 +25,6 @@ M(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \ M(DescWriteNonWritable, "Cannot write to non-writable property '{}'") \ M(DivisionByZero, "Division by zero") \ - M(FunctionArgsNotObject, "Argument array must be an object") \ M(GetCapabilitiesExecutorCalledMultipleTimes, "GetCapabilitiesExecutor was called multiple times") \ M(InOperatorWithObject, "'in' operator must be used on an object") \ M(InstanceOfOperatorBadPrototype, "'prototype' property of {} is not an object") \ diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index e07c24e593..77cad5c748 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Linus Groh + * Copyright (c) 2020-2021, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -56,20 +56,9 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply) auto arg_array = vm.argument(1); if (arg_array.is_nullish()) return vm.call(function, this_arg); - if (!arg_array.is_object()) { - vm.throw_exception(global_object, ErrorType::FunctionArgsNotObject); - return {}; - } - auto length = length_of_array_like(global_object, arg_array.as_object()); + auto arguments = create_list_from_array_like(global_object, arg_array); if (vm.exception()) return {}; - MarkedValueList arguments(vm.heap()); - for (size_t i = 0; i < length; ++i) { - auto element = arg_array.as_object().get(i); - if (vm.exception()) - return {}; - arguments.append(element.value_or(js_undefined())); - } return vm.call(function, this_arg, move(arguments)); }