Skip to content

Commit d6fc855

Browse files
deokjinkimjuanarbol
authored andcommitted
lib: refactor to use validate function
Throwing error after checking type is repeated. So replace it with validate function. PR-URL: #46101 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 1b0cc79 commit d6fc855

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

lib/_http_client.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,10 @@ function ClientRequest(input, options, cb) {
228228
this.maxHeaderSize = maxHeaderSize;
229229

230230
const insecureHTTPParser = options.insecureHTTPParser;
231-
if (insecureHTTPParser !== undefined &&
232-
typeof insecureHTTPParser !== 'boolean') {
233-
throw new ERR_INVALID_ARG_TYPE(
234-
'options.insecureHTTPParser', 'boolean', insecureHTTPParser);
231+
if (insecureHTTPParser !== undefined) {
232+
validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
235233
}
234+
236235
this.insecureHTTPParser = insecureHTTPParser;
237236

238237
if (options.joinDuplicateHeaders !== undefined) {

lib/_tls_wrap.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -1224,21 +1224,16 @@ function Server(options, listener) {
12241224

12251225
validateNumber(this[kHandshakeTimeout], 'options.handshakeTimeout');
12261226

1227-
if (this[kSNICallback] && typeof this[kSNICallback] !== 'function') {
1228-
throw new ERR_INVALID_ARG_TYPE(
1229-
'options.SNICallback', 'function', options.SNICallback);
1227+
if (this[kSNICallback]) {
1228+
validateFunction(this[kSNICallback], 'options.SNICallback');
12301229
}
12311230

1232-
if (this[kPskCallback] && typeof this[kPskCallback] !== 'function') {
1233-
throw new ERR_INVALID_ARG_TYPE(
1234-
'options.pskCallback', 'function', options.pskCallback);
1231+
if (this[kPskCallback]) {
1232+
validateFunction(this[kPskCallback], 'options.pskCallback');
12351233
}
1236-
if (this[kPskIdentityHint] && typeof this[kPskIdentityHint] !== 'string') {
1237-
throw new ERR_INVALID_ARG_TYPE(
1238-
'options.pskIdentityHint',
1239-
'string',
1240-
options.pskIdentityHint
1241-
);
1234+
1235+
if (this[kPskIdentityHint]) {
1236+
validateString(this[kPskIdentityHint], 'options.pskIdentityHint');
12421237
}
12431238

12441239
// constructor call

lib/async_hooks.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const {
1818
const {
1919
ERR_ASYNC_CALLBACK,
2020
ERR_ASYNC_TYPE,
21-
ERR_INVALID_ARG_TYPE,
2221
ERR_INVALID_ASYNC_ID
2322
} = require('internal/errors').codes;
2423
const { kEmptyObject } = require('internal/util');
@@ -280,10 +279,8 @@ class AsyncLocalStorage {
280279
validateObject(options, 'options');
281280

282281
const { onPropagate = null } = options;
283-
if (onPropagate !== null && typeof onPropagate !== 'function') {
284-
throw new ERR_INVALID_ARG_TYPE('options.onPropagate',
285-
'function',
286-
onPropagate);
282+
if (onPropagate !== null) {
283+
validateFunction(onPropagate, 'options.onPropagate');
287284
}
288285

289286
this.kResourceStore = Symbol('kResourceStore');

0 commit comments

Comments
 (0)