| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,6 @@ const { | |||
| 26 | 26 | ||
| 27 | 27 | const { | |
| 28 | 28 | codes: { | |
| 29 | - ERR_INVALID_ARG_TYPE, | ||
| 30 | 29 | ERR_NO_CRYPTO, | |
| 31 | 30 | ERR_UNKNOWN_SIGNAL | |
| 32 | 31 | }, | |
@@ -83,6 +82,8 @@ function isError(e) { | |||
| 83 | 82 | // each one once. | |
| 84 | 83 | const codesWarned = new Set(); | |
| 85 | 84 | ||
| 85 | + let validateString; | ||
| 86 | + | ||
| 86 | 87 | // Mark that a method should not be used. | |
| 87 | 88 | // Returns a modified function which warns once by default. | |
| 88 | 89 | // If --no-deprecation is set, then it is a no-op. | |
@@ -91,8 +92,12 @@ function deprecate(fn, msg, code) { | |||
| 91 | 92 | return fn; | |
| 92 | 93 | } | |
| 93 | 94 | ||
| 94 | - if (code !== undefined && typeof code !== 'string') | ||
| 95 | - throw new ERR_INVALID_ARG_TYPE('code', 'string', code); | ||
| 95 | + // Lazy-load to avoid a circular dependency. | ||
| 96 | + if (validateString === undefined) | ||
| 97 | + ({ validateString } = require('internal/validators')); | ||
| 98 | + | ||
| 99 | + if (code !== undefined) | ||
| 100 | + validateString(code, 'code'); | ||
| 96 | 101 | ||
| 97 | 102 | let warned = false; | |
| 98 | 103 | function deprecated(...args) { | |
@@ -307,15 +312,20 @@ function getSystemErrorMap() { | |||
| 307 | 312 | const kCustomPromisifiedSymbol = SymbolFor('nodejs.util.promisify.custom'); | |
| 308 | 313 | const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs'); | |
| 309 | 314 | ||
| 315 | + let validateFunction; | ||
| 316 | + | ||
| 310 | 317 | function promisify(original) { | |
| 311 | - if (typeof original !== 'function') | ||
| 312 | - throw new ERR_INVALID_ARG_TYPE('original', 'Function', original); | ||
| 318 | + // Lazy-load to avoid a circular dependency. | ||
| 319 | + if (validateFunction === undefined) | ||
| 320 | + ({ validateFunction } = require('internal/validators')); | ||
| 321 | + | ||
| 322 | + validateFunction(original, 'original'); | ||
| 313 | 323 | ||
| 314 | 324 | if (original[kCustomPromisifiedSymbol]) { | |
| 315 | 325 | const fn = original[kCustomPromisifiedSymbol]; | |
| 316 | - if (typeof fn !== 'function') { | ||
| 317 | - throw new ERR_INVALID_ARG_TYPE('util.promisify.custom', 'Function', fn); | ||
| 318 | - } | ||
| 326 | + | ||
| 327 | + validateFunction(fn, 'util.promisify.custom'); | ||
| 328 | + | ||
| 319 | 329 | return ObjectDefineProperty(fn, kCustomPromisifiedSymbol, { | |
| 320 | 330 | value: fn, enumerable: false, writable: false, configurable: true | |
| 321 | 331 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,6 +233,11 @@ const validateAbortSignal = hideStackFrames((signal, name) => { | |||
| 233 | 233 | } | |
| 234 | 234 | }); | |
| 235 | 235 | ||
| 236 | + const validateFunction = hideStackFrames((value, name) => { | ||
| 237 | + if (typeof value !== 'function') | ||
| 238 | + throw new ERR_INVALID_ARG_TYPE(name, 'Function', value); | ||
| 239 | + }); | ||
| 240 | + | ||
| 236 | 241 | module.exports = { | |
| 237 | 242 | isInt32, | |
| 238 | 243 | isUint32, | |
@@ -241,6 +246,7 @@ module.exports = { | |||
| 241 | 246 | validateBoolean, | |
| 242 | 247 | validateBuffer, | |
| 243 | 248 | validateEncoding, | |
| 249 | + validateFunction, | ||
| 244 | 250 | validateInt32, | |
| 245 | 251 | validateInteger, | |
| 246 | 252 | validateNumber, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments