mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 11:37:16 +02:00
LibJS: Convert Array::create{,_from}() to NonnullGCPtr
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 08:42:05 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/91b0123eaf Pull-request: https://github.com/SerenityOS/serenity/pull/16479 Reviewed-by: https://github.com/davidot ✅
@@ -55,11 +55,11 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
|
||||
auto* proto = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::array_prototype));
|
||||
|
||||
if (vm.argument_count() == 0)
|
||||
return MUST(Array::create(realm, 0, proto));
|
||||
return MUST(Array::create(realm, 0, proto)).ptr();
|
||||
|
||||
if (vm.argument_count() == 1) {
|
||||
auto length = vm.argument(0);
|
||||
auto* array = MUST(Array::create(realm, 0, proto));
|
||||
auto array = MUST(Array::create(realm, 0, proto));
|
||||
size_t int_length;
|
||||
if (!length.is_number()) {
|
||||
MUST(array->create_data_property_or_throw(0, length));
|
||||
@@ -70,15 +70,15 @@ ThrowCompletionOr<Object*> ArrayConstructor::construct(FunctionObject& new_targe
|
||||
return vm.throw_completion<RangeError>(ErrorType::InvalidLength, "array");
|
||||
}
|
||||
TRY(array->set(vm.names.length, Value(int_length), Object::ShouldThrowExceptions::Yes));
|
||||
return array;
|
||||
return array.ptr();
|
||||
}
|
||||
|
||||
auto* array = TRY(Array::create(realm, vm.argument_count(), proto));
|
||||
auto array = TRY(Array::create(realm, vm.argument_count(), proto));
|
||||
|
||||
for (size_t k = 0; k < vm.argument_count(); ++k)
|
||||
MUST(array->create_data_property_or_throw(k, vm.argument(k)));
|
||||
|
||||
return array;
|
||||
return array.ptr();
|
||||
}
|
||||
|
||||
// 23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-array.from
|
||||
|
||||
Reference in New Issue
Block a user