Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 93e91f3

Browse filesBrowse files
debadree25targos
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 9c7a2e3 commit 93e91f3
Copy full SHA for 93e91f3

File tree

Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/webstreams/readablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js
+1-1Lines 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)
Collapse file

‎test/parallel/test-whatwg-readablestream.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-readablestream.js
+30Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.