Skip to content

Commit

Permalink
dns: make process.binding('cares_wrap') internal
Browse files Browse the repository at this point in the history
PR-URL: #22474
Refs: #22160
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
cjihrig committed Aug 30, 2018
1 parent 6046570 commit 8b0c482
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

'use strict';

const cares = process.binding('cares_wrap');
const { internalBinding } = require('internal/bootstrap/loaders');
const cares = internalBinding('cares_wrap');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const errors = require('internal/errors');
Expand Down
1 change: 1 addition & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
// internalBinding.
const internalBindingWhitelist =
new SafeSet([
'cares_wrap',
'fs_event_wrap',
'uv',
'pipe_wrap',
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ const {
} = require('internal/dns/utils');
const { codes, dnsException } = require('internal/errors');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
const { internalBinding } = require('internal/bootstrap/loaders');
const {
getaddrinfo,
getnameinfo,
ChannelWrap,
GetAddrInfoReqWrap,
GetNameInfoReqWrap,
QueryReqWrap
} = process.binding('cares_wrap');
} = internalBinding('cares_wrap');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_OPT_VALUE,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';
const errors = require('internal/errors');
const { isIP } = require('internal/net');
const { internalBinding } = require('internal/bootstrap/loaders');
const {
ChannelWrap,
strerror,
AI_ADDRCONFIG,
AI_V4MAPPED
} = process.binding('cares_wrap');
} = internalBinding('cares_wrap');
const IANA_DNS_PORT = 53;
const IPv6RE = /^\[([^[\]]*)\]/;
const addrSplitRE = /(^.+?)(?::(\d+))?$/;
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/net.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const Buffer = require('buffer').Buffer;
const { isIPv6 } = process.binding('cares_wrap');
const { internalBinding } = require('internal/bootstrap/loaders');
const { isIPv6 } = internalBinding('cares_wrap');
const { writeBuffer } = process.binding('fs');
const errors = require('internal/errors');

Expand Down
2 changes: 1 addition & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const { Buffer } = require('buffer');
const EventEmitter = require('events');
const { URL } = require('internal/url');
const DuplexPair = require('internal/streams/duplexpair');
const { canonicalizeIP } = process.binding('cares_wrap');
const { canonicalizeIP } = internalBinding('cares_wrap');
const _tls_common = require('_tls_common');
const _tls_wrap = require('_tls_wrap');

Expand Down
2 changes: 1 addition & 1 deletion src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2238,4 +2238,4 @@ void Initialize(Local<Object> target,
} // namespace cares_wrap
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(cares_wrap, node::cares_wrap::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(cares_wrap, node::cares_wrap::Initialize)
4 changes: 3 additions & 1 deletion test/internet/test-dns.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -22,6 +23,7 @@
'use strict';
const common = require('../common');
const { addresses } = require('../common/internet');
const { internalBinding } = require('internal/test/binding');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
Expand Down Expand Up @@ -674,7 +676,7 @@ let getaddrinfoCallbackCalled = false;

console.log(`looking up ${addresses.INET4_HOST}..`);

const cares = process.binding('cares_wrap');
const cares = internalBinding('cares_wrap');
const req = new cares.GetAddrInfoReqWrap();
cares.getaddrinfo(req, addresses.INET4_HOST, 4,
/* hints */ 0, /* verbatim */ true);
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
const common = require('../common');
const { addresses } = require('../common/internet');
const assert = require('assert');
const cares = process.binding('cares_wrap');
const { internalBinding } = require('internal/test/binding');
const cares = internalBinding('cares_wrap');
const dns = require('dns');
const dnsPromises = dns.promises;

const { internalBinding } = require('internal/test/binding');

// Stub `getaddrinfo` to *always* error.
cares.getaddrinfo = () => internalBinding('uv').UV_ENOENT;

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tls-canonical-ip.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';
require('../common');

Expand All @@ -6,7 +7,8 @@ require('../common');
// of a TLS certificate

const assert = require('assert');
const { canonicalizeIP } = process.binding('cares_wrap');
const { internalBinding } = require('internal/test/binding');
const { canonicalizeIP } = internalBinding('cares_wrap');

assert.strictEqual(canonicalizeIP('127.0.0.1'), '127.0.0.1');
assert.strictEqual(canonicalizeIP('10.1.0.1'), '10.1.0.1');
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function testInitialized(req, ctor_name) {


{
const cares = process.binding('cares_wrap');
const cares = internalBinding('cares_wrap');
const dns = require('dns');

testUninitialized(new cares.GetAddrInfoReqWrap(), 'GetAddrInfoReqWrap');
Expand Down

0 comments on commit 8b0c482

Please sign in to comment.