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

Streams: test interaction between autoAllocateChunkSize and respondWithNewView #32757

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
17 changes: 17 additions & 0 deletions streams/readable-byte-streams/bad-buffers-and-views.any.js
Expand Up @@ -250,6 +250,23 @@ async_test(t => {
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
'different length (in the readable state)');

async_test(t => {
// Tests https://github.com/nodejs/node/issues/41886
const stream = new ReadableStream({
pull: t.step_func_done(c => {
const view = new Uint8Array(new ArrayBuffer(11), 0, 3);

assert_throws_js(RangeError, () => c.byobRequest.respondWithNewView(view));
}),
type: 'bytes',
autoAllocateChunkSize: 10
});
const reader = stream.getReader();

reader.read();
}, 'ReadableStream with byte source: respondWithNewView() throws if the supplied view\'s buffer has a ' +
'different length (autoAllocateChunkSize)');

async_test(t => {
const stream = new ReadableStream({
pull: t.step_func_done(c => {
Expand Down
23 changes: 23 additions & 0 deletions streams/readable-byte-streams/general.any.js
Expand Up @@ -2876,3 +2876,26 @@ promise_test(async t => {

}, 'ReadableStream with byte source: read(view) with 1 element Uint16Array, respond(1), releaseLock(), read() on ' +
'second reader, enqueue()');

promise_test(async t => {
// Tests https://github.com/nodejs/node/issues/41886
const stream = new ReadableStream({
type: 'bytes',
autoAllocateChunkSize: 10,
pull: t.step_func((c) => {
const newView = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
newView.set([20, 21, 22]);
c.byobRequest.respondWithNewView(newView);
})
});

const reader = stream.getReader();
const result = await reader.read();
assert_false(result.done, 'result.done');

const view = result.value;
assert_equals(view.byteOffset, 0, 'result.value.byteOffset');
assert_equals(view.byteLength, 3, 'result.value.byteLength');
assert_equals(view.buffer.byteLength, 10, 'result.value.buffer.byteLength');
assert_array_equals([...new Uint8Array(view)], [20, 21, 22], 'result.value');
}, 'ReadableStream with byte source: autoAllocateChunkSize, read(), respondWithNewView()');