Skip to content

Commit 4ad5a28

Browse files
VoltrexKeyvatargos
authored andcommitted
stream: refactor to use more validators
Use more validators where appropriate for consistency. PR-URL: #41871 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 545b2cd commit 4ad5a28

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/internal/streams/operators.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
const {
1414
validateAbortSignal,
1515
validateInteger,
16+
validateObject,
1617
} = require('internal/validators');
1718
const { kWeakHandler } = require('internal/event_target');
1819
const { finished } = require('internal/streams/end-of-stream');
@@ -36,8 +37,8 @@ function map(fn, options) {
3637
throw new ERR_INVALID_ARG_TYPE(
3738
'fn', ['Function', 'AsyncFunction'], fn);
3839
}
39-
if (options != null && typeof options !== 'object') {
40-
throw new ERR_INVALID_ARG_TYPE('options', ['Object']);
40+
if (options != null) {
41+
validateObject(options, 'options');
4142
}
4243
if (options?.signal != null) {
4344
validateAbortSignal(options.signal, 'options.signal');
@@ -167,8 +168,8 @@ function map(fn, options) {
167168
}
168169

169170
function asIndexedPairs(options = undefined) {
170-
if (options != null && typeof options !== 'object') {
171-
throw new ERR_INVALID_ARG_TYPE('options', ['Object']);
171+
if (options != null) {
172+
validateObject(options, 'options');
172173
}
173174
if (options?.signal != null) {
174175
validateAbortSignal(options.signal, 'options.signal');
@@ -252,8 +253,8 @@ async function reduce(reducer, initialValue, options) {
252253
throw new ERR_INVALID_ARG_TYPE(
253254
'reducer', ['Function', 'AsyncFunction'], reducer);
254255
}
255-
if (options != null && typeof options !== 'object') {
256-
throw new ERR_INVALID_ARG_TYPE('options', ['Object']);
256+
if (options != null) {
257+
validateObject(options, 'options');
257258
}
258259
if (options?.signal != null) {
259260
validateAbortSignal(options.signal, 'options.signal');
@@ -296,8 +297,8 @@ async function reduce(reducer, initialValue, options) {
296297
}
297298

298299
async function toArray(options) {
299-
if (options != null && typeof options !== 'object') {
300-
throw new ERR_INVALID_ARG_TYPE('options', ['Object']);
300+
if (options != null) {
301+
validateObject(options, 'options');
301302
}
302303
if (options?.signal != null) {
303304
validateAbortSignal(options.signal, 'options.signal');
@@ -336,8 +337,8 @@ function toIntegerOrInfinity(number) {
336337
}
337338

338339
function drop(number, options = undefined) {
339-
if (options != null && typeof options !== 'object') {
340-
throw new ERR_INVALID_ARG_TYPE('options', ['Object']);
340+
if (options != null) {
341+
validateObject(options, 'options');
341342
}
342343
if (options?.signal != null) {
343344
validateAbortSignal(options.signal, 'options.signal');
@@ -360,8 +361,8 @@ function drop(number, options = undefined) {
360361
}
361362

362363
function take(number, options = undefined) {
363-
if (options != null && typeof options !== 'object') {
364-
throw new ERR_INVALID_ARG_TYPE('options', ['Object']);
364+
if (options != null) {
365+
validateObject(options, 'options');
365366
}
366367
if (options?.signal != null) {
367368
validateAbortSignal(options.signal, 'options.signal');

0 commit comments

Comments
 (0)