mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-19 09:17:38 +03:00
LibJS: Add spec comments to ArrayCreate
This commit is contained in:
parent
1132151f3d
commit
65eb1ee67a
Notes:
sideshowbarker
2024-07-17 09:45:05 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/65eb1ee67a Pull-request: https://github.com/SerenityOS/serenity/pull/14469 Reviewed-by: https://github.com/IdanHo
@ -20,12 +20,24 @@ namespace JS {
|
||||
ThrowCompletionOr<Array*> Array::create(GlobalObject& global_object, size_t length, Object* prototype)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. If length > 2^32 - 1, throw a RangeError exception.
|
||||
if (length > NumericLimits<u32>::max())
|
||||
return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidLength, "array");
|
||||
|
||||
// 2. If proto is not present, set proto to %Array.prototype%.
|
||||
if (!prototype)
|
||||
prototype = global_object.array_prototype();
|
||||
|
||||
// 3. Let A be MakeBasicObject(« [[Prototype]], [[Extensible]] »).
|
||||
// 4. Set A.[[Prototype]] to proto.
|
||||
// 5. Set A.[[DefineOwnProperty]] as specified in 10.4.2.1.
|
||||
auto* array = global_object.heap().allocate<Array>(global_object, *prototype);
|
||||
|
||||
// 6. Perform ! OrdinaryDefineOwnProperty(A, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||
MUST(array->internal_define_own_property(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = false }));
|
||||
|
||||
// 7. Return A.
|
||||
return array;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user