Skip to content

Commit ed2faa7

Browse files
debadree25danielleadams
authored andcommitted
stream: fix respondWithNewView() errors when view.byteOffset != 0
Fixes: #42851 Refs: https://github.com/whatwg/streams/blob/f894acdd417926a2121710803cef593e15127964/reference-implementation/lib/abstract-ops/readable-streams.js#L1756 PR-URL: #46465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent ea71a2a commit ed2faa7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/internal/webstreams/readablestream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2965,7 +2965,7 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
29652965
if (byteOffset + bytesFilled !== viewByteOffset)
29662966
throw new ERR_INVALID_ARG_VALUE.RangeError('view', view);
29672967

2968-
if (bytesFilled + viewByteOffset > byteLength)
2968+
if (bytesFilled + viewByteLength > byteLength)
29692969
throw new ERR_INVALID_ARG_VALUE.RangeError('view', view);
29702970

29712971
if (bufferByteLength !== viewBufferByteLength)

test/parallel/test-whatwg-readablestream.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,3 +1657,33 @@ class Source {
16571657
reader.read(new DataView(buffer))
16581658
.then(common.mustCall());
16591659
}
1660+
1661+
{
1662+
const stream = new ReadableStream({
1663+
type: 'bytes',
1664+
autoAllocateChunkSize: 128,
1665+
pull: common.mustCall((controller) => {
1666+
const view = controller.byobRequest.view;
1667+
const dest = new Uint8Array(
1668+
view.buffer,
1669+
view.byteOffset,
1670+
view.byteLength
1671+
);
1672+
dest.fill(1);
1673+
controller.byobRequest.respondWithNewView(dest);
1674+
}),
1675+
});
1676+
1677+
const reader = stream.getReader({ mode: 'byob' });
1678+
1679+
const buffer = new ArrayBuffer(10);
1680+
const view = new Uint8Array(
1681+
buffer,
1682+
1,
1683+
3
1684+
);
1685+
1686+
reader.read(view).then(common.mustCall(({ value }) => {
1687+
assert.deepStrictEqual(value, new Uint8Array([1, 1, 1]));
1688+
}));
1689+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy