mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibJS: Make Array.of(...items) generic
As well as bring it generally closer to the specification.
This commit is contained in:
parent
7ff363127b
commit
1d94d7a367
Notes:
sideshowbarker
2024-07-18 11:21:02 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/1d94d7a3676 Pull-request: https://github.com/SerenityOS/serenity/pull/8311 Reviewed-by: https://github.com/linusg
1 changed files with 20 additions and 3 deletions
|
@ -155,9 +155,26 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array)
|
|||
// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
|
||||
{
|
||||
auto* array = Array::create(global_object);
|
||||
for (size_t i = 0; i < vm.argument_count(); ++i)
|
||||
array->indexed_properties().append(vm.argument(i));
|
||||
auto this_value = vm.this_value(global_object);
|
||||
Value array;
|
||||
if (this_value.is_constructor()) {
|
||||
MarkedValueList arguments(vm.heap());
|
||||
arguments.empend(vm.argument_count());
|
||||
array = vm.construct(this_value.as_function(), this_value.as_function(), move(arguments));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
} else {
|
||||
array = Array::create(global_object);
|
||||
}
|
||||
auto& array_object = array.as_object();
|
||||
for (size_t k = 0; k < vm.argument_count(); ++k) {
|
||||
array_object.define_property(k, vm.argument(k));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
array_object.put(vm.names.length, Value(vm.argument_count()));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
return array;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue