Skip to content

Commit

Permalink
Bug 1754322 [wpt PR 32757] - Streams: test interaction between autoAl…
Browse files Browse the repository at this point in the history
…locateChunkSize and respondWithNewView, a=testonly

Automatic update from web-platform-tests
Test interaction between autoAllocateChunkSize and respondWithNewView (#32757)

See whatwg/streams#1216 for context.

Upstreamed from nodejs/node#41887.
--

wpt-commits: 6a46d9cb8d20c510a620141c721b81b460a4ee55
wpt-pr: 32757
  • Loading branch information
MattiasBuelens authored and moz-wptsync-bot committed Mar 7, 2022
1 parent ba8ac6c commit e31df41
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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
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()');

0 comments on commit e31df41

Please sign in to comment.