Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1cfa2e6

Browse filesBrowse files
deokjinkimRafaelGSS
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 1aa4534 commit 1cfa2e6
Copy full SHA for 1cfa2e6

File tree

Expand file treeCollapse file tree

3 files changed

+12
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-21
lines changed
Open diff view settings
Collapse file

‎lib/_http_client.js‎

Copy file name to clipboardExpand all lines: lib/_http_client.js
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,10 @@ function ClientRequest(input, options, cb) {
223223
this.maxHeaderSize = maxHeaderSize;
224224

225225
const insecureHTTPParser = options.insecureHTTPParser;
226-
if (insecureHTTPParser !== undefined &&
227-
typeof insecureHTTPParser !== 'boolean') {
228-
throw new ERR_INVALID_ARG_TYPE(
229-
'options.insecureHTTPParser', 'boolean', insecureHTTPParser);
226+
if (insecureHTTPParser !== undefined) {
227+
validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
230228
}
229+
231230
this.insecureHTTPParser = insecureHTTPParser;
232231

233232
if (options.joinDuplicateHeaders !== undefined) {
Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+7-12Lines changed: 7 additions & 12 deletions
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
Collapse file

‎lib/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/async_hooks.js
+2-5Lines changed: 2 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.