mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +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(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \
|
||||||
M(DescWriteNonWritable, "Cannot write to non-writable property '{}'") \
|
M(DescWriteNonWritable, "Cannot write to non-writable property '{}'") \
|
||||||
M(DivisionByZero, "Division by zero") \
|
M(DivisionByZero, "Division by zero") \
|
||||||
M(FunctionArgsNotObject, "Argument array must be an object") \
|
|
||||||
M(GetCapabilitiesExecutorCalledMultipleTimes, "GetCapabilitiesExecutor was called multiple times") \
|
M(GetCapabilitiesExecutorCalledMultipleTimes, "GetCapabilitiesExecutor was called multiple times") \
|
||||||
M(InOperatorWithObject, "'in' operator must be used on an object") \
|
M(InOperatorWithObject, "'in' operator must be used on an object") \
|
||||||
M(InstanceOfOperatorBadPrototype, "'prototype' property of {} is not 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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -56,20 +56,9 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::apply)
|
||||||
auto arg_array = vm.argument(1);
|
auto arg_array = vm.argument(1);
|
||||||
if (arg_array.is_nullish())
|
if (arg_array.is_nullish())
|
||||||
return vm.call(function, this_arg);
|
return vm.call(function, this_arg);
|
||||||
if (!arg_array.is_object()) {
|
auto arguments = create_list_from_array_like(global_object, arg_array);
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::FunctionArgsNotObject);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
auto length = length_of_array_like(global_object, arg_array.as_object());
|
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
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));
|
return vm.call(function, this_arg, move(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue