@@ -42,7 +42,6 @@ const {
4242 Resolver,
4343 validateHints,
4444 emitInvalidHostnameWarning,
45- emitTypeCoercionDeprecationWarning,
4645 getDefaultVerbatim,
4746 setDefaultResultOrder,
4847} = require ( 'internal/dns/utils' ) ;
@@ -52,10 +51,12 @@ const {
5251 ERR_MISSING_ARGS ,
5352} = errors . codes ;
5453const {
54+ validateBoolean,
5555 validateFunction,
56+ validateNumber,
57+ validateOneOf,
5658 validatePort,
5759 validateString,
58- validateOneOf,
5960} = require ( 'internal/validators' ) ;
6061
6162const {
@@ -107,9 +108,10 @@ function onlookupall(err, addresses) {
107108
108109// Easy DNS A/AAAA look up
109110// lookup(hostname, [options,] callback)
111+ const validFamilies = [ 0 , 4 , 6 ] ;
110112function lookup ( hostname , options , callback ) {
111113 let hints = 0 ;
112- let family = - 1 ;
114+ let family = 0 ;
113115 let all = false ;
114116 let verbatim = getDefaultVerbatim ( ) ;
115117
@@ -121,39 +123,36 @@ function lookup(hostname, options, callback) {
121123 if ( typeof options === 'function' ) {
122124 callback = options ;
123125 family = 0 ;
126+ } else if ( typeof options === 'number' ) {
127+ validateFunction ( callback , 'callback' ) ;
128+
129+ validateOneOf ( options , 'family' , validFamilies , true ) ;
130+ family = options ;
131+ } else if ( options !== undefined && typeof options !== 'object' ) {
132+ validateFunction ( arguments . length === 2 ? options : callback , 'callback' ) ;
133+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'integer' , 'object' ] , options ) ;
124134 } else {
125135 validateFunction ( callback , 'callback' ) ;
126136
127- if ( options !== null && typeof options === 'object' ) {
128- if ( options . hints != null && typeof options . hints !== 'number' ) {
129- emitTypeCoercionDeprecationWarning ( ) ;
130- }
137+ if ( options ?. hints != null ) {
138+ validateNumber ( options . hints , 'options.hints' ) ;
131139 hints = options . hints >>> 0 ;
132- if ( options . family != null && typeof options . family !== 'number' ) {
133- emitTypeCoercionDeprecationWarning ( ) ;
134- }
135- family = options . family >>> 0 ;
136- if ( options . all != null && typeof options . all !== 'boolean' ) {
137- emitTypeCoercionDeprecationWarning ( ) ;
138- }
139- all = options . all === true ;
140- if ( typeof options . verbatim === 'boolean' ) {
141- verbatim = options . verbatim === true ;
142- } else if ( options . verbatim != null ) {
143- emitTypeCoercionDeprecationWarning ( ) ;
144- }
145-
146140 validateHints ( hints ) ;
147- } else {
148- if ( options != null && typeof options !== 'number' ) {
149- emitTypeCoercionDeprecationWarning ( ) ;
150- }
151- family = options >>> 0 ;
141+ }
142+ if ( options ?. family != null ) {
143+ validateOneOf ( options . family , 'options.family' , validFamilies , true ) ;
144+ family = options . family ;
145+ }
146+ if ( options ?. all != null ) {
147+ validateBoolean ( options . all , 'options.all' ) ;
148+ all = options . all ;
149+ }
150+ if ( options ?. verbatim != null ) {
151+ validateBoolean ( options . verbatim , 'options.verbatim' ) ;
152+ verbatim = options . verbatim ;
152153 }
153154 }
154155
155- validateOneOf ( family , 'family' , [ 0 , 4 , 6 ] ) ;
156-
157156 if ( ! hostname ) {
158157 emitInvalidHostnameWarning ( hostname ) ;
159158 if ( all ) {
0 commit comments