@@ -15,7 +15,6 @@ const {
1515 validateTimeout,
1616 validateTries,
1717 emitInvalidHostnameWarning,
18- emitTypeCoercionDeprecationWarning,
1918 getDefaultVerbatim,
2019} = require ( 'internal/dns/utils' ) ;
2120const { codes, dnsException } = require ( 'internal/errors' ) ;
@@ -30,13 +29,16 @@ const {
3029 QueryReqWrap
3130} = internalBinding ( 'cares_wrap' ) ;
3231const {
32+ ERR_INVALID_ARG_TYPE ,
3333 ERR_INVALID_ARG_VALUE ,
3434 ERR_MISSING_ARGS ,
3535} = codes ;
3636const {
37+ validateBoolean,
38+ validateNumber,
39+ validateOneOf,
3740 validatePort,
3841 validateString,
39- validateOneOf,
4042} = require ( 'internal/validators' ) ;
4143
4244const kPerfHooksDnsLookupContext = Symbol ( 'kPerfHooksDnsLookupContext' ) ;
@@ -120,9 +122,10 @@ function createLookupPromise(family, hostname, all, hints, verbatim) {
120122 } ) ;
121123}
122124
125+ const validFamilies = [ 0 , 4 , 6 ] ;
123126function lookup ( hostname , options ) {
124127 let hints = 0 ;
125- let family = - 1 ;
128+ let family = 0 ;
126129 let all = false ;
127130 let verbatim = getDefaultVerbatim ( ) ;
128131
@@ -131,35 +134,31 @@ function lookup(hostname, options) {
131134 validateString ( hostname , 'hostname' ) ;
132135 }
133136
134- if ( options !== null && typeof options === 'object' ) {
135- if ( options . hints != null && typeof options . hints !== 'number' ) {
136- emitTypeCoercionDeprecationWarning ( ) ;
137+ if ( typeof options === 'number' ) {
138+ validateOneOf ( options , 'family' , validFamilies , true ) ;
139+ family = options ;
140+ } else if ( options !== undefined && typeof options !== 'object' ) {
141+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'integer' , 'object' ] , options ) ;
142+ } else {
143+ if ( options ?. hints != null ) {
144+ validateNumber ( options . hints , 'options.hints' ) ;
145+ hints = options . hints >>> 0 ;
146+ validateHints ( hints ) ;
137147 }
138- hints = options . hints >>> 0 ;
139- if ( options . family != null && typeof options . family !== 'number' ) {
140- emitTypeCoercionDeprecationWarning ( ) ;
148+ if ( options ?. family != null ) {
149+ validateOneOf ( options . family , ' options.family' , validFamilies , true ) ;
150+ family = options . family ;
141151 }
142- family = options . family >>> 0 ;
143- if ( options . all != null && typeof options . all !== 'boolean' ) {
144- emitTypeCoercionDeprecationWarning ( ) ;
152+ if ( options ?. all != null ) {
153+ validateBoolean ( options . all , ' options.all' ) ;
154+ all = options . all ;
145155 }
146- all = options . all === true ;
147- if ( typeof options . verbatim === 'boolean' ) {
148- verbatim = options . verbatim === true ;
149- } else if ( options . verbatim != null ) {
150- emitTypeCoercionDeprecationWarning ( ) ;
156+ if ( options ?. verbatim != null ) {
157+ validateBoolean ( options . verbatim , 'options.verbatim' ) ;
158+ verbatim = options . verbatim ;
151159 }
152-
153- validateHints ( hints ) ;
154- } else {
155- if ( options != null && typeof options !== 'number' ) {
156- emitTypeCoercionDeprecationWarning ( ) ;
157- }
158- family = options >>> 0 ;
159160 }
160161
161- validateOneOf ( family , 'family' , [ 0 , 4 , 6 ] , true ) ;
162-
163162 return createLookupPromise ( family , hostname , all , hints , verbatim ) ;
164163}
165164
0 commit comments