Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refactor to use validate function #46101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/_http_client.js
Expand Up @@ -223,11 +223,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) {
Expand Down
19 changes: 7 additions & 12 deletions lib/_tls_wrap.js
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions lib/async_hooks.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down