GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: validate broadcast writer writev chunks · nodejs/node@f63143f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/streams/iter
    • broadcast.js
  • test/parallel
    • test-stream-iter-validation.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/streams/iter/broadcast.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/iter/broadcast.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ class BroadcastWriter {
463463
}
464464

465465
writev(chunks, options) {
466+
if (!ArrayIsArray(chunks)) {
467+
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
468+
}
466469
// Fast path: no signal, writer open, buffer has space
467470
if (this.#canUseWriteFastPath(options)) {
468471
const converted = convertChunks(chunks);
@@ -523,6 +526,9 @@ class BroadcastWriter {
523526
}
524527

525528
writevSync(chunks) {
529+
if (!ArrayIsArray(chunks)) {
530+
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
531+
}
526532
if (this.#isClosedOrAborted()) return false;
527533
if (!this.#broadcast[kCanWrite]()) return false;
528534
const converted = convertChunks(chunks);
Collapse file

‎test/parallel/test-stream-iter-validation.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-iter-validation.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ assert.throws(() => broadcast({ highWaterMark: Number.MAX_SAFE_INTEGER + 1 }),
147147
assert.throws(() => broadcast({ signal: {} }), { code: 'ERR_INVALID_ARG_TYPE' });
148148
assert.throws(() => broadcast({ backpressure: 'bad' }), { code: 'ERR_INVALID_ARG_VALUE' });
149149

150+
// BroadcastWriter.writev requires array
151+
{
152+
const { writer } = broadcast();
153+
assert.throws(() => writer.writev('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
154+
assert.throws(() => writer.writev(42), { code: 'ERR_INVALID_ARG_TYPE' });
155+
assert.throws(() => writer.writevSync('bad'), { code: 'ERR_INVALID_ARG_TYPE' });
156+
assert.throws(() => writer.writevSync(42), { code: 'ERR_INVALID_ARG_TYPE' });
157+
writer.endSync();
158+
}
159+
150160
// Broadcast.from rejects non-iterable input
151161
assert.throws(() => Broadcast.from(42), { code: 'ERR_INVALID_ARG_TYPE' });
152162
assert.throws(() => Broadcast.from('bad'), { code: 'ERR_INVALID_ARG_TYPE' });

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.