Skip to content

Commit

Permalink
stream: refactor to use validateFunction
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
deokjinkim authored and RafaelGSS committed Jan 4, 2023
1 parent 8e96c99 commit 57274a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const {

const {
validateBoolean,
validateFunction,
validateObject,
} = require('internal/validators');

Expand Down Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions lib/internal/webstreams/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const {

const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OPERATION_FAILED,
},
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 57274a8

Please sign in to comment.