You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All the array methods throw an error when they create an array longer than 2**53-1 (thus, when you exceed the index 2**53-2). However, Array.from(iterable) throws one element earlier:
e. Repeat,
i. If k ≥ 2**53 - 1, then
1. Let error be ThrowCompletion(a newly created TypeError object).
2. Return ? IteratorClose(iteratorRecord, error).
ii. Let Pk be ! ToString(𝔽(k)).
iii. Let next be ? IteratorStep(iteratorRecord).
iv. If next is false, then
1. Perform ? Set(A, "length", 𝔽(k), true).
2. Return A.
v. Let nextValue be ? IteratorValue(next).
... other steps to add a new element with nextValue
This code always checks if we reached the length 2**53-1, but it throws before making sure that we are actually exceeding it. Looking at #352, it seems like the intention was to throw when exceeding 2**53-1.
I think step e.i should be moved after step e.iv.
Additionally, I think we should introduce a similar check in the Array.from(arrayLike) case (Array.from({ length: 2**53 }) should throw), but that's a bigger normative change.
@nicolo-ribaudo if that’s ordinary Array, wouldn’t a RangeError be the expected outcome?
The max array index is (the canonical numeric string of) 2 ** 32 - 2
Defining properties with keys whose numeric value is beyond this range works — but they’re just ordinary properties (AEO [[DefineOwnProperty]] would exit via step 3)
But: setting a length greater than 2 ** 32 - 1 would lead to throwing a RangeError (ArraySetLength steps 3-5)
Array.from would try to set such a length when it finishes consuming the iterator (step 5.e.iv.1)
(I’d guess the reason from permits 2 ** 53 - 1 is because it’s meant to be “generic” rather than because Array itself is supposed to also permit it, though I dunno the history.)
Description:
All the array methods throw an error when they create an array longer than
2**53-1
(thus, when you exceed the index2**53-2
). However,Array.from(iterable)
throws one element earlier:https://tc39.es/ecma262/#sec-array.from
This code always checks if we reached the length
2**53-1
, but it throws before making sure that we are actually exceeding it. Looking at #352, it seems like the intention was to throw when exceeding2**53-1
.I think step
e.i
should be moved after stepe.iv
.Additionally, I think we should introduce a similar check in the
Array.from(arrayLike)
case (Array.from({ length: 2**53 })
should throw), but that's a bigger normative change.eshost Output:
I don't understand these eshost results, and in Node.js it segfaults.
The text was updated successfully, but these errors were encountered: