@@ -30,7 +30,6 @@ const {
3030const {
3131 hideStackFrames,
3232 codes : {
33- ERR_INVALID_ARG_TYPE ,
3433 ERR_NO_CRYPTO ,
3534 ERR_UNKNOWN_SIGNAL
3635 } ,
@@ -75,6 +74,8 @@ function isError(e) {
7574// each one once.
7675const codesWarned = new SafeSet ( ) ;
7776
77+ let validateString ;
78+
7879// Mark that a method should not be used.
7980// Returns a modified function which warns once by default.
8081// If --no-deprecation is set, then it is a no-op.
@@ -83,8 +84,12 @@ function deprecate(fn, msg, code) {
8384 return fn ;
8485 }
8586
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' ) ;
8893
8994 let warned = false ;
9095 function deprecated ( ...args ) {
@@ -300,15 +305,20 @@ function getSystemErrorMap() {
300305const kCustomPromisifiedSymbol = SymbolFor ( 'nodejs.util.promisify.custom' ) ;
301306const kCustomPromisifyArgsSymbol = Symbol ( 'customPromisifyArgs' ) ;
302307
308+ let validateFunction ;
309+
303310function 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' ) ;
306316
307317 if ( original [ kCustomPromisifiedSymbol ] ) {
308318 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+
312322 return ObjectDefineProperty ( fn , kCustomPromisifiedSymbol , {
313323 value : fn , enumerable : false , writable : false , configurable : true
314324 } ) ;
0 commit comments