From 8b0c482647004667ac9688f72264b9efca36b699 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 23 Aug 2018 09:28:41 -0400 Subject: [PATCH] dns: make process.binding('cares_wrap') internal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/22474 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Daniel Bevenius Reviewed-By: Michaƫl Zasso Reviewed-By: Anna Henningsen --- lib/dns.js | 3 ++- lib/internal/bootstrap/node.js | 1 + lib/internal/dns/promises.js | 3 ++- lib/internal/dns/utils.js | 3 ++- lib/internal/net.js | 3 ++- lib/tls.js | 2 +- src/cares_wrap.cc | 2 +- test/internet/test-dns.js | 4 +++- test/parallel/test-dns-lookup.js | 5 ++--- test/parallel/test-tls-canonical-ip.js | 4 +++- test/sequential/test-async-wrap-getasyncid.js | 2 +- 11 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index 7059ed91ddc..44fdb1764a1 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -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'); diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 26d0b2710f7..abe4d44b12e 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -348,6 +348,7 @@ // internalBinding. const internalBindingWhitelist = new SafeSet([ + 'cares_wrap', 'fs_event_wrap', 'uv', 'pipe_wrap', diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index 9ba202e5b2c..408dec712d8 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -6,6 +6,7 @@ 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, @@ -13,7 +14,7 @@ const { GetAddrInfoReqWrap, GetNameInfoReqWrap, QueryReqWrap -} = process.binding('cares_wrap'); +} = internalBinding('cares_wrap'); const { ERR_INVALID_ARG_TYPE, ERR_INVALID_OPT_VALUE, diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js index f6bace7528f..2362f28a821 100644 --- a/lib/internal/dns/utils.js +++ b/lib/internal/dns/utils.js @@ -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+))?$/; diff --git a/lib/internal/net.js b/lib/internal/net.js index 78e155e055a..8e72033e555 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -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'); diff --git a/lib/tls.js b/lib/tls.js index d58906b2867..9da17411db3 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -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'); diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 9d3d0987344..d32c8c2ba68 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -2238,4 +2238,4 @@ void Initialize(Local 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) diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 4608713927a..5c53781fde4 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -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 @@ -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'); @@ -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); diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index b45393718a3..b20d403d37b 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -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; diff --git a/test/parallel/test-tls-canonical-ip.js b/test/parallel/test-tls-canonical-ip.js index 408948119c3..f5a4aab17a2 100644 --- a/test/parallel/test-tls-canonical-ip.js +++ b/test/parallel/test-tls-canonical-ip.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; require('../common'); @@ -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'); diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 6e17b657932..866970c0d6d 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -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');