Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2022-01-07 14:00:10 +0300
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2022-04-12 06:50:11 +0300
commit08773e3c0498ff04395f0f8b10c5e8bda096b0bf (patch)
treebc99c600d93a6e5987a2222610861e904b49f880 /lib
parent3a26db9697a09915a0d541d97f047fc9c02bb452 (diff)
dns: remove `dns.lookup` and `dnsPromises.lookup` options type coercion
PR-URL: https://github.com/nodejs/node/pull/41431 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dns.js55
-rw-r--r--lib/internal/dns/promises.js51
-rw-r--r--lib/internal/dns/utils.js13
3 files changed, 52 insertions, 67 deletions
diff --git a/lib/dns.js b/lib/dns.js
index 14937769d1d..af5416c6247 100644
--- a/lib/dns.js
+++ b/lib/dns.js
@@ -42,7 +42,6 @@ const {
Resolver,
validateHints,
emitInvalidHostnameWarning,
- emitTypeCoercionDeprecationWarning,
getDefaultVerbatim,
setDefaultResultOrder,
} = require('internal/dns/utils');
@@ -52,10 +51,12 @@ const {
ERR_MISSING_ARGS,
} = errors.codes;
const {
+ validateBoolean,
validateFunction,
+ validateNumber,
+ validateOneOf,
validatePort,
validateString,
- validateOneOf,
} = require('internal/validators');
const {
@@ -107,9 +108,10 @@ function onlookupall(err, addresses) {
// Easy DNS A/AAAA look up
// lookup(hostname, [options,] callback)
+const validFamilies = [0, 4, 6];
function lookup(hostname, options, callback) {
let hints = 0;
- let family = -1;
+ let family = 0;
let all = false;
let verbatim = getDefaultVerbatim();
@@ -121,39 +123,36 @@ function lookup(hostname, options, callback) {
if (typeof options === 'function') {
callback = options;
family = 0;
+ } else if (typeof options === 'number') {
+ validateFunction(callback, 'callback');
+
+ validateOneOf(options, 'family', validFamilies, true);
+ family = options;
+ } else if (options !== undefined && typeof options !== 'object') {
+ validateFunction(arguments.length === 2 ? options : callback, 'callback');
+ throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
} else {
validateFunction(callback, 'callback');
- if (options !== null && typeof options === 'object') {
- if (options.hints != null && typeof options.hints !== 'number') {
- emitTypeCoercionDeprecationWarning();
- }
+ if (options?.hints != null) {
+ validateNumber(options.hints, 'options.hints');
hints = options.hints >>> 0;
- if (options.family != null && typeof options.family !== 'number') {
- emitTypeCoercionDeprecationWarning();
- }
- family = options.family >>> 0;
- if (options.all != null && typeof options.all !== 'boolean') {
- emitTypeCoercionDeprecationWarning();
- }
- all = options.all === true;
- if (typeof options.verbatim === 'boolean') {
- verbatim = options.verbatim === true;
- } else if (options.verbatim != null) {
- emitTypeCoercionDeprecationWarning();
- }
-
validateHints(hints);
- } else {
- if (options != null && typeof options !== 'number') {
- emitTypeCoercionDeprecationWarning();
- }
- family = options >>> 0;
+ }
+ if (options?.family != null) {
+ validateOneOf(options.family, 'options.family', validFamilies, true);
+ family = options.family;
+ }
+ if (options?.all != null) {
+ validateBoolean(options.all, 'options.all');
+ all = options.all;
+ }
+ if (options?.verbatim != null) {
+ validateBoolean(options.verbatim, 'options.verbatim');
+ verbatim = options.verbatim;
}
}
- validateOneOf(family, 'family', [0, 4, 6]);
-
if (!hostname) {
emitInvalidHostnameWarning(hostname);
if (all) {
diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js
index 68fcb29745e..9625e9e7b9b 100644
--- a/lib/internal/dns/promises.js
+++ b/lib/internal/dns/promises.js
@@ -15,7 +15,6 @@ const {
validateTimeout,
validateTries,
emitInvalidHostnameWarning,
- emitTypeCoercionDeprecationWarning,
getDefaultVerbatim,
} = require('internal/dns/utils');
const { codes, dnsException } = require('internal/errors');
@@ -30,13 +29,16 @@ const {
QueryReqWrap
} = internalBinding('cares_wrap');
const {
+ ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_MISSING_ARGS,
} = codes;
const {
+ validateBoolean,
+ validateNumber,
+ validateOneOf,
validatePort,
validateString,
- validateOneOf,
} = require('internal/validators');
const kPerfHooksDnsLookupContext = Symbol('kPerfHooksDnsLookupContext');
@@ -120,9 +122,10 @@ function createLookupPromise(family, hostname, all, hints, verbatim) {
});
}
+const validFamilies = [0, 4, 6];
function lookup(hostname, options) {
let hints = 0;
- let family = -1;
+ let family = 0;
let all = false;
let verbatim = getDefaultVerbatim();
@@ -131,35 +134,31 @@ function lookup(hostname, options) {
validateString(hostname, 'hostname');
}
- if (options !== null && typeof options === 'object') {
- if (options.hints != null && typeof options.hints !== 'number') {
- emitTypeCoercionDeprecationWarning();
+ if (typeof options === 'number') {
+ validateOneOf(options, 'family', validFamilies, true);
+ family = options;
+ } else if (options !== undefined && typeof options !== 'object') {
+ throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
+ } else {
+ if (options?.hints != null) {
+ validateNumber(options.hints, 'options.hints');
+ hints = options.hints >>> 0;
+ validateHints(hints);
}
- hints = options.hints >>> 0;
- if (options.family != null && typeof options.family !== 'number') {
- emitTypeCoercionDeprecationWarning();
+ if (options?.family != null) {
+ validateOneOf(options.family, 'options.family', validFamilies, true);
+ family = options.family;
}
- family = options.family >>> 0;
- if (options.all != null && typeof options.all !== 'boolean') {
- emitTypeCoercionDeprecationWarning();
+ if (options?.all != null) {
+ validateBoolean(options.all, 'options.all');
+ all = options.all;
}
- all = options.all === true;
- if (typeof options.verbatim === 'boolean') {
- verbatim = options.verbatim === true;
- } else if (options.verbatim != null) {
- emitTypeCoercionDeprecationWarning();
+ if (options?.verbatim != null) {
+ validateBoolean(options.verbatim, 'options.verbatim');
+ verbatim = options.verbatim;
}
-
- validateHints(hints);
- } else {
- if (options != null && typeof options !== 'number') {
- emitTypeCoercionDeprecationWarning();
- }
- family = options >>> 0;
}
- validateOneOf(family, 'family', [0, 4, 6], true);
-
return createLookupPromise(family, hostname, all, hints, verbatim);
}
diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js
index 58d3eaafcaa..62606e6f7f0 100644
--- a/lib/internal/dns/utils.js
+++ b/lib/internal/dns/utils.js
@@ -190,18 +190,6 @@ function emitInvalidHostnameWarning(hostname) {
}
}
-let typeCoercionWarningEmitted = false;
-function emitTypeCoercionDeprecationWarning() {
- if (!typeCoercionWarningEmitted) {
- process.emitWarning(
- 'Type coercion of dns.lookup options is deprecated',
- 'DeprecationWarning',
- 'DEP0153'
- );
- typeCoercionWarningEmitted = true;
- }
-}
-
let dnsOrder = getOptionValue('--dns-result-order') || 'verbatim';
function getDefaultVerbatim() {
@@ -222,7 +210,6 @@ module.exports = {
validateTries,
Resolver,
emitInvalidHostnameWarning,
- emitTypeCoercionDeprecationWarning,
getDefaultVerbatim,
setDefaultResultOrder,
};