Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2d409ed

Browse filesBrowse files
VoltrexKeyvadanielleadams
authored andcommitted
dns: refactor and use validators
The logical NOT operator and validators should be used where appropriate. PR-URL: #40022 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Qingyu Deng <i@ayase-lab.com>
1 parent 71a94aa commit 2d409ed
Copy full SHA for 2d409ed

File tree

Expand file treeCollapse file tree

1 file changed

+11
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-10
lines changed
Open diff view settings
Collapse file

‎lib/internal/dns/promises.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/promises.js
+11-10Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const {
2828
QueryReqWrap
2929
} = internalBinding('cares_wrap');
3030
const {
31-
ERR_INVALID_ARG_TYPE,
3231
ERR_INVALID_ARG_VALUE,
3332
ERR_MISSING_ARGS,
3433
} = codes;
@@ -44,7 +43,7 @@ function onlookup(err, addresses) {
4443
return;
4544
}
4645

47-
const family = this.family ? this.family : isIP(addresses[0]);
46+
const family = this.family || isIP(addresses[0]);
4847
this.resolve({ address: addresses[0], family });
4948
}
5049

@@ -61,7 +60,7 @@ function onlookupall(err, addresses) {
6160

6261
addresses[i] = {
6362
address,
64-
family: family ? family : isIP(addresses[i])
63+
family: family || isIP(addresses[i])
6564
};
6665
}
6766

@@ -107,9 +106,11 @@ function lookup(hostname, options) {
107106
var verbatim = getDefaultVerbatim();
108107

109108
// Parse arguments
110-
if (hostname && typeof hostname !== 'string') {
111-
throw new ERR_INVALID_ARG_TYPE('hostname', 'string', hostname);
112-
} else if (options !== null && typeof options === 'object') {
109+
if (hostname) {
110+
validateString(hostname, 'hostname');
111+
}
112+
113+
if (options !== null && typeof options === 'object') {
113114
hints = options.hints >>> 0;
114115
family = options.family >>> 0;
115116
all = options.all === true;
@@ -242,15 +243,15 @@ Resolver.prototype.reverse = resolver('getHostByAddr');
242243
Resolver.prototype.resolve = function resolve(hostname, rrtype) {
243244
var resolver;
244245

245-
if (typeof rrtype === 'string') {
246+
if (rrtype !== undefined) {
247+
validateString(rrtype, 'rrtype');
248+
246249
resolver = resolveMap[rrtype];
247250

248251
if (typeof resolver !== 'function')
249252
throw new ERR_INVALID_ARG_VALUE('rrtype', rrtype);
250-
} else if (rrtype === undefined) {
251-
resolver = resolveMap.A;
252253
} else {
253-
throw new ERR_INVALID_ARG_TYPE('rrtype', 'string', rrtype);
254+
resolver = resolveMap.A;
254255
}
255256

256257
return ReflectApply(resolver, this, [hostname]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.