Skip to content

stream/iter: arrayBuffer consumers return SharedArrayBuffer for SAB-backed chunks #64381

Description

@trivikr

Version

main

Platform

macOS 26.5.2

Subsystem

stream

What steps will reproduce the bug?

import { arrayBuffer, arrayBufferSync } from 'node:stream/iter';

const shared = new SharedArrayBuffer(4);
const chunk = new Uint8Array(shared);

const asyncResult = await arrayBuffer([chunk]);
const syncResult = arrayBufferSync([chunk]);

console.log('arrayBuffer():', asyncResult.constructor.name);
console.log('arrayBufferSync():', syncResult.constructor.name);
console.log('async instanceof ArrayBuffer:', asyncResult instanceof ArrayBuffer);
console.log('sync instanceof ArrayBuffer:', syncResult instanceof ArrayBuffer);

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

arrayBuffer(): ArrayBuffer
arrayBufferSync(): ArrayBuffer
async instanceof ArrayBuffer: true
sync instanceof ArrayBuffer: true

Spec §11.3 says

  1. Let bytes be the result of bytes() with source and options.

Spec §11.1 says

  1. If chunks has exactly one element whose buffer is not shared, return that element.
  2. Otherwise, concatenate all chunks into a new Uint8Array and return it.

What do you see instead?

arrayBuffer(): SharedArrayBuffer
arrayBufferSync(): SharedArrayBuffer
async instanceof ArrayBuffer: false
sync instanceof ArrayBuffer: false

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions