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: use validateNumber for BYOB reader options.min · nodejs/node@4f6f2cf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • readablestream.js
  • test/parallel
    • test-whatwg-readablestream-byob-read-min.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/readablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const {
6262
const {
6363
validateAbortSignal,
6464
validateBuffer,
65+
validateNumber,
6566
validateObject,
6667
kValidateObjectAllowObjects,
6768
kValidateObjectAllowObjectsAndNull,
@@ -1086,8 +1087,7 @@ class ReadableStreamBYOBReader {
10861087
// detached, but there's no API available to use to check that.
10871088

10881089
const min = options?.min ?? 1;
1089-
if (typeof min !== 'number')
1090-
throw new ERR_INVALID_ARG_TYPE('options.min', 'number', min);
1090+
validateNumber(min, 'options.min');
10911091
if (!NumberIsInteger(min))
10921092
throw new ERR_INVALID_ARG_VALUE('options.min', min, 'must be an integer');
10931093
if (min <= 0)
Collapse file

‎test/parallel/test-whatwg-readablestream-byob-read-min.js‎

Copy file name to clipboard
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('node:assert');
4+
5+
const {
6+
ReadableStream,
7+
} = require('node:stream/web');
8+
9+
// Validation of the options.min argument of ReadableStreamBYOBReader.read()
10+
// must reject with the same errors regardless of how the checks are implemented internally.
11+
12+
const reader = new ReadableStream({ type: 'bytes' })
13+
.getReader({ mode: 'byob' });
14+
15+
(async () => {
16+
// A null min is not covered here: `options?.min ?? 1` turns it into
17+
// the default before validation, so it never reaches the type check.
18+
for (const min of ['1', true, {}, [], 1n]) {
19+
await assert.rejects(
20+
reader.read(new Uint8Array(8), { min }),
21+
{ code: 'ERR_INVALID_ARG_TYPE' },
22+
);
23+
}
24+
25+
for (const min of [NaN, 1.5, 0, -1]) {
26+
await assert.rejects(
27+
reader.read(new Uint8Array(8), { min }),
28+
{ code: 'ERR_INVALID_ARG_VALUE' },
29+
);
30+
}
31+
32+
await assert.rejects(
33+
reader.read(new Uint8Array(8), { min: 9 }),
34+
{ code: 'ERR_OUT_OF_RANGE' },
35+
);
36+
37+
await assert.rejects(
38+
reader.read(new DataView(new ArrayBuffer(8)), { min: 9 }),
39+
{ code: 'ERR_OUT_OF_RANGE' },
40+
);
41+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.