Skip to main content

Module js_iterator

Module js_iterator 

Source
Expand description

The one { value, done } iterator protocol used by every web-platform collection class (Headers, URLSearchParams, FormData).

WHATWG iteration is LIVE: mutations made during a loop are observed, so for (const [k] of params) params.delete(k) behaves as it does in Node. The iterator therefore holds no snapshot — it re-reads its parent on every next().

The parent is carried as a property ON the iterator object, which the JS GC traces, and re-read per call. The native next closure captures nothing from the JS heap, per the GC-cycle discipline: a closure that captured the parent Class would be invisible to the collector and could strand the runtime at teardown.

Functions§

live_iterator
Build a live iterator over parent, projecting each position through project. The result is itself iterable ([Symbol.iterator] returns this), so it works with for..of, spread and Array.from.

Type Aliases§

Project
Yield the entry at index, or None once the collection is exhausted. Called with the parent freshly borrowed, so it always sees current state.