mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
LibJS: Add spec comments to ArrayCreate
This commit is contained in:
parent
1132151f3d
commit
65eb1ee67a
1 changed files with 12 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue