Skip to content

Commit

Permalink
src: move process.binding('tcp_wrap') to internal
Browse files Browse the repository at this point in the history
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: #22160

PR-URL: #22432
Refs: #22160
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
danbev committed Aug 24, 2018
1 parent 56e331a commit 57d98bc
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@
'stream_wrap',
'signal_wrap',
'crypto',
'contextify']);
'contextify',
'tcp_wrap']);
process.binding = function binding(name) {
return internalBindingWhitelist.has(name) ?
internalBinding(name) :
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const {
TCP,
TCPConnectWrap,
constants: TCPConstants
} = process.binding('tcp_wrap');
} = internalBinding('tcp_wrap');
const {
Pipe,
PipeConnectWrap,
Expand Down
2 changes: 1 addition & 1 deletion src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,4 @@ Local<Object> 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)
3 changes: 2 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-dgram-bind-fd-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-dgram-create-socket-handle-fd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
if (common.isWindows)
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Flags: --expose-internals
'use strict';
require('../common');

// This test ensures that unnecessary prototypes are no longer
// 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`);
});
1 change: 1 addition & 0 deletions test/parallel/test-http-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-https-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-net-persistent-nodelay.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-net-persistent-ref-unref.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-net-server-listen-handle.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
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');
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-tcp-wrap-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tcp-wrap-listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tcp-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 57d98bc

Please sign in to comment.