Skip to content

fix(buffer): materialize Buffer iterators via spread + Array.from (#3909)#3975

Merged
proggeramlug merged 2 commits into
mainfrom
hygiene-node-surface-c2
Jun 1, 2026
Merged

fix(buffer): materialize Buffer iterators via spread + Array.from (#3909)#3975
proggeramlug merged 2 commits into
mainfrom
hygiene-node-surface-c2

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

buf.keys(), buf.values(), and buf.entries() returned working iterator objects (.next() and for...of produced the right byte indices/values), but [...buf.keys()] and Array.from(buf.values()) returned an empty array.

js_array_clone_for_spread — the runtime helper behind array spread and Array.from — recognizes iterator objects by class id, but its is_array_iterator check listed only the array/map/set/iterator-helper class ids, not BUFFER_ITERATOR_CLASS_ID. A Buffer iterator therefore fell through to the array-like .length/[i] materialization path (which a Buffer iterator doesn't support), yielding nothing. Added the buffer iterator class id alongside the others so spread and Array.from drive its .next() protocol like every other iterator.

Testing

Verified byte-for-byte against node --experimental-strip-types:

[...buf.keys()]            → [0,1,2]
[...buf.values()]          → [byte values]
Array.from(buf.entries())  → [[i,v], …]

.next() and for...of (already working) stay covered. Added node-suite/buffer/iterator-spread regression fixture. Local suites green (perry-runtime, perry-hir), cargo fmt --check clean.

Closes #3909

Ralph Küpper added 2 commits June 1, 2026 14:15
)

buf.keys()/values()/entries() worked via .next() and for-of but spread
[...buf.keys()] / Array.from(buf.values()) returned an empty array — the
BUFFER_ITERATOR_CLASS_ID was missing from js_array_clone_for_spread's
is_array_iterator detection. Add it alongside the array/map/set/helper
iterator class ids. + node-suite regression fixture.
@proggeramlug proggeramlug merged commit 8c99f88 into main Jun 1, 2026
11 checks passed
@proggeramlug proggeramlug deleted the hygiene-node-surface-c2 branch June 1, 2026 12:19
proggeramlug pushed a commit to andrewtdiz/perry that referenced this pull request Jun 1, 2026
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.

node:buffer: Buffer keys/values/entries iterators return empty results

1 participant