From 57d98bc7323b4f72631074cd68a9306f33066bb8 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 21 Aug 2018 08:54:02 +0200 Subject: [PATCH] src: move process.binding('tcp_wrap') to internal This commit makes the tcp_wrap builtin an internal builtin, and changes usage of the builtin from using process.binding('tcp_wrap') to use internalBinding instead. Refs: https://github.com/nodejs/node/issues/22160 PR-URL: https://github.com/nodejs/node/pull/22432 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat --- lib/_tls_wrap.js | 4 ++-- lib/internal/bootstrap/node.js | 3 ++- lib/internal/child_process.js | 2 +- lib/net.js | 2 +- src/tcp_wrap.cc | 2 +- test/common/index.js | 3 ++- test/parallel/test-dgram-bind-fd-error.js | 3 ++- test/parallel/test-dgram-create-socket-handle-fd.js | 4 +++- ...st-env-newprotomethod-remove-unnecessary-prototypes.js | 8 +++++--- test/parallel/test-http-localaddress.js | 1 + test/parallel/test-https-localaddress.js | 1 + test/parallel/test-net-persistent-nodelay.js | 4 +++- test/parallel/test-net-persistent-ref-unref.js | 4 +++- test/parallel/test-net-server-listen-handle.js | 4 +++- test/parallel/test-tcp-wrap-connect.js | 7 +++++-- test/parallel/test-tcp-wrap-listen.js | 2 +- test/parallel/test-tcp-wrap.js | 2 +- test/sequential/test-async-wrap-getasyncid.js | 4 ++-- 18 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 15604f466df12d..9124bb7ddcc5e9 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -33,10 +33,10 @@ const { StreamWrap } = require('_stream_wrap'); const { Buffer } = require('buffer'); const debug = util.debuglog('tls'); const tls_wrap = process.binding('tls_wrap'); -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); +const { internalBinding } = require('internal/bootstrap/loaders'); +const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap'); const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); const { owner_symbol } = require('internal/async_hooks').symbols; -const { internalBinding } = require('internal/bootstrap/loaders'); const { SecureContext: NativeSecureContext } = internalBinding('crypto'); const { ERR_INVALID_ARG_TYPE, diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 2482b5d31b8fd5..23088c2b71158f 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -352,7 +352,8 @@ 'stream_wrap', 'signal_wrap', 'crypto', - 'contextify']); + 'contextify', + 'tcp_wrap']); process.binding = function binding(name) { return internalBindingWhitelist.has(name) ? internalBinding(name) : diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index cf7e23bf7a9248..479b1362f7b191 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -27,7 +27,7 @@ const { Process } = process.binding('process_wrap'); const { WriteWrap } = internalBinding('stream_wrap'); const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); const { TTY } = process.binding('tty_wrap'); -const { TCP } = process.binding('tcp_wrap'); +const { TCP } = internalBinding('tcp_wrap'); const { UDP } = process.binding('udp_wrap'); const SocketList = require('internal/socket_list'); const { owner_symbol } = require('internal/async_hooks').symbols; diff --git a/lib/net.js b/lib/net.js index 428675173f3e3e..2700a54a0780ce 100644 --- a/lib/net.js +++ b/lib/net.js @@ -48,7 +48,7 @@ const { TCP, TCPConnectWrap, constants: TCPConstants -} = process.binding('tcp_wrap'); +} = internalBinding('tcp_wrap'); const { Pipe, PipeConnectWrap, diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index e817087d97110b..ebc82f46683200 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -375,4 +375,4 @@ Local AddressToJS(Environment* env, } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(tcp_wrap, node::TCPWrap::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(tcp_wrap, node::TCPWrap::Initialize) diff --git a/test/common/index.js b/test/common/index.js index 369f23f790c5f4..0f453d3af55fe4 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -444,7 +444,8 @@ function _mustCallInner(fn, criteria = 1, field) { } exports.hasMultiLocalhost = function hasMultiLocalhost() { - const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); + const { internalBinding } = require('internal/test/binding'); + const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap'); const t = new TCP(TCPConstants.SOCKET); const ret = t.bind('127.0.0.2', 0); t.close(); diff --git a/test/parallel/test-dgram-bind-fd-error.js b/test/parallel/test-dgram-bind-fd-error.js index efe0e43d7b5673..519855bacc4861 100644 --- a/test/parallel/test-dgram-bind-fd-error.js +++ b/test/parallel/test-dgram-bind-fd-error.js @@ -7,7 +7,8 @@ if (common.isWindows) const dgram = require('dgram'); const assert = require('assert'); const { kStateSymbol } = require('internal/dgram'); -const { TCP, constants } = process.binding('tcp_wrap'); +const { internalBinding } = require('internal/test/binding'); +const { TCP, constants } = internalBinding('tcp_wrap'); const TYPE = 'udp4'; // Throw when the fd is occupied according to https://github.com/libuv/libuv/pull/1851. diff --git a/test/parallel/test-dgram-create-socket-handle-fd.js b/test/parallel/test-dgram-create-socket-handle-fd.js index ff507b6ec5091e..3829ec245f07ee 100644 --- a/test/parallel/test-dgram-create-socket-handle-fd.js +++ b/test/parallel/test-dgram-create-socket-handle-fd.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); if (common.isWindows) @@ -6,7 +7,8 @@ if (common.isWindows) const assert = require('assert'); const dgram = require('dgram'); const { UDP } = process.binding('udp_wrap'); -const { TCP, constants } = process.binding('tcp_wrap'); +const { internalBinding } = require('internal/test/binding'); +const { TCP, constants } = internalBinding('tcp_wrap'); const _createSocketHandle = dgram._createSocketHandle; // Return a negative number if the "existing fd" is invalid. diff --git a/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js b/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js index bcc522cd45ad50..ff76e9fa5c997f 100644 --- a/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js +++ b/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; require('../common'); @@ -5,14 +6,15 @@ require('../common'); // being generated by Environment::NewFunctionTemplate. const assert = require('assert'); +const { internalBinding } = require('internal/test/binding'); [ process.binding('udp_wrap').UDP.prototype.bind6, - process.binding('tcp_wrap').TCP.prototype.bind6, + internalBinding('tcp_wrap').TCP.prototype.bind6, process.binding('udp_wrap').UDP.prototype.send6, - process.binding('tcp_wrap').TCP.prototype.bind, + internalBinding('tcp_wrap').TCP.prototype.bind, process.binding('udp_wrap').UDP.prototype.close, - process.binding('tcp_wrap').TCP.prototype.open + internalBinding('tcp_wrap').TCP.prototype.open ].forEach((binding, i) => { assert.strictEqual('prototype' in binding, false, `Test ${i} failed`); }); diff --git a/test/parallel/test-http-localaddress.js b/test/parallel/test-http-localaddress.js index 0ed048688eefae..8c5e57b118b597 100644 --- a/test/parallel/test-http-localaddress.js +++ b/test/parallel/test-http-localaddress.js @@ -19,6 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +// Flags: --expose-internals 'use strict'; const common = require('../common'); if (!common.hasMultiLocalhost()) diff --git a/test/parallel/test-https-localaddress.js b/test/parallel/test-https-localaddress.js index bfa24457dac64e..4bf3835dddbc8c 100644 --- a/test/parallel/test-https-localaddress.js +++ b/test/parallel/test-https-localaddress.js @@ -19,6 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +// Flags: --expose-internals 'use strict'; const common = require('../common'); if (!common.hasCrypto) diff --git a/test/parallel/test-net-persistent-nodelay.js b/test/parallel/test-net-persistent-nodelay.js index bb2a9dfd22e5cc..de7f0a7f65813e 100644 --- a/test/parallel/test-net-persistent-nodelay.js +++ b/test/parallel/test-net-persistent-nodelay.js @@ -1,8 +1,10 @@ +// Flags: --expose-internals 'use strict'; require('../common'); const assert = require('assert'); const net = require('net'); -const TCPWrap = process.binding('tcp_wrap').TCP; +const { internalBinding } = require('internal/test/binding'); +const TCPWrap = internalBinding('tcp_wrap').TCP; const echoServer = net.createServer(function(connection) { connection.end(); diff --git a/test/parallel/test-net-persistent-ref-unref.js b/test/parallel/test-net-persistent-ref-unref.js index d8de7ba3f2877a..15b71f6d02fc15 100644 --- a/test/parallel/test-net-persistent-ref-unref.js +++ b/test/parallel/test-net-persistent-ref-unref.js @@ -1,8 +1,10 @@ +// Flags: --expose-internals 'use strict'; require('../common'); const assert = require('assert'); const net = require('net'); -const TCPWrap = process.binding('tcp_wrap').TCP; +const { internalBinding } = require('internal/test/binding'); +const TCPWrap = internalBinding('tcp_wrap').TCP; const echoServer = net.createServer(function(conn) { conn.end(); diff --git a/test/parallel/test-net-server-listen-handle.js b/test/parallel/test-net-server-listen-handle.js index 5bf8451302fae9..32af3c3e0e2dc1 100644 --- a/test/parallel/test-net-server-listen-handle.js +++ b/test/parallel/test-net-server-listen-handle.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); @@ -5,7 +6,8 @@ const assert = require('assert'); const net = require('net'); const fs = require('fs'); const { getSystemErrorName } = require('util'); -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); +const { internalBinding } = require('internal/test/binding'); +const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap'); const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); const tmpdir = require('../common/tmpdir'); diff --git a/test/parallel/test-tcp-wrap-connect.js b/test/parallel/test-tcp-wrap-connect.js index a903307e5b6cca..354c9d74edd505 100644 --- a/test/parallel/test-tcp-wrap-connect.js +++ b/test/parallel/test-tcp-wrap-connect.js @@ -3,8 +3,11 @@ require('../common'); const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); -const { TCPConnectWrap } = process.binding('tcp_wrap'); +const { + TCP, + constants: TCPConstants, + TCPConnectWrap +} = internalBinding('tcp_wrap'); const { ShutdownWrap } = internalBinding('stream_wrap'); function makeConnection() { diff --git a/test/parallel/test-tcp-wrap-listen.js b/test/parallel/test-tcp-wrap-listen.js index 7df5a11ff1861e..a1f38a4b49404f 100644 --- a/test/parallel/test-tcp-wrap-listen.js +++ b/test/parallel/test-tcp-wrap-listen.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); +const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap'); const { WriteWrap } = internalBinding('stream_wrap'); const server = new TCP(TCPConstants.SOCKET); diff --git a/test/parallel/test-tcp-wrap.js b/test/parallel/test-tcp-wrap.js index f6a54a012b80cc..f044d05a0524ed 100644 --- a/test/parallel/test-tcp-wrap.js +++ b/test/parallel/test-tcp-wrap.js @@ -24,8 +24,8 @@ require('../common'); const assert = require('assert'); -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); const { internalBinding } = require('internal/test/binding'); +const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap'); const { UV_EINVAL } = internalBinding('uv'); const handle = new TCP(TCPConstants.SOCKET); diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 8000c5e4ca2cb6..9386c331996ebc 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -207,7 +207,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check { const stream_wrap = internalBinding('stream_wrap'); - const tcp_wrap = process.binding('tcp_wrap'); + const tcp_wrap = internalBinding('tcp_wrap'); const server = net.createServer(common.mustCall((socket) => { server.close(); socket.on('data', () => { @@ -256,7 +256,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check - const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); + const { TCP, constants: TCPConstants } = internalBinding('tcp_wrap'); const tcp = new TCP(TCPConstants.SOCKET); const ca = fixtures.readSync('test_ca.pem', 'ascii');