ReviewOS

zig-utils/zig-js

ABI: implement exact iterable callback traversal

#237
Closed chris opened this 9 days ago ·
9 days ago

Parent: #134 Related: #140, #163, #164

Implement the pinned JSC__JSValue__forEach private-ABI boundary as a real iterator-protocol traversal with a native callback per yielded value.

Acceptance

  • Perform exact GetMethod(value, @@iterator), iterator creation, cached next lookup, IteratorStep, and IteratorValue ordering for arrays, strings, Map/Set, generators, and custom iterables.
  • Invoke the native callback once per yielded value with the selected global, VM identity, opaque callback context, and stable EncodedJSValue identity.
  • Preserve getter/proxy/custom-iterator observability and stop on abrupt completion; close an open iterator when the callback publishes an exception, retaining the original first-wins exception if return() also throws.
  • Accept same-VM sibling values, reject foreign-VM handles, and leave an already-pending exception untouched without advancing the iterable.
  • Add focused normal/leak coverage and the pinned consumer compile-link-runtime fixture.
  • Update generated Home/Bun inventories, README/docs counts, and all parent issue evidence from committed artifacts.
9 days ago

Completed on main in two small commits: implementation and focused/consumer coverage at 815bbb87, then generated inventories and README/docs evidence at 839b4743.

Evidence:

  • exact @@iterator lookup/call, cached next, IteratorStep, and IteratorValue order
  • arrays, code-point strings, Set, Map entries, generators, and observable custom iterators
  • stable yielded object/primitive EncodedJSValue identity with exact VM/global/context callback metadata
  • callback-published abrupt completion performs IteratorClose; a throwing return() cannot replace the first exception
  • same-VM sibling acceptance, foreign-VM rejection, and pre-existing pending-state preservation
  • focused unit matrix: 3/3 passed, 0 leaked
  • pinned consumer fixture: 229/229 symbols linked; runtime matrix passed
  • Home audit: 230/431 implemented, 201 pending, 0 unclassified
  • Bun core audit: 224/421 implemented, 197 pending, 0 unclassified
  • public classification: 117 public, 19 extensions, 234 private/support exports

The committed 1,540-sample JSC benchmark artifact remains 36a617b3; this ABI-only slice did not regenerate performance scores.

Sign in to comment on this issue.