Skip to content

Commit dc6c607

Browse files
committed
dns: call ada::idna::to_ascii directly from c++
1 parent 0b3fcfc commit dc6c607

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

lib/dns.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const {
2828
} = primordials;
2929

3030
const cares = internalBinding('cares_wrap');
31-
const { toASCII } = require('internal/idna');
3231
const { isIP } = require('internal/net');
3332
const { customPromisifyArgs } = require('internal/util');
3433
const errors = require('internal/errors');
@@ -220,7 +219,7 @@ function lookup(hostname, options, callback) {
220219
req.oncomplete = all ? onlookupall : onlookup;
221220

222221
const err = cares.getaddrinfo(
223-
req, toASCII(hostname), family, hints, verbatim,
222+
req, hostname, family, hints, verbatim,
224223
);
225224
if (err) {
226225
process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname));

lib/internal/dns/callback_resolver.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const {
77
Symbol,
88
} = primordials;
99

10-
const { toASCII } = require('internal/idna');
11-
1210
const {
1311
codes: {
1412
ERR_INVALID_ARG_TYPE,
@@ -70,7 +68,7 @@ function resolver(bindingName) {
7068
req.hostname = name;
7169
req.oncomplete = onresolve;
7270
req.ttl = !!(options && options.ttl);
73-
const err = this._handle[bindingName](req, toASCII(name));
71+
const err = this._handle[bindingName](req, name);
7472
if (err) throw dnsException(err, bindingName, name);
7573
if (hasObserver('dns')) {
7674
startPerf(req, kPerfHooksDnsLookupResolveContext, {

lib/internal/dns/promises.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const {
4646
CANCELLED,
4747
} = dnsErrorCodes;
4848
const { codes, dnsException } = require('internal/errors');
49-
const { toASCII } = require('internal/idna');
5049
const { isIP } = require('internal/net');
5150
const {
5251
getaddrinfo,
@@ -138,7 +137,7 @@ function createLookupPromise(family, hostname, all, hints, verbatim) {
138137
req.resolve = resolve;
139138
req.reject = reject;
140139

141-
const err = getaddrinfo(req, toASCII(hostname), family, hints, verbatim);
140+
const err = getaddrinfo(req, hostname, family, hints, verbatim);
142141

143142
if (err) {
144143
reject(dnsException(err, 'getaddrinfo', hostname));
@@ -274,7 +273,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) {
274273
req.reject = reject;
275274
req.ttl = ttl;
276275

277-
const err = resolver._handle[bindingName](req, toASCII(hostname));
276+
const err = resolver._handle[bindingName](req, hostname);
278277

279278
if (err)
280279
reject(dnsException(err, bindingName, hostname));

src/cares_wrap.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
#include "ada.h"
2223
#include "cares_wrap.h"
2324
#include "async_wrap-inl.h"
2425
#include "base64-inl.h"
@@ -1558,6 +1559,7 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
15581559
CHECK(args[4]->IsBoolean());
15591560
Local<Object> req_wrap_obj = args[0].As<Object>();
15601561
node::Utf8Value hostname(env->isolate(), args[1]);
1562+
std::string ascii_hostname = ada::idna::to_ascii(hostname.ToStringView());
15611563

15621564
int32_t flags = 0;
15631565
if (args[3]->IsInt32()) {
@@ -1592,13 +1594,13 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
15921594

15931595
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(
15941596
TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(),
1595-
"hostname", TRACE_STR_COPY(*hostname),
1597+
"hostname", TRACE_STR_COPY(ascii_hostname.data()),
15961598
"family",
15971599
family == AF_INET ? "ipv4" : family == AF_INET6 ? "ipv6" : "unspec");
15981600

15991601
int err = req_wrap->Dispatch(uv_getaddrinfo,
16001602
AfterGetAddrInfo,
1601-
*hostname,
1603+
ascii_hostname.data(),
16021604
nullptr,
16031605
&hints);
16041606
if (err == 0)

0 commit comments

Comments
 (0)