aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2020-11-20 10:26:23 +0100
committerNode.js GitHub Bot <github-bot@iojs.org>2020-12-07 19:40:52 +0000
commit96b4950dcac5221765a51bd0c1d21c252a3d0f77 (patch)
tree548958ad8fdc4a427acaa77ac208347c91a5d222 /lib
parentbf31d3c3b17ffe97828381dc7caf3f73d21805fd (diff)
downloadios-node-v8-96b4950dcac5221765a51bd0c1d21c252a3d0f77.tar.gz
ios-node-v8-96b4950dcac5221765a51bd0c1d21c252a3d0f77.tar.bz2
ios-node-v8-96b4950dcac5221765a51bd0c1d21c252a3d0f77.zip
dns: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36314 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dns.js7
-rw-r--r--lib/internal/dns/promises.js7
-rw-r--r--lib/internal/dns/utils.js21
3 files changed, 23 insertions, 12 deletions
diff --git a/lib/dns.js b/lib/dns.js
index 8d45be73ba..0c1b259d73 100644
--- a/lib/dns.js
+++ b/lib/dns.js
@@ -22,9 +22,11 @@
'use strict';
const {
+ ArrayPrototypeMap,
ObjectCreate,
ObjectDefineProperties,
ObjectDefineProperty,
+ ReflectApply,
} = primordials;
const cares = internalBinding('cares_wrap');
@@ -197,7 +199,8 @@ ObjectDefineProperty(lookupService, customPromisifyArgs,
function onresolve(err, result, ttls) {
if (ttls && this.ttl)
- result = result.map((address, index) => ({ address, ttl: ttls[index] }));
+ result = ArrayPrototypeMap(
+ result, (address, index) => ({ address, ttl: ttls[index] }));
if (err)
this.callback(dnsException(err, this.bindingName, this.hostname));
@@ -261,7 +264,7 @@ function resolve(hostname, rrtype, callback) {
}
if (typeof resolver === 'function') {
- return resolver.call(this, hostname, callback);
+ return ReflectApply(resolver, this, [hostname, callback]);
}
throw new ERR_INVALID_ARG_VALUE('rrtype', rrtype);
}
diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js
index 4240f93974..e0158eef81 100644
--- a/lib/internal/dns/promises.js
+++ b/lib/internal/dns/promises.js
@@ -1,9 +1,11 @@
'use strict';
const {
+ ArrayPrototypeMap,
ObjectCreate,
ObjectDefineProperty,
Promise,
+ ReflectApply,
} = primordials;
const {
@@ -169,7 +171,8 @@ function onresolve(err, result, ttls) {
}
if (ttls && this.ttl)
- result = result.map((address, index) => ({ address, ttl: ttls[index] }));
+ result = ArrayPrototypeMap(
+ result, (address, index) => ({ address, ttl: ttls[index] }));
this.resolve(result);
}
@@ -246,7 +249,7 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) {
throw new ERR_INVALID_ARG_TYPE('rrtype', 'string', rrtype);
}
- return resolver.call(this, hostname);
+ return ReflectApply(resolver, this, [hostname]);
};
diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js
index 1c50a089d1..27d25c92ad 100644
--- a/lib/internal/dns/utils.js
+++ b/lib/internal/dns/utils.js
@@ -2,8 +2,13 @@
const {
ArrayIsArray,
+ ArrayPrototypeForEach,
+ ArrayPrototypeJoin,
+ ArrayPrototypeMap,
ArrayPrototypePush,
+ FunctionPrototypeBind,
NumberParseInt,
+ StringPrototypeMatch,
StringPrototypeReplace,
} = primordials;
@@ -45,7 +50,7 @@ class Resolver {
}
getServers() {
- return this._handle.getServers().map((val) => {
+ return ArrayPrototypeMap(this._handle.getServers(), (val) => {
if (!val[1] || val[1] === IANA_DNS_PORT)
return val[0];
@@ -65,16 +70,16 @@ class Resolver {
const orig = this._handle.getServers();
const newSet = [];
- servers.forEach((serv, index) => {
+ ArrayPrototypeForEach(servers, (serv, index) => {
if (typeof serv !== 'string') {
throw new ERR_INVALID_ARG_TYPE(`servers[${index}]`, 'string', serv);
}
let ipVersion = isIP(serv);
if (ipVersion !== 0)
- return newSet.push([ipVersion, serv, IANA_DNS_PORT]);
+ return ArrayPrototypePush(newSet, [ipVersion, serv, IANA_DNS_PORT]);
- const match = serv.match(IPv6RE);
+ const match = StringPrototypeMatch(serv, IPv6RE);
// Check for an IPv6 in brackets.
if (match) {
@@ -88,7 +93,7 @@ class Resolver {
}
// addr::port
- const addrSplitMatch = serv.match(addrSplitRE);
+ const addrSplitMatch = StringPrototypeMatch(serv, addrSplitRE);
if (addrSplitMatch) {
const hostIP = addrSplitMatch[1];
@@ -109,7 +114,7 @@ class Resolver {
if (errorNumber !== 0) {
// Reset the servers to the old servers, because ares probably unset them.
- this._handle.setServers(orig.join(','));
+ this._handle.setServers(ArrayPrototypeJoin(orig, ','));
const err = strerror(errorNumber);
throw new ERR_DNS_SET_SERVERS_FAILED(err, servers);
}
@@ -156,8 +161,8 @@ function setDefaultResolver(resolver) {
}
function bindDefaultResolver(target, source) {
- resolverKeys.forEach((key) => {
- target[key] = source[key].bind(defaultResolver);
+ ArrayPrototypeForEach(resolverKeys, (key) => {
+ target[key] = FunctionPrototypeBind(source[key], defaultResolver);
});
}