Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const {
const {
validateAbortSignal,
validateBuffer,
validateNumber,
validateObject,
kValidateObjectAllowObjects,
kValidateObjectAllowObjectsAndNull,
Expand Down Expand Up @@ -1095,8 +1096,7 @@ class ReadableStreamBYOBReader {
// detached, but there's no API available to use to check that.

const min = options?.min ?? 1;
if (typeof min !== 'number')
throw new ERR_INVALID_ARG_TYPE('options.min', 'number', min);
validateNumber(min, 'options.min');
if (!NumberIsInteger(min))
throw new ERR_INVALID_ARG_VALUE('options.min', min, 'must be an integer');
if (min <= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,38 @@ let pass = 0;
.then(common.mustCall());
}

{
// options.min must be a number.
const stream = new ReadableStream({
start(c) {
c.enqueue(new Uint8Array([1, 2, 3]));
},
type: 'bytes',
});
const reader = stream.getReader({ mode: 'byob' });

assert
.rejects(reader.read(new Uint8Array(3), { min: 'not a number' }), {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
})
.then(common.mustCall());
}

{
// A valid numeric options.min still works as expected.
const stream = new ReadableStream({
start(c) {
c.enqueue(new Uint8Array([1, 2, 3]));
},
type: 'bytes',
});
const reader = stream.getReader({ mode: 'byob' });

reader.read(new Uint8Array(3), { min: 1 }).then(common.mustCall(({ value, done }) => {
assert.strictEqual(done, false);
assert.deepStrictEqual([...value], [1, 2, 3]);
}));
}

process.on('exit', () => assert.strictEqual(pass, 2));
Loading