GeezerVison is showing github.com — lib: refactor to use validate function · nodejs/node@1cfa2e6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/_http_client.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -223,11 +223,10 @@ function ClientRequest(input, options, cb) { | 223 | 223 | this.maxHeaderSize = maxHeaderSize; | 224 | 224 |
| 225 | 225 | 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'); | 230 | 228 | } | | 229 | + | 231 | 230 | this.insecureHTTPParser = insecureHTTPParser; | 232 | 231 |
| 233 | 232 | if (options.joinDuplicateHeaders !== undefined) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/_tls_wrap.js +7-12Lines changed: 7 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1224,21 +1224,16 @@ function Server(options, listener) { | 1224 | 1224 |
| 1225 | 1225 | validateNumber(this[kHandshakeTimeout], 'options.handshakeTimeout'); | 1226 | 1226 |
| 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'); | 1230 | 1229 | } | 1231 | 1230 |
| 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'); | 1235 | 1233 | } | 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'); | 1242 | 1237 | } | 1243 | 1238 |
| 1244 | 1239 | // constructor call | |
Collapse file Copy file name to clipboardExpand all lines: lib/async_hooks.js +2-5Lines changed: 2 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,6 @@ const { | 18 | 18 | const { | 19 | 19 | ERR_ASYNC_CALLBACK, | 20 | 20 | ERR_ASYNC_TYPE, | 21 | | - ERR_INVALID_ARG_TYPE, | 22 | 21 | ERR_INVALID_ASYNC_ID | 23 | 22 | } = require('internal/errors').codes; | 24 | 23 | const { kEmptyObject } = require('internal/util'); | @@ -280,10 +279,8 @@ class AsyncLocalStorage { | 280 | 279 | validateObject(options, 'options'); | 281 | 280 |
| 282 | 281 | 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'); | 287 | 284 | } | 288 | 285 |
| 289 | 286 | this.kResourceStore = Symbol('kResourceStore'); | |
|