Skip to content

Commit d5ad01d

Browse files
MattiasBuelensDanielRyanSmith
authored andcommitted
Test interaction between autoAllocateChunkSize and respondWithNewView (web-platform-tests#32757)
See whatwg/streams#1216 for context. Upstreamed from nodejs/node#41887.
1 parent 057e18e commit d5ad01d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

streams/readable-byte-streams/bad-buffers-and-views.any.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ async_test(t => {
250250
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
251251
'different length (in the readable state)');
252252

253+
async_test(t => {
254+
// Tests https://github.com/nodejs/node/issues/41886
255+
const stream = new ReadableStream({
256+
pull: t.step_func_done(c => {
257+
const view = new Uint8Array(new ArrayBuffer(11), 0, 3);
258+
259+
assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
260+
}),
261+
type: 'bytes',
262+
autoAllocateChunkSize: 10
263+
});
264+
const reader = stream.getReader();
265+
266+
reader.read();
267+
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
268+
'different length (autoAllocateChunkSize)');
269+
253270
async_test(t => {
254271
const stream = new ReadableStream({
255272
pull: t.step_func_done(c => {

streams/readable-byte-streams/general.any.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,3 +2876,26 @@ promise_test(async t => {
28762876

28772877
}, 'ReadableStream with byte source: read(view) with 1 element Uint16Array, respond(1), releaseLock(), read() on ' +
28782878
'second reader, enqueue()');
2879+
2880+
promise_test(async t => {
2881+
// Tests https://github.com/nodejs/node/issues/41886
2882+
const stream = new ReadableStream({
2883+
type: 'bytes',
2884+
autoAllocateChunkSize: 10,
2885+
pull: t.step_func((c) => {
2886+
const newView = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
2887+
newView.set([20, 21, 22]);
2888+
c.byobRequest.respondWithNewView(newView);
2889+
})
2890+
});
2891+
2892+
const reader = stream.getReader();
2893+
const result = await reader.read();
2894+
assert_false(result.done, 'result.done');
2895+
2896+
const view = result.value;
2897+
assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
2898+
assert_equals(view.byteLength, 3, 'result.value.byteLength');
2899+
assert_equals(view.buffer.byteLength, 10, 'result.value.buffer.byteLength');
2900+
assert_array_equals([...new Uint8Array(view)], [20, 21, 22], 'result.value');
2901+
}, 'ReadableStream with byte source: autoAllocateChunkSize, read(), respondWithNewView()');

0 commit comments

Comments
 (0)