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
6 changes: 6 additions & 0 deletions lib/internal/streams/iter/broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ class BroadcastWriter {
}

writev(chunks, options) {
if (!ArrayIsArray(chunks)) {
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
}
// Fast path: no signal, writer open, buffer has space
if (this.#canUseWriteFastPath(options)) {
const converted = convertChunks(chunks);
Expand Down Expand Up @@ -522,6 +525,9 @@ class BroadcastWriter {
}

writevSync(chunks) {
if (!ArrayIsArray(chunks)) {
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
}
if (this.#isClosedOrAborted()) return false;
if (!this.#broadcast[kCanWrite]()) return false;
const converted = convertChunks(chunks);
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-stream-iter-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ assert.throws(() => broadcast({ highWaterMark: Number.MAX_SAFE_INTEGER + 1 }),
assert.throws(() => broadcast({ signal: {} }), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => broadcast({ backpressure: 'bad' }), { code: 'ERR_INVALID_ARG_VALUE' });

// BroadcastWriter.writev requires array
{
const { writer } = broadcast();
assert.throws(() => writer.writev('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => writer.writev(42), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => writer.writevSync('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => writer.writevSync(42), { code: 'ERR_INVALID_ARG_TYPE' });
writer.endSync();
}

// Broadcast.from rejects non-iterable input
assert.throws(() => Broadcast.from(42), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => Broadcast.from('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
Expand Down
Loading