Skip to content

fix: honour overridden array iterators in destructuring and spread - #7

Merged
jlongster merged 1 commit into
devfrom
array-iterator-protector
Nov 20, 2026
Merged

jlongster merged 1 commit into
devfrom
array-iterator-protector

Conversation

@jlongster

Copy link
Copy Markdown
Collaborator

Arrays were iterated directly, ignoring a program's replacement of Array.prototype[Symbol.iterator] or the built-in iterators' next.

  • A per-runtime Protector (src/runtime/objects.ts) is cleared, for the rest of the run, by any set/define/accessor/delete of those two keys on those two prototypes (one guard check in the already-slow property-write paths).
  • Arr/Arguments/Bytes iterator() and builtinCursor for built-in array iterators fall back to the iterator protocol when it is cleared, or when an array has its own [Symbol.iterator] or another prototype. This covers destructuring, spread, for...of, yield*, Array.from, Map/Set/Promise intake.
  • The flag is saved and restored with snapshots (an anchored Protector record).
  • Default derived constructors pass their arguments without iterating them, which the spec requires.
  • test262: 19408 → 19522 pass, 114 unskipped.
  • Bench (min, taskset, 8 pairs): array callbacks 108.4 → 100.4 ms, destructuring/spread (new case) 31.1 → 28.4 ms.

User decisions:
- Honour overridden array iterators with a single protector flag, keeping the fast path for code that doesn't override them
@jlongster
jlongster merged commit 67d21a5 into dev Nov 20, 2026
1 check passed
@jlongster
jlongster deleted the array-iterator-protector branch November 20, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant