Skip to content

Commit ec5b594

Browse files
sbquinlanbengl
authored andcommitted
lib: allow respondWithNewView on byob auto allocated streams
Fixes: #41886 PR-URL: #41887 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent f6c6d7d commit ec5b594

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/internal/webstreams/readablestream.js

+1
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,7 @@ function readableByteStreamControllerPullSteps(controller, readRequest) {
26042604
pendingPullIntos,
26052605
{
26062606
buffer,
2607+
bufferByteLength: autoAllocateChunkSize,
26072608
byteOffset: 0,
26082609
byteLength: autoAllocateChunkSize,
26092610
bytesFilled: 0,

test/parallel/test-whatwg-readablebytestream.js

+30
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,33 @@ class Source {
232232
code: 'ERR_INVALID_STATE',
233233
});
234234
}
235+
236+
{
237+
const stream = new ReadableStream({
238+
type: 'bytes',
239+
pull(c) {
240+
const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
241+
v.set([20, 21, 22]);
242+
c.byobRequest.respondWithNewView(v);
243+
},
244+
});
245+
const buffer = new ArrayBuffer(10);
246+
const view = new Uint8Array(buffer, 0, 3);
247+
view.set([10, 11, 12]);
248+
const reader = stream.getReader({ mode: 'byob' });
249+
reader.read(view);
250+
}
251+
252+
{
253+
const stream = new ReadableStream({
254+
type: 'bytes',
255+
autoAllocateChunkSize: 10,
256+
pull(c) {
257+
const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
258+
v.set([20, 21, 22]);
259+
c.byobRequest.respondWithNewView(v);
260+
},
261+
});
262+
const reader = stream.getReader();
263+
reader.read();
264+
}

0 commit comments

Comments
 (0)