stream: refactor to use `validateFunction`

PR-URL: https://github.com/nodejs/node/pull/46007
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
Deokjin Kim 2023-01-01 15:33:41 +09:00 committed by GitHub
parent e2dd139da0
commit 979ec87665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -64,6 +64,7 @@ const {
const {
validateBoolean,
validateFunction,
validateObject,
} = require('internal/validators');
@ -924,8 +925,7 @@ function newReadableStreamFromStreamBase(streamBase, strategy, options = kEmptyO
if (typeof streamBase.onread === 'function')
throw new ERR_INVALID_STATE('StreamBase already has a consumer');
if (typeof ondone !== 'function')
throw new ERR_INVALID_ARG_TYPE('options.ondone', 'Function', ondone);
validateFunction(ondone, 'options.ondone');
let controller;

View File

@ -19,7 +19,6 @@ const {
const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OPERATION_FAILED,
},
@ -48,6 +47,10 @@ const {
const assert = require('internal/assert');
const { isArrayBufferDetached } = require('internal/util');
const {
validateFunction,
} = require('internal/validators');
const kState = Symbol('kState');
const kType = Symbol('kType');
@ -78,8 +81,7 @@ function extractHighWaterMark(value, defaultHWM) {
function extractSizeAlgorithm(size) {
if (size === undefined) return () => 1;
if (typeof size !== 'function')
throw new ERR_INVALID_ARG_TYPE('strategy.size', 'Function', size);
validateFunction(size, 'strategy.size');
return size;
}