diff --git a/lib/_http_client.js b/lib/_http_client.js index 4c2f39ed067a83..3324cf69f1f074 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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) { diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 65db04e76901b0..78fe3191dc86d5 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -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 diff --git a/lib/async_hooks.js b/lib/async_hooks.js index c120a4828855e9..bf76874ffe2c1b 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -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');