From c8950cdabc2f8cd0b146797f2045a67974687d5a Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 23 Aug 2018 09:49:35 -0400 Subject: [PATCH] dgram: make process.binding('udp_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/22475 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Tobias Nießen Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Michaël Zasso --- lib/dgram.js | 3 ++- lib/internal/bootstrap/node.js | 1 + lib/internal/child_process.js | 2 +- lib/internal/dgram.js | 2 +- src/udp_wrap.cc | 2 +- test/parallel/test-accessor-properties.js | 2 +- test/parallel/test-cluster-dgram-bind-fd.js | 5 ++++- test/parallel/test-dgram-bind-fd.js | 4 +++- test/parallel/test-dgram-create-socket-handle-fd.js | 2 +- test/parallel/test-dgram-create-socket-handle.js | 3 ++- ...est-env-newprotomethod-remove-unnecessary-prototypes.js | 7 +++---- test/sequential/test-async-wrap-getasyncid.js | 2 +- 12 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index acb0e22e568a92..cfaea69abd9cf3 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -52,9 +52,10 @@ const { defaultTriggerAsyncIdScope, symbols: { async_id_symbol, owner_symbol } } = require('internal/async_hooks'); +const { internalBinding } = require('internal/bootstrap/loaders'); const { UV_UDP_REUSEADDR } = process.binding('constants').os; -const { UDP, SendWrap } = process.binding('udp_wrap'); +const { UDP, SendWrap } = internalBinding('udp_wrap'); const BIND_STATE_UNBOUND = 0; const BIND_STATE_BINDING = 1; diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index abe4d44b12ef06..30b177c5a4557c 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -350,6 +350,7 @@ new SafeSet([ 'cares_wrap', 'fs_event_wrap', + 'udp_wrap', 'uv', 'pipe_wrap', 'http_parser', diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 70211e99fec954..a4850f0238d119 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -28,7 +28,7 @@ const { WriteWrap } = internalBinding('stream_wrap'); const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap'); const { TCP } = internalBinding('tcp_wrap'); const { TTY } = internalBinding('tty_wrap'); -const { UDP } = process.binding('udp_wrap'); +const { UDP } = internalBinding('udp_wrap'); const SocketList = require('internal/socket_list'); const { owner_symbol } = require('internal/async_hooks').symbols; const { convertToValidSignal } = require('internal/util'); diff --git a/lib/internal/dgram.js b/lib/internal/dgram.js index f4a1c4e7b89936..829b11bf68706a 100644 --- a/lib/internal/dgram.js +++ b/lib/internal/dgram.js @@ -1,7 +1,7 @@ 'use strict'; const { codes } = require('internal/errors'); const { internalBinding } = require('internal/bootstrap/loaders'); -const { UDP } = process.binding('udp_wrap'); +const { UDP } = internalBinding('udp_wrap'); const { isInt32 } = require('internal/validators'); const TTYWrap = internalBinding('tty_wrap'); const { UV_EINVAL } = internalBinding('uv'); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 9bcf6ceb7b3ed2..d23c62c14ecea1 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -527,4 +527,4 @@ uv_udp_t* UDPWrap::UVHandle() { } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(udp_wrap, node::UDPWrap::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(udp_wrap, node::UDPWrap::Initialize) diff --git a/test/parallel/test-accessor-properties.js b/test/parallel/test-accessor-properties.js index 4cb84e0f12ae91..ce026313d09283 100644 --- a/test/parallel/test-accessor-properties.js +++ b/test/parallel/test-accessor-properties.js @@ -12,7 +12,7 @@ const assert = require('assert'); // their prototype const { internalBinding } = require('internal/test/binding'); const TTY = internalBinding('tty_wrap').TTY; -const UDP = process.binding('udp_wrap').UDP; +const UDP = internalBinding('udp_wrap').UDP; { // Should throw instead of raise assertions diff --git a/test/parallel/test-cluster-dgram-bind-fd.js b/test/parallel/test-cluster-dgram-bind-fd.js index 429f932608e2b2..7b6fb89501fae1 100644 --- a/test/parallel/test-cluster-dgram-bind-fd.js +++ b/test/parallel/test-cluster-dgram-bind-fd.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); if (common.isWindows) @@ -9,7 +10,6 @@ const PACKETS_PER_WORKER = 10; const assert = require('assert'); const cluster = require('cluster'); const dgram = require('dgram'); -const { UDP } = process.binding('udp_wrap'); if (cluster.isMaster) master(); @@ -18,6 +18,9 @@ else function master() { + const { internalBinding } = require('internal/test/binding'); + const { UDP } = internalBinding('udp_wrap'); + // Create a handle and use its fd. const rawHandle = new UDP(); const err = rawHandle.bind(common.localhostIPv4, 0, 0); diff --git a/test/parallel/test-dgram-bind-fd.js b/test/parallel/test-dgram-bind-fd.js index c4a80abb92c4d2..8c81cb118c1001 100644 --- a/test/parallel/test-dgram-bind-fd.js +++ b/test/parallel/test-dgram-bind-fd.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); if (common.isWindows) @@ -5,7 +6,8 @@ if (common.isWindows) const assert = require('assert'); const dgram = require('dgram'); -const { UDP } = process.binding('udp_wrap'); +const { internalBinding } = require('internal/test/binding'); +const { UDP } = internalBinding('udp_wrap'); const { UV_UDP_REUSEADDR } = process.binding('constants').os; const BUFFER_SIZE = 4096; diff --git a/test/parallel/test-dgram-create-socket-handle-fd.js b/test/parallel/test-dgram-create-socket-handle-fd.js index 3829ec245f07ee..93175859c196ea 100644 --- a/test/parallel/test-dgram-create-socket-handle-fd.js +++ b/test/parallel/test-dgram-create-socket-handle-fd.js @@ -6,8 +6,8 @@ if (common.isWindows) const assert = require('assert'); const dgram = require('dgram'); -const { UDP } = process.binding('udp_wrap'); const { internalBinding } = require('internal/test/binding'); +const { UDP } = internalBinding('udp_wrap'); const { TCP, constants } = internalBinding('tcp_wrap'); const _createSocketHandle = dgram._createSocketHandle; diff --git a/test/parallel/test-dgram-create-socket-handle.js b/test/parallel/test-dgram-create-socket-handle.js index 3df34a95c2b526..6875448474ab8f 100644 --- a/test/parallel/test-dgram-create-socket-handle.js +++ b/test/parallel/test-dgram-create-socket-handle.js @@ -3,7 +3,8 @@ const common = require('../common'); const assert = require('assert'); const { _createSocketHandle } = require('internal/dgram'); -const UDP = process.binding('udp_wrap').UDP; +const { internalBinding } = require('internal/test/binding'); +const UDP = internalBinding('udp_wrap').UDP; { // Create a handle that is not bound. diff --git a/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js b/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js index ff76e9fa5c997f..a2e2dabab0ffb2 100644 --- a/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js +++ b/test/parallel/test-env-newprotomethod-remove-unnecessary-prototypes.js @@ -7,13 +7,12 @@ require('../common'); const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); - [ - process.binding('udp_wrap').UDP.prototype.bind6, + internalBinding('udp_wrap').UDP.prototype.bind6, internalBinding('tcp_wrap').TCP.prototype.bind6, - process.binding('udp_wrap').UDP.prototype.send6, + internalBinding('udp_wrap').UDP.prototype.send6, internalBinding('tcp_wrap').TCP.prototype.bind, - process.binding('udp_wrap').UDP.prototype.close, + internalBinding('udp_wrap').UDP.prototype.close, internalBinding('tcp_wrap').TCP.prototype.open ].forEach((binding, i) => { assert.strictEqual('prototype' in binding, false, `Test ${i} failed`); diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 866970c0d6dafc..a3acda54a1ca9a 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -272,7 +272,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check } { - const binding = process.binding('udp_wrap'); + const binding = internalBinding('udp_wrap'); const handle = new binding.UDP(); const req = new binding.SendWrap(); testInitialized(handle, 'UDP');