mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
forEach, map, filter, some, every, find, findIndex, findLast, findLastIndex, reduce and reduceRight compile on every typed-array kind through one shared helper per method shape. The receiver, the callback and reduce's initial value evaluate in order before the helper runs; the helper reads the length once and each element when it visits it, so the callback's writes show in later elements. Callbacks receive the element, its index and the typed array (reduce's receive the accumulator first). map and filter return a new typed array of the receiver's kind, map storing each result with that kind's element conversion, and a Buffer's map and filter return a Buffer. reduce without an initial value throws Node's TypeError on an empty typed array. A thisArg keeps the fence, as for arrays. Fixes #1620 Co-authored-by: ejc3 <1694850+ejc3@users.noreply.github.com>