mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:37:34 +00:00
LibJS: Use create_list_from_array_like() in Function.prototype.apply()
This commit is contained in:
parent
f932da095e
commit
b639bf64f2
2 changed files with 2 additions and 14 deletions
|
@ -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") \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* 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<TypeError>(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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue