js-on-sx: reduce/reduceRight callback receives (acc, cur, idx, array)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

This commit is contained in:
2026-05-09 19:13:12 +00:00
parent 0655b942a5
commit d4be87166b
2 changed files with 12 additions and 2 deletions

View File

@@ -2624,7 +2624,11 @@
(cond
((>= i (len arr)) acc)
(else
(js-list-reduce-loop f (f acc (nth arr i)) arr (+ i 1))))))
(js-list-reduce-loop
f
(js-call-with-this js-undefined f (list acc (nth arr i) i arr))
arr
(+ i 1))))))
(define
js-list-find-loop
@@ -2773,7 +2777,11 @@
(if
(< i 0)
acc
(js-list-reduce-right-loop f (f acc (nth arr i)) arr (- i 1)))))
(js-list-reduce-right-loop
f
(js-call-with-this js-undefined f (list acc (nth arr i) i arr))
arr
(- i 1)))))
(define
js-list-keys-loop

View File

@@ -158,6 +158,8 @@ Each item: implement → tests → update progress. Mark `[x]` when tests green.
Append-only record of completed iterations. Loop writes one line per iteration: date, what was done, test count delta.
- 2026-05-09 — **`Array.prototype.reduce`/`reduceRight` callback receives `(acc, cur, idx, array)`.** Was calling `(f acc cur)` — only two args, no index, no source array. Per spec the reducer signature is `(accumulator, currentValue, currentIndex, array)`. Updated `js-list-reduce-loop` and `js-list-reduce-right-loop` to call via `js-call-with-this js-undefined f (list acc cur i arr)`. Result: built-ins/Array/prototype/reduce 6/30 → 8/30, reduceRight 6/30 → 8/30. Object 30/30 holds. conformance.sh: 148/148.
- 2026-05-09 — **`Array.prototype.find`/`findIndex`/`some`/`every` honour `thisArg` and pass `(value, index, array)`.** Same shape as the previous `forEach`/`map`/`filter` fix — these were calling `(f x)` directly. Updated each prototype method to extract optional `thisArg` (defaulting to globalThis when null/undefined) and route through `js-call-with-this` with the full `(value, index, array)` triple. Updated `js-list-find-loop` / `js-list-find-index-loop` / `js-list-some-loop` / `js-list-every-loop` to match. Result: built-ins/Array/prototype/find 5/30 → 6/30. Modest delta this round (most remaining failures need deeper Array semantics — sparse arrays, ToLength on `length`, etc.). Object 30/30, Map 18/30 unchanged. conformance.sh: 148/148.
- 2026-05-09 — **`Array.prototype.forEach`/`map`/`filter` honour `thisArg` and pass `(value, index, array)` to callback.** Was calling the callback with just `(value)` from a bare `(f x)` and ignoring the optional second `thisArg` parameter. Per spec, the callback receives `(value, index, array)` and `this` is `thisArg ?? globalThis` in non-strict. Updated the prototype methods to take `&rest args`, extract `thisArg` (defaulting to globalThis when null/undefined), and route through `js-call-with-this` with the full triple. Updated `js-list-foreach-loop` / `js-list-map-loop` / `js-list-filter-loop` accordingly. Result: built-ins/Array/prototype/forEach 2/30 → 9/30, filter 5/30 → 10/30. Array 18/30, Object 30/30, Map 18/30 unchanged. conformance.sh: 148/148.