@@ -26,7 +26,6 @@ const {
2626
2727const {
2828 codes : {
29- ERR_INVALID_ARG_TYPE ,
3029 ERR_NO_CRYPTO ,
3130 ERR_UNKNOWN_SIGNAL
3231 } ,
@@ -83,6 +82,8 @@ function isError(e) {
8382// each one once.
8483const codesWarned = new Set ( ) ;
8584
85+ let validateString ;
86+
8687// Mark that a method should not be used.
8788// Returns a modified function which warns once by default.
8889// If --no-deprecation is set, then it is a no-op.
@@ -91,8 +92,12 @@ function deprecate(fn, msg, code) {
9192 return fn ;
9293 }
9394
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' ) ;
96101
97102 let warned = false ;
98103 function deprecated ( ...args ) {
@@ -307,15 +312,20 @@ function getSystemErrorMap() {
307312const kCustomPromisifiedSymbol = SymbolFor ( 'nodejs.util.promisify.custom' ) ;
308313const kCustomPromisifyArgsSymbol = Symbol ( 'customPromisifyArgs' ) ;
309314
315+ let validateFunction ;
316+
310317function 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' ) ;
313323
314324 if ( original [ kCustomPromisifiedSymbol ] ) {
315325 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+
319329 return ObjectDefineProperty ( fn , kCustomPromisifiedSymbol , {
320330 value : fn , enumerable : false , writable : false , configurable : true
321331 } ) ;
0 commit comments