| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 929e8df commit 2268d1c
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,12 +51,15 @@ const { AsyncResource } = require('async_hooks'); | |||
| 51 | 51 | const { async_id_symbol } = require('internal/async_hooks').symbols; | |
| 52 | 52 | const { | |
| 53 | 53 | codes: { | |
| 54 | - ERR_INVALID_ARG_TYPE, | ||
| 55 | 54 | ERR_OUT_OF_RANGE, | |
| 56 | 55 | }, | |
| 57 | 56 | } = require('internal/errors'); | |
| 58 | 57 | const { once } = require('internal/util'); | |
| 59 | - const { validateNumber, validateOneOf } = require('internal/validators'); | ||
| 58 | + const { | ||
| 59 | + validateNumber, | ||
| 60 | + validateOneOf, | ||
| 61 | + validateString, | ||
| 62 | + } = require('internal/validators'); | ||
| 60 | 63 | ||
| 61 | 64 | const kOnKeylog = Symbol('onkeylog'); | |
| 62 | 65 | const kRequestOptions = Symbol('requestOptions'); | |
@@ -344,10 +347,7 @@ function calculateServerName(options, req) { | |||
| 344 | 347 | let servername = options.host; | |
| 345 | 348 | const hostHeader = req.getHeader('host'); | |
| 346 | 349 | if (hostHeader) { | |
| 347 | - if (typeof hostHeader !== 'string') { | ||
| 348 | - throw new ERR_INVALID_ARG_TYPE('options.headers.host', | ||
| 349 | - 'String', hostHeader); | ||
| 350 | - } | ||
| 350 | + validateString(hostHeader, 'options.headers.host'); | ||
| 351 | 351 | ||
| 352 | 352 | // abc => abc | |
| 353 | 353 | // abc:123 => abc | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,9 +84,12 @@ const { | |||
| 84 | 84 | getAllowUnauthorized, | |
| 85 | 85 | } = require('internal/options'); | |
| 86 | 86 | const { | |
| 87 | + validateBoolean, | ||
| 87 | 88 | validateBuffer, | |
| 88 | 89 | validateCallback, | |
| 90 | + validateFunction, | ||
| 89 | 91 | validateInt32, | |
| 92 | + validateNumber, | ||
| 90 | 93 | validateObject, | |
| 91 | 94 | validateString, | |
| 92 | 95 | validateUint32, | |
@@ -468,9 +471,8 @@ function TLSSocket(socket, opts) { | |||
| 468 | 471 | process.emitWarning('Enabling --trace-tls can expose sensitive data in ' + | |
| 469 | 472 | 'the resulting log.'); | |
| 470 | 473 | } | |
| 471 | - } else if (typeof enableTrace !== 'boolean') { | ||
| 472 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 473 | - 'options.enableTrace', 'boolean', enableTrace); | ||
| 474 | + } else { | ||
| 475 | + validateBoolean(enableTrace, 'options.enableTrace'); | ||
| 474 | 476 | } | |
| 475 | 477 | ||
| 476 | 478 | if (tlsOptions.ALPNProtocols) | |
@@ -783,11 +785,7 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 783 | 785 | } | |
| 784 | 786 | ||
| 785 | 787 | if (options.pskCallback && ssl.enablePskCallback) { | |
| 786 | - if (typeof options.pskCallback !== 'function') { | ||
| 787 | - throw new ERR_INVALID_ARG_TYPE('pskCallback', | ||
| 788 | - 'function', | ||
| 789 | - options.pskCallback); | ||
| 790 | - } | ||
| 788 | + validateFunction(options.pskCallback, 'pskCallback'); | ||
| 791 | 789 | ||
| 792 | 790 | ssl[kOnPskExchange] = options.isServer ? | |
| 793 | 791 | onPskServerCallback : onPskClientCallback; | |
@@ -796,13 +794,7 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 796 | 794 | ssl.enablePskCallback(); | |
| 797 | 795 | ||
| 798 | 796 | if (options.pskIdentityHint) { | |
| 799 | - if (typeof options.pskIdentityHint !== 'string') { | ||
| 800 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 801 | - 'options.pskIdentityHint', | ||
| 802 | - 'string', | ||
| 803 | - options.pskIdentityHint | ||
| 804 | - ); | ||
| 805 | - } | ||
| 797 | + validateString(options.pskIdentityHint, 'options.pskIdentityHint'); | ||
| 806 | 798 | ssl.setPskIdentityHint(options.pskIdentityHint); | |
| 807 | 799 | } | |
| 808 | 800 | } | |
@@ -1215,10 +1207,7 @@ function Server(options, listener) { | |||
| 1215 | 1207 | this[kPskCallback] = options.pskCallback; | |
| 1216 | 1208 | this[kPskIdentityHint] = options.pskIdentityHint; | |
| 1217 | 1209 | ||
| 1218 | - if (typeof this[kHandshakeTimeout] !== 'number') { | ||
| 1219 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 1220 | - 'options.handshakeTimeout', 'number', options.handshakeTimeout); | ||
| 1221 | - } | ||
| 1210 | + validateNumber(this[kHandshakeTimeout], 'options.handshakeTimeout'); | ||
| 1222 | 1211 | ||
| 1223 | 1212 | if (this[kSNICallback] && typeof this[kSNICallback] !== 'function') { | |
| 1224 | 1213 | throw new ERR_INVALID_ARG_TYPE( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,7 @@ const { | |||
| 62 | 62 | ||
| 63 | 63 | const { | |
| 64 | 64 | validateAbortSignal, | |
| 65 | + validateBoolean, | ||
| 65 | 66 | validateFunction, | |
| 66 | 67 | } = require('internal/validators'); | |
| 67 | 68 | ||
@@ -89,10 +90,7 @@ ObjectDefineProperty(EventEmitter, 'captureRejections', { | |||
| 89 | 90 | return EventEmitter.prototype[kCapture]; | |
| 90 | 91 | }, | |
| 91 | 92 | set(value) { | |
| 92 | - if (typeof value !== 'boolean') { | ||
| 93 | - throw new ERR_INVALID_ARG_TYPE('EventEmitter.captureRejections', | ||
| 94 | - 'boolean', value); | ||
| 95 | - } | ||
| 93 | + validateBoolean(value, 'EventEmitter.captureRejections'); | ||
| 96 | 94 | ||
| 97 | 95 | EventEmitter.prototype[kCapture] = value; | |
| 98 | 96 | }, | |
@@ -190,10 +188,7 @@ EventEmitter.init = function(opts) { | |||
| 190 | 188 | ||
| 191 | 189 | ||
| 192 | 190 | if (opts?.captureRejections) { | |
| 193 | - if (typeof opts.captureRejections !== 'boolean') { | ||
| 194 | - throw new ERR_INVALID_ARG_TYPE('options.captureRejections', | ||
| 195 | - 'boolean', opts.captureRejections); | ||
| 196 | - } | ||
| 191 | + validateBoolean(opts.captureRejections, 'options.captureRejections'); | ||
| 197 | 192 | this[kCapture] = Boolean(opts.captureRejections); | |
| 198 | 193 | } else { | |
| 199 | 194 | // Assigning the kCapture property directly saves an expensive | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,8 @@ const { | |||
| 15 | 15 | } = require('internal/perf/perf'); | |
| 16 | 16 | ||
| 17 | 17 | const { | |
| 18 | - validateObject | ||
| 18 | + validateFunction, | ||
| 19 | + validateObject, | ||
| 19 | 20 | } = require('internal/validators'); | |
| 20 | 21 | ||
| 21 | 22 | const { | |
@@ -57,8 +58,7 @@ function processComplete(name, start, args, histogram) { | |||
| 57 | 58 | } | |
| 58 | 59 | ||
| 59 | 60 | function timerify(fn, options = {}) { | |
| 60 | - if (typeof fn !== 'function') | ||
| 61 | - throw new ERR_INVALID_ARG_TYPE('fn', 'function', fn); | ||
| 61 | + validateFunction(fn, 'fn'); | ||
| 62 | 62 | ||
| 63 | 63 | validateObject(options, 'options'); | |
| 64 | 64 | const { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,7 @@ const { | |||
| 43 | 43 | const format = require('internal/util/inspect').format; | |
| 44 | 44 | const { | |
| 45 | 45 | validateArray, | |
| 46 | + validateNumber, | ||
| 46 | 47 | validateObject, | |
| 47 | 48 | } = require('internal/validators'); | |
| 48 | 49 | const constants = internalBinding('constants').os.signals; | |
@@ -122,19 +123,13 @@ function wrapProcessMethods(binding) { | |||
| 122 | 123 | if (!previousValueIsValid(prevValue.user)) { | |
| 123 | 124 | validateObject(prevValue, 'prevValue'); | |
| 124 | 125 | ||
| 125 | - if (typeof prevValue.user !== 'number') { | ||
| 126 | - throw new ERR_INVALID_ARG_TYPE('prevValue.user', | ||
| 127 | - 'number', prevValue.user); | ||
| 128 | - } | ||
| 126 | + validateNumber(prevValue.user, 'prevValue.user'); | ||
| 129 | 127 | throw new ERR_INVALID_ARG_VALUE.RangeError('prevValue.user', | |
| 130 | 128 | prevValue.user); | |
| 131 | 129 | } | |
| 132 | 130 | ||
| 133 | 131 | if (!previousValueIsValid(prevValue.system)) { | |
| 134 | - if (typeof prevValue.system !== 'number') { | ||
| 135 | - throw new ERR_INVALID_ARG_TYPE('prevValue.system', | ||
| 136 | - 'number', prevValue.system); | ||
| 137 | - } | ||
| 132 | + validateNumber(prevValue.system, 'prevValue.system'); | ||
| 138 | 133 | throw new ERR_INVALID_ARG_VALUE.RangeError('prevValue.system', | |
| 139 | 134 | prevValue.system); | |
| 140 | 135 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,10 @@ const { | |||
| 60 | 60 | inspect | |
| 61 | 61 | } = require('internal/util/inspect'); | |
| 62 | 62 | const { debuglog } = require('internal/util/debuglog'); | |
| 63 | - const { validateNumber } = require('internal/validators'); | ||
| 63 | + const { | ||
| 64 | + validateFunction, | ||
| 65 | + validateNumber, | ||
| 66 | + } = require('internal/validators'); | ||
| 64 | 67 | const { TextDecoder, TextEncoder } = require('internal/encoding'); | |
| 65 | 68 | const { isBuffer } = require('buffer').Buffer; | |
| 66 | 69 | const types = require('internal/util/types'); | |
@@ -285,18 +288,14 @@ const callbackifyOnRejected = hideStackFrames((reason, cb) => { | |||
| 285 | 288 | * } | |
| 286 | 289 | */ | |
| 287 | 290 | function callbackify(original) { | |
| 288 | - if (typeof original !== 'function') { | ||
| 289 | - throw new ERR_INVALID_ARG_TYPE('original', 'Function', original); | ||
| 290 | - } | ||
| 291 | + validateFunction(original, 'original'); | ||
| 291 | 292 | ||
| 292 | 293 | // We DO NOT return the promise as it gives the user a false sense that | |
| 293 | 294 | // the promise is actually somehow related to the callback's execution | |
| 294 | 295 | // and that the callback throwing will reject the promise. | |
| 295 | 296 | function callbackified(...args) { | |
| 296 | 297 | const maybeCb = ArrayPrototypePop(args); | |
| 297 | - if (typeof maybeCb !== 'function') { | ||
| 298 | - throw new ERR_INVALID_ARG_TYPE('last argument', 'Function', maybeCb); | ||
| 299 | - } | ||
| 298 | + validateFunction(maybeCb, 'last argument'); | ||
| 300 | 299 | const cb = FunctionPrototypeBind(maybeCb, this); | |
| 301 | 300 | // In true node style we process the callback on `nextTick` with all the | |
| 302 | 301 | // implications (stack, `uncaughtException`, `async_hooks`) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,14 +46,15 @@ const { | |||
| 46 | 46 | isArrayBufferView, | |
| 47 | 47 | } = require('internal/util/types'); | |
| 48 | 48 | const { | |
| 49 | - validateInt32, | ||
| 50 | - validateUint32, | ||
| 51 | - validateString, | ||
| 52 | 49 | validateArray, | |
| 53 | 50 | validateBoolean, | |
| 54 | 51 | validateBuffer, | |
| 52 | + validateFunction, | ||
| 53 | + validateInt32, | ||
| 55 | 54 | validateObject, | |
| 56 | 55 | validateOneOf, | |
| 56 | + validateString, | ||
| 57 | + validateUint32, | ||
| 57 | 58 | } = require('internal/validators'); | |
| 58 | 59 | const { | |
| 59 | 60 | kVmBreakFirstLineSymbol, | |
@@ -108,11 +109,8 @@ class Script extends ContextifyScript { | |||
| 108 | 109 | } | |
| 109 | 110 | ||
| 110 | 111 | if (importModuleDynamically !== undefined) { | |
| 111 | - if (typeof importModuleDynamically !== 'function') { | ||
| 112 | - throw new ERR_INVALID_ARG_TYPE('options.importModuleDynamically', | ||
| 113 | - 'function', | ||
| 114 | - importModuleDynamically); | ||
| 115 | - } | ||
| 112 | + validateFunction(importModuleDynamically, | ||
| 113 | + 'options.importModuleDynamically'); | ||
| 116 | 114 | const { importModuleDynamicallyWrap } = | |
| 117 | 115 | require('internal/vm/module'); | |
| 118 | 116 | const { callbackMap } = internalBinding('module_wrap'); | |
@@ -373,11 +371,8 @@ function compileFunction(code, params, options = {}) { | |||
| 373 | 371 | } | |
| 374 | 372 | ||
| 375 | 373 | if (importModuleDynamically !== undefined) { | |
| 376 | - if (typeof importModuleDynamically !== 'function') { | ||
| 377 | - throw new ERR_INVALID_ARG_TYPE('options.importModuleDynamically', | ||
| 378 | - 'function', | ||
| 379 | - importModuleDynamically); | ||
| 380 | - } | ||
| 374 | + validateFunction(importModuleDynamically, | ||
| 375 | + 'options.importModuleDynamically'); | ||
| 381 | 376 | const { importModuleDynamicallyWrap } = | |
| 382 | 377 | require('internal/vm/module'); | |
| 383 | 378 | const { callbackMap } = internalBinding('module_wrap'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ const { isArrayBuffer } = require('internal/util/types'); | |||
| 18 | 18 | const { | |
| 19 | 19 | validateArray, | |
| 20 | 20 | validateBoolean, | |
| 21 | + validateFunction, | ||
| 21 | 22 | validateInt32, | |
| 22 | 23 | validateObject, | |
| 23 | 24 | } = require('internal/validators'); | |
@@ -118,10 +119,7 @@ class WASI { | |||
| 118 | 119 | ||
| 119 | 120 | const { _start, _initialize } = this[kInstance].exports; | |
| 120 | 121 | ||
| 121 | - if (typeof _start !== 'function') { | ||
| 122 | - throw new ERR_INVALID_ARG_TYPE( | ||
| 123 | - 'instance.exports._start', 'function', _start); | ||
| 124 | - } | ||
| 122 | + validateFunction(_start, 'instance.exports._start'); | ||
| 125 | 123 | if (_initialize !== undefined) { | |
| 126 | 124 | throw new ERR_INVALID_ARG_TYPE( | |
| 127 | 125 | 'instance.exports._initialize', 'undefined', _initialize); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,6 +71,7 @@ const { | |||
| 71 | 71 | const { owner_symbol } = require('internal/async_hooks').symbols; | |
| 72 | 72 | const { | |
| 73 | 73 | validateFunction, | |
| 74 | + validateNumber, | ||
| 74 | 75 | } = require('internal/validators'); | |
| 75 | 76 | ||
| 76 | 77 | const kFlushFlag = Symbol('kFlushFlag'); | |
@@ -212,10 +213,7 @@ const checkFiniteNumber = hideStackFrames((number, name) => { | |||
| 212 | 213 | return false; | |
| 213 | 214 | } | |
| 214 | 215 | ||
| 215 | - // Other non-numbers | ||
| 216 | - if (typeof number !== 'number') { | ||
| 217 | - throw new ERR_INVALID_ARG_TYPE(name, 'number', number); | ||
| 218 | - } | ||
| 216 | + validateNumber(number, name); | ||
| 219 | 217 | ||
| 220 | 218 | // Infinite numbers | |
| 221 | 219 | throw new ERR_OUT_OF_RANGE(name, 'a finite number', number); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments