Files
scriptc/tests
Chris Tate 1ea8a6c467 Skip the element read for array callbacks that never use it
A callback that declares no element parameter, or binds it to a name
that appears nowhere else in the function (`filter(() => true)`,
`map((_, i) => i)`, `reduce((s, v) => s + 1, 0)`), no longer gets the
element read and converted for each visit. The helpers and the fused
loops pass a constant of the parameter's type in its place (NaN, "",
false, or the undefined arm of a union that has one); other parameter
types keep the read.

An array holding an element its type cannot hold, written through an
unknown[] view, threw a TypeError at that element for every callback
method. With such callbacks it now behaves as in Node:

- map, flatMap, forEach, some, every, findIndex, findLastIndex, reduce
  and reduceRight visit it without reading it;
- filter appends each kept element as it is stored, so the written value
  stays in the result as the view's push would store it;
- find and findLast read the element only once the predicate holds.

Callbacks that read the element keep the TypeError for a value their
parameter type cannot hold.
2026-10-25 19:36:55 -05:00
..
2026-10-25 10:55:32 -05:00
…