mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
stream: fix respondWithNewView() errors when view.byteOffset != 0
Fixes: https://github.com/nodejs/node/issues/42851 Refs: https://github.com/whatwg/streams/blob/f894acdd417926a2121710803cef593e15127964/reference-implementation/lib/abstract-ops/readable-streams.js#L1756 PR-URL: https://github.com/nodejs/node/pull/46465 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
1 parent
9c7a2e30fb
commit
93e91f3dde
2 files changed
+31
-1
No files matched your search
@@ -2965,7 +2965,7 @@ function readableByteStreamControllerRespondWithNewView(controller, view) {
|
||||
if (byteOffset + bytesFilled !== viewByteOffset)
|
||||
throw new ERR_INVALID_ARG_VALUE.RangeError('view', view);
|
||||
|
||||
if (bytesFilled + viewByteOffset > byteLength)
|
||||
if (bytesFilled + viewByteLength > byteLength)
|
||||
throw new ERR_INVALID_ARG_VALUE.RangeError('view', view);
|
||||
|
||||
if (bufferByteLength !== viewBufferByteLength)
|
||||
|
||||
@@ -1657,3 +1657,33 @@ class Source {
|
||||
reader.read(new DataView(buffer))
|
||||
.then(common.mustCall());
|
||||
}
|
||||
|
||||
{
|
||||
const stream = new ReadableStream({
|
||||
type: 'bytes',
|
||||
autoAllocateChunkSize: 128,
|
||||
pull: common.mustCall((controller) => {
|
||||
const view = controller.byobRequest.view;
|
||||
const dest = new Uint8Array(
|
||||
view.buffer,
|
||||
view.byteOffset,
|
||||
view.byteLength
|
||||
);
|
||||
dest.fill(1);
|
||||
controller.byobRequest.respondWithNewView(dest);
|
||||
}),
|
||||
});
|
||||
|
||||
const reader = stream.getReader({ mode: 'byob' });
|
||||
|
||||
const buffer = new ArrayBuffer(10);
|
||||
const view = new Uint8Array(
|
||||
buffer,
|
||||
1,
|
||||
3
|
||||
);
|
||||
|
||||
reader.read(view).then(common.mustCall(({ value }) => {
|
||||
assert.deepStrictEqual(value, new Uint8Array([1, 1, 1]));
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user