Skip to main content

to_array_length

Function to_array_length 

Source
pub fn to_array_length(v: &Value) -> Result<usize, String>
Expand description

ToUint32-validated array length — ECMA-262 10.4.2.2 ArrayCreate step 1 and 10.4.2.4 ArraySetLength step 3.

A length is legal only if ToUint32(v) equals ToNumber(v) exactly, so -1, 1.5, NaN, Infinity, 'x' and 2**32 are all RangeError: Invalid array length while '3' is 3 and -0 is 0 (measured on node v26.7.0: new Array(-0).length is 0, a.length = '3' leaves 3, a.length = 'x' throws). node-js validated none of them — it built [-1] from new Array(-1), silently ignored a.length = -1, and sat materializing four billion elements for a.length = 2**32.