@@ -30,7 +30,6 @@ const {
30
30
const {
31
31
hideStackFrames,
32
32
codes : {
33
- ERR_INVALID_ARG_TYPE ,
34
33
ERR_NO_CRYPTO ,
35
34
ERR_UNKNOWN_SIGNAL
36
35
} ,
@@ -75,6 +74,8 @@ function isError(e) {
75
74
// each one once.
76
75
const codesWarned = new SafeSet ( ) ;
77
76
77
+ let validateString ;
78
+
78
79
// Mark that a method should not be used.
79
80
// Returns a modified function which warns once by default.
80
81
// If --no-deprecation is set, then it is a no-op.
@@ -83,8 +84,12 @@ function deprecate(fn, msg, code) {
83
84
return fn ;
84
85
}
85
86
86
- if ( code !== undefined && typeof code !== 'string' )
87
- throw new ERR_INVALID_ARG_TYPE ( 'code' , 'string' , code ) ;
87
+ // Lazy-load to avoid a circular dependency.
88
+ if ( validateString === undefined )
89
+ ( { validateString } = require ( 'internal/validators' ) ) ;
90
+
91
+ if ( code !== undefined )
92
+ validateString ( code , 'code' ) ;
88
93
89
94
let warned = false ;
90
95
function deprecated ( ...args ) {
@@ -300,15 +305,20 @@ function getSystemErrorMap() {
300
305
const kCustomPromisifiedSymbol = SymbolFor ( 'nodejs.util.promisify.custom' ) ;
301
306
const kCustomPromisifyArgsSymbol = Symbol ( 'customPromisifyArgs' ) ;
302
307
308
+ let validateFunction ;
309
+
303
310
function promisify ( original ) {
304
- if ( typeof original !== 'function' )
305
- throw new ERR_INVALID_ARG_TYPE ( 'original' , 'Function' , original ) ;
311
+ // Lazy-load to avoid a circular dependency.
312
+ if ( validateFunction === undefined )
313
+ ( { validateFunction } = require ( 'internal/validators' ) ) ;
314
+
315
+ validateFunction ( original , 'original' ) ;
306
316
307
317
if ( original [ kCustomPromisifiedSymbol ] ) {
308
318
const fn = original [ kCustomPromisifiedSymbol ] ;
309
- if ( typeof fn !== 'function' ) {
310
- throw new ERR_INVALID_ARG_TYPE ( 'util.promisify.custom' , 'Function' , fn ) ;
311
- }
319
+
320
+ validateFunction ( fn , 'util.promisify.custom' ) ;
321
+
312
322
return ObjectDefineProperty ( fn , kCustomPromisifiedSymbol , {
313
323
value : fn , enumerable : false , writable : false , configurable : true
314
324
} ) ;
0 commit comments