Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: allow respondWithNewView on byob auto allocated webstreams #41887

Merged
merged 1 commit into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/webstreams/readablestream.js
Expand Up @@ -2604,6 +2604,7 @@ function readableByteStreamControllerPullSteps(controller, readRequest) {
pendingPullIntos,
{
buffer,
bufferByteLength: autoAllocateChunkSize,
byteOffset: 0,
byteLength: autoAllocateChunkSize,
bytesFilled: 0,
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-whatwg-readablebytestream.js
Expand Up @@ -232,3 +232,33 @@ class Source {
code: 'ERR_INVALID_STATE',
});
}

{
const stream = new ReadableStream({
type: 'bytes',
pull(c) {
const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
v.set([20, 21, 22]);
c.byobRequest.respondWithNewView(v);
},
});
const buffer = new ArrayBuffer(10);
const view = new Uint8Array(buffer, 0, 3);
view.set([10, 11, 12]);
const reader = stream.getReader({ mode: 'byob' });
reader.read(view);
}

{
const stream = new ReadableStream({
type: 'bytes',
autoAllocateChunkSize: 10,
pull(c) {
const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
v.set([20, 21, 22]);
c.byobRequest.respondWithNewView(v);
},
});
const reader = stream.getReader();
reader.read();
}