Skip to content

Commit ab22a8f

Browse files
deokjinkimRafaelGSS
authored andcommitted
stream: refactor to use validateFunction
PR-URL: #46007 Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 2d49e0e commit ab22a8f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/internal/webstreams/adapters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const {
6464

6565
const {
6666
validateBoolean,
67+
validateFunction,
6768
validateObject,
6869
} = require('internal/validators');
6970

@@ -924,8 +925,7 @@ function newReadableStreamFromStreamBase(streamBase, strategy, options = kEmptyO
924925
if (typeof streamBase.onread === 'function')
925926
throw new ERR_INVALID_STATE('StreamBase already has a consumer');
926927

927-
if (typeof ondone !== 'function')
928-
throw new ERR_INVALID_ARG_TYPE('options.ondone', 'Function', ondone);
928+
validateFunction(ondone, 'options.ondone');
929929

930930
let controller;
931931

lib/internal/webstreams/util.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const {
1919

2020
const {
2121
codes: {
22-
ERR_INVALID_ARG_TYPE,
2322
ERR_INVALID_ARG_VALUE,
2423
ERR_OPERATION_FAILED,
2524
},
@@ -48,6 +47,10 @@ const {
4847
const assert = require('internal/assert');
4948
const { isArrayBufferDetached } = require('internal/util');
5049

50+
const {
51+
validateFunction,
52+
} = require('internal/validators');
53+
5154
const kState = Symbol('kState');
5255
const kType = Symbol('kType');
5356

@@ -78,8 +81,7 @@ function extractHighWaterMark(value, defaultHWM) {
7881

7982
function extractSizeAlgorithm(size) {
8083
if (size === undefined) return () => 1;
81-
if (typeof size !== 'function')
82-
throw new ERR_INVALID_ARG_TYPE('strategy.size', 'Function', size);
84+
validateFunction(size, 'strategy.size');
8385
return size;
8486
}
8587

0 commit comments

Comments
 (0)