lib: refactor to use validate function

Throwing error after checking type is repeated. So replace
it with validate function.

PR-URL: https://github.com/nodejs/node/pull/46101
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
Deokjin Kim authored and Juan José Arboleda committed 2023-01-31 08:04:19 -05:00
1 parent 1b0cc79785
commit d6fc855b8a
3 files changed
+12 -21

No files matched your search

+3 -4
View File
@@ -228,11 +228,10 @@ function ClientRequest(input, options, cb) {
this.maxHeaderSize = maxHeaderSize;
const insecureHTTPParser = options.insecureHTTPParser;
if (insecureHTTPParser !== undefined &&
typeof insecureHTTPParser !== 'boolean') {
throw new ERR_INVALID_ARG_TYPE(
'options.insecureHTTPParser', 'boolean', insecureHTTPParser);
if (insecureHTTPParser !== undefined) {
validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
}
this.insecureHTTPParser = insecureHTTPParser;
if (options.joinDuplicateHeaders !== undefined) {
+7 -12
View File
@@ -1224,21 +1224,16 @@ function Server(options, listener) {
validateNumber(this[kHandshakeTimeout], 'options.handshakeTimeout');
if (this[kSNICallback] && typeof this[kSNICallback] !== 'function') {
throw new ERR_INVALID_ARG_TYPE(
'options.SNICallback', 'function', options.SNICallback);
if (this[kSNICallback]) {
validateFunction(this[kSNICallback], 'options.SNICallback');
}
if (this[kPskCallback] && typeof this[kPskCallback] !== 'function') {
throw new ERR_INVALID_ARG_TYPE(
'options.pskCallback', 'function', options.pskCallback);
if (this[kPskCallback]) {
validateFunction(this[kPskCallback], 'options.pskCallback');
}
if (this[kPskIdentityHint] && typeof this[kPskIdentityHint] !== 'string') {
throw new ERR_INVALID_ARG_TYPE(
'options.pskIdentityHint',
'string',
options.pskIdentityHint
);
if (this[kPskIdentityHint]) {
validateString(this[kPskIdentityHint], 'options.pskIdentityHint');
}
// constructor call
+2 -5
View File
@@ -18,7 +18,6 @@ const {
const {
ERR_ASYNC_CALLBACK,
ERR_ASYNC_TYPE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ASYNC_ID
} = require('internal/errors').codes;
const { kEmptyObject } = require('internal/util');
@@ -280,10 +279,8 @@ class AsyncLocalStorage {
validateObject(options, 'options');
const { onPropagate = null } = options;
if (onPropagate !== null && typeof onPropagate !== 'function') {
throw new ERR_INVALID_ARG_TYPE('options.onPropagate',
'function',
onPropagate);
if (onPropagate !== null) {
validateFunction(onPropagate, 'options.onPropagate');
}
this.kResourceStore = Symbol('kResourceStore');