| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2943,6 +2943,9 @@ deprecated and should no longer be used. | |||
| 2943 | 2943 | ||
| 2944 | 2944 | <!-- YAML | |
| 2945 | 2945 | changes: | |
| 2946 | + - version: REPLACEME | ||
| 2947 | + pr-url: https://github.com/nodejs/node/pull/41431 | ||
| 2948 | + description: End-of-Life. | ||
| 2946 | 2949 | - version: v17.0.0 | |
| 2947 | 2950 | pr-url: https://github.com/nodejs/node/pull/39793 | |
| 2948 | 2951 | description: Runtime deprecation. | |
@@ -2951,12 +2954,13 @@ changes: | |||
| 2951 | 2954 | description: Documentation-only deprecation. | |
| 2952 | 2955 | --> | |
| 2953 | 2956 | ||
| 2954 | - Type: Runtime | ||
| 2957 | + Type: End-of-Life | ||
| 2955 | 2958 | ||
| 2956 | 2959 | Using a non-nullish non-integer value for `family` option, a non-nullish | |
| 2957 | 2960 | non-number value for `hints` option, a non-nullish non-boolean value for `all` | |
| 2958 | 2961 | option, or a non-nullish non-boolean value for `verbatim` option in | |
| 2959 | - [`dns.lookup()`][] and [`dnsPromises.lookup()`][] is deprecated. | ||
| 2962 | + [`dns.lookup()`][] and [`dnsPromises.lookup()`][] throws an | ||
| 2963 | + `ERR_INVALID_ARG_TYPE` error. | ||
| 2960 | 2964 | ||
| 2961 | 2965 | ### DEP0154: RSA-PSS generate key pair options | |
| 2962 | 2966 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,6 @@ const { | |||
| 42 | 42 | Resolver, | |
| 43 | 43 | validateHints, | |
| 44 | 44 | emitInvalidHostnameWarning, | |
| 45 | - emitTypeCoercionDeprecationWarning, | ||
| 46 | 45 | getDefaultVerbatim, | |
| 47 | 46 | setDefaultResultOrder, | |
| 48 | 47 | } = require('internal/dns/utils'); | |
@@ -52,10 +51,12 @@ const { | |||
| 52 | 51 | ERR_MISSING_ARGS, | |
| 53 | 52 | } = errors.codes; | |
| 54 | 53 | const { | |
| 54 | + validateBoolean, | ||
| 55 | 55 | validateFunction, | |
| 56 | + validateNumber, | ||
| 57 | + validateOneOf, | ||
| 56 | 58 | validatePort, | |
| 57 | 59 | validateString, | |
| 58 | - validateOneOf, | ||
| 59 | 60 | } = require('internal/validators'); | |
| 60 | 61 | ||
| 61 | 62 | const { | |
@@ -107,9 +108,10 @@ function onlookupall(err, addresses) { | |||
| 107 | 108 | ||
| 108 | 109 | // Easy DNS A/AAAA look up | |
| 109 | 110 | // lookup(hostname, [options,] callback) | |
| 111 | + const validFamilies = [0, 4, 6]; | ||
| 110 | 112 | function lookup(hostname, options, callback) { | |
| 111 | 113 | let hints = 0; | |
| 112 | - let family = -1; | ||
| 114 | + let family = 0; | ||
| 113 | 115 | let all = false; | |
| 114 | 116 | let verbatim = getDefaultVerbatim(); | |
| 115 | 117 | ||
@@ -121,39 +123,36 @@ function lookup(hostname, options, callback) { | |||
| 121 | 123 | if (typeof options === 'function') { | |
| 122 | 124 | callback = options; | |
| 123 | 125 | 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); | ||
| 124 | 134 | } else { | |
| 125 | 135 | validateFunction(callback, 'callback'); | |
| 126 | 136 | ||
| 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'); | ||
| 131 | 139 | 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 | - | ||
| 146 | 140 | 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; | ||
| 152 | 153 | } | |
| 153 | 154 | } | |
| 154 | 155 | ||
| 155 | - validateOneOf(family, 'family', [0, 4, 6]); | ||
| 156 | - | ||
| 157 | 156 | if (!hostname) { | |
| 158 | 157 | emitInvalidHostnameWarning(hostname); | |
| 159 | 158 | if (all) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ const { | |||
| 15 | 15 | validateTimeout, | |
| 16 | 16 | validateTries, | |
| 17 | 17 | emitInvalidHostnameWarning, | |
| 18 | - emitTypeCoercionDeprecationWarning, | ||
| 19 | 18 | getDefaultVerbatim, | |
| 20 | 19 | } = require('internal/dns/utils'); | |
| 21 | 20 | const { codes, dnsException } = require('internal/errors'); | |
@@ -30,13 +29,16 @@ const { | |||
| 30 | 29 | QueryReqWrap | |
| 31 | 30 | } = internalBinding('cares_wrap'); | |
| 32 | 31 | const { | |
| 32 | + ERR_INVALID_ARG_TYPE, | ||
| 33 | 33 | ERR_INVALID_ARG_VALUE, | |
| 34 | 34 | ERR_MISSING_ARGS, | |
| 35 | 35 | } = codes; | |
| 36 | 36 | const { | |
| 37 | + validateBoolean, | ||
| 38 | + validateNumber, | ||
| 39 | + validateOneOf, | ||
| 37 | 40 | validatePort, | |
| 38 | 41 | validateString, | |
| 39 | - validateOneOf, | ||
| 40 | 42 | } = require('internal/validators'); | |
| 41 | 43 | ||
| 42 | 44 | const kPerfHooksDnsLookupContext = Symbol('kPerfHooksDnsLookupContext'); | |
@@ -120,9 +122,10 @@ function createLookupPromise(family, hostname, all, hints, verbatim) { | |||
| 120 | 122 | }); | |
| 121 | 123 | } | |
| 122 | 124 | ||
| 125 | + const validFamilies = [0, 4, 6]; | ||
| 123 | 126 | function lookup(hostname, options) { | |
| 124 | 127 | let hints = 0; | |
| 125 | - let family = -1; | ||
| 128 | + let family = 0; | ||
| 126 | 129 | let all = false; | |
| 127 | 130 | let verbatim = getDefaultVerbatim(); | |
| 128 | 131 | ||
@@ -131,35 +134,31 @@ function lookup(hostname, options) { | |||
| 131 | 134 | validateString(hostname, 'hostname'); | |
| 132 | 135 | } | |
| 133 | 136 | ||
| 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); | ||
| 137 | 147 | } | |
| 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; | ||
| 141 | 151 | } | |
| 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; | ||
| 145 | 155 | } | |
| 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; | ||
| 151 | 159 | } | |
| 152 | - | ||
| 153 | - validateHints(hints); | ||
| 154 | - } else { | ||
| 155 | - if (options != null && typeof options !== 'number') { | ||
| 156 | - emitTypeCoercionDeprecationWarning(); | ||
| 157 | - } | ||
| 158 | - family = options >>> 0; | ||
| 159 | 160 | } | |
| 160 | 161 | ||
| 161 | - validateOneOf(family, 'family', [0, 4, 6], true); | ||
| 162 | - | ||
| 163 | 162 | return createLookupPromise(family, hostname, all, hints, verbatim); | |
| 164 | 163 | } | |
| 165 | 164 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,18 +190,6 @@ function emitInvalidHostnameWarning(hostname) { | |||
| 190 | 190 | } | |
| 191 | 191 | } | |
| 192 | 192 | ||
| 193 | - let typeCoercionWarningEmitted = false; | ||
| 194 | - function emitTypeCoercionDeprecationWarning() { | ||
| 195 | - if (!typeCoercionWarningEmitted) { | ||
| 196 | - process.emitWarning( | ||
| 197 | - 'Type coercion of dns.lookup options is deprecated', | ||
| 198 | - 'DeprecationWarning', | ||
| 199 | - 'DEP0153' | ||
| 200 | - ); | ||
| 201 | - typeCoercionWarningEmitted = true; | ||
| 202 | - } | ||
| 203 | - } | ||
| 204 | - | ||
| 205 | 193 | let dnsOrder = getOptionValue('--dns-result-order') || 'verbatim'; | |
| 206 | 194 | ||
| 207 | 195 | function getDefaultVerbatim() { | |
@@ -222,7 +210,6 @@ module.exports = { | |||
| 222 | 210 | validateTries, | |
| 223 | 211 | Resolver, | |
| 224 | 212 | emitInvalidHostnameWarning, | |
| 225 | - emitTypeCoercionDeprecationWarning, | ||
| 226 | 213 | getDefaultVerbatim, | |
| 227 | 214 | setDefaultResultOrder, | |
| 228 | 215 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,17 +45,10 @@ dns.lookup(addresses.NOT_FOUND, { | |||
| 45 | 45 | assert.strictEqual(error.hostname, addresses.NOT_FOUND); | |
| 46 | 46 | })); | |
| 47 | 47 | ||
| 48 | - common.expectWarning('DeprecationWarning', | ||
| 49 | - 'Type coercion of dns.lookup options is deprecated', | ||
| 50 | - 'DEP0153'); | ||
| 51 | - | ||
| 52 | - assert.rejects( | ||
| 53 | - dnsPromises.lookup(addresses.NOT_FOUND, { | ||
| 48 | + assert.throws( | ||
| 49 | + () => dnsPromises.lookup(addresses.NOT_FOUND, { | ||
| 54 | 50 | family: 'IPv4', | |
| 55 | 51 | all: 'all' | |
| 56 | 52 | }), | |
| 57 | - { | ||
| 58 | - code: 'ENOTFOUND', | ||
| 59 | - message: `getaddrinfo ENOTFOUND ${addresses.NOT_FOUND}` | ||
| 60 | - } | ||
| 53 | + { code: 'ERR_INVALID_ARG_VALUE' } | ||
| 61 | 54 | ); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,18 +15,21 @@ common.expectWarning({ | |||
| 15 | 15 | 'internal/test/binding': [ | |
| 16 | 16 | 'These APIs are for internal testing only. Do not use them.', | |
| 17 | 17 | ], | |
| 18 | - 'DeprecationWarning': { | ||
| 19 | - DEP0153: 'Type coercion of dns.lookup options is deprecated' | ||
| 20 | - } | ||
| 21 | 18 | }); | |
| 22 | 19 | ||
| 23 | 20 | assert.throws(() => { | |
| 24 | 21 | dnsPromises.lookup('127.0.0.1', { hints: '-1' }); | |
| 25 | 22 | }, { | |
| 26 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 23 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 27 | 24 | name: 'TypeError' | |
| 28 | 25 | }); | |
| 29 | - dnsPromises.lookup('127.0.0.1', { family: '6' }); | ||
| 30 | - dnsPromises.lookup('127.0.0.1', { all: 'true' }); | ||
| 31 | - dnsPromises.lookup('127.0.0.1', { verbatim: 'true' }); | ||
| 32 | - dnsPromises.lookup('127.0.0.1', '6'); | ||
| 26 | + assert.throws(() => dnsPromises.lookup('127.0.0.1', { hints: -1 }), | ||
| 27 | + { code: 'ERR_INVALID_ARG_VALUE' }); | ||
| 28 | + assert.throws(() => dnsPromises.lookup('127.0.0.1', { family: '6' }), | ||
| 29 | + { code: 'ERR_INVALID_ARG_VALUE' }); | ||
| 30 | + assert.throws(() => dnsPromises.lookup('127.0.0.1', { all: 'true' }), | ||
| 31 | + { code: 'ERR_INVALID_ARG_TYPE' }); | ||
| 32 | + assert.throws(() => dnsPromises.lookup('127.0.0.1', { verbatim: 'true' }), | ||
| 33 | + { code: 'ERR_INVALID_ARG_TYPE' }); | ||
| 34 | + assert.throws(() => dnsPromises.lookup('127.0.0.1', '6'), | ||
| 35 | + { code: 'ERR_INVALID_ARG_TYPE' }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,14 +69,15 @@ assert.throws(() => { | |||
| 69 | 69 | } | |
| 70 | 70 | ||
| 71 | 71 | { | |
| 72 | + const family = 20; | ||
| 72 | 73 | const err = { | |
| 73 | 74 | code: 'ERR_INVALID_ARG_VALUE', | |
| 74 | 75 | name: 'TypeError', | |
| 75 | - message: "The argument 'family' must be one of: 0, 4, 6. Received 20" | ||
| 76 | + message: `The property 'options.family' must be one of: 0, 4, 6. Received ${family}` | ||
| 76 | 77 | }; | |
| 77 | 78 | const options = { | |
| 78 | 79 | hints: 0, | |
| 79 | - family: 20, | ||
| 80 | + family, | ||
| 80 | 81 | all: false | |
| 81 | 82 | }; | |
| 82 | 83 | ||
@@ -86,6 +87,52 @@ assert.throws(() => { | |||
| 86 | 87 | }, err); | |
| 87 | 88 | } | |
| 88 | 89 | ||
| 90 | + [1, 0n, 1n, '', '0', Symbol(), true, false, {}, [], () => {}] | ||
| 91 | + .forEach((family) => { | ||
| 92 | + const err = { code: 'ERR_INVALID_ARG_VALUE' }; | ||
| 93 | + const options = { family }; | ||
| 94 | + assert.throws(() => { dnsPromises.lookup(false, options); }, err); | ||
| 95 | + assert.throws(() => { | ||
| 96 | + dns.lookup(false, options, common.mustNotCall()); | ||
| 97 | + }, err); | ||
| 98 | + }); | ||
| 99 | + [0n, 1n, '', '0', Symbol(), true, false].forEach((family) => { | ||
| 100 | + const err = { code: 'ERR_INVALID_ARG_TYPE' }; | ||
| 101 | + assert.throws(() => { dnsPromises.lookup(false, family); }, err); | ||
| 102 | + assert.throws(() => { | ||
| 103 | + dns.lookup(false, family, common.mustNotCall()); | ||
| 104 | + }, err); | ||
| 105 | + }); | ||
| 106 | + assert.throws(() => dnsPromises.lookup(false, () => {}), | ||
| 107 | + { code: 'ERR_INVALID_ARG_TYPE' }); | ||
| 108 | + | ||
| 109 | + [0n, 1n, '', '0', Symbol(), true, false, {}, [], () => {}].forEach((hints) => { | ||
| 110 | + const err = { code: 'ERR_INVALID_ARG_TYPE' }; | ||
| 111 | + const options = { hints }; | ||
| 112 | + assert.throws(() => { dnsPromises.lookup(false, options); }, err); | ||
| 113 | + assert.throws(() => { | ||
| 114 | + dns.lookup(false, options, common.mustNotCall()); | ||
| 115 | + }, err); | ||
| 116 | + }); | ||
| 117 | + | ||
| 118 | + [0, 1, 0n, 1n, '', '0', Symbol(), {}, [], () => {}].forEach((all) => { | ||
| 119 | + const err = { code: 'ERR_INVALID_ARG_TYPE' }; | ||
| 120 | + const options = { all }; | ||
| 121 | + assert.throws(() => { dnsPromises.lookup(false, options); }, err); | ||
| 122 | + assert.throws(() => { | ||
| 123 | + dns.lookup(false, options, common.mustNotCall()); | ||
| 124 | + }, err); | ||
| 125 | + }); | ||
| 126 | + | ||
| 127 | + [0, 1, 0n, 1n, '', '0', Symbol(), {}, [], () => {}].forEach((verbatim) => { | ||
| 128 | + const err = { code: 'ERR_INVALID_ARG_TYPE' }; | ||
| 129 | + const options = { verbatim }; | ||
| 130 | + assert.throws(() => { dnsPromises.lookup(false, options); }, err); | ||
| 131 | + assert.throws(() => { | ||
| 132 | + dns.lookup(false, options, common.mustNotCall()); | ||
| 133 | + }, err); | ||
| 134 | + }); | ||
| 135 | + | ||
| 89 | 136 | (async function() { | |
| 90 | 137 | let res; | |
| 91 | 138 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments