Skip to content

Commit f0b3855

Browse files
dnluptargos
authored andcommitted
net: remove usage of require('util')
Use `require('internal/util/inspect').inspect`, `require('internal/util/debuglog').debuglog`, `require('internal/util').deprecate` and `Object.setPrototypeOf` instead of `require('util')`. Fix test in `test/parallel/test-net-access-byteswritten.js` to do not check the `super_` property that was set when using `require('util').inherits`. Refs: #26546 Refs: #26896 PR-URL: #26920 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent e54f237 commit f0b3855

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lib/net.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
const EventEmitter = require('events');
2525
const stream = require('stream');
26-
const util = require('util');
27-
const internalUtil = require('internal/util');
26+
const { inspect } = require('internal/util/inspect');
27+
const debug = require('internal/util/debuglog').debuglog('net');
28+
const { deprecate } = require('internal/util');
2829
const {
2930
isIP,
3031
isIPv4,
@@ -130,8 +131,6 @@ function getNewAsyncId(handle) {
130131
}
131132

132133

133-
const debug = util.debuglog('net');
134-
135134
function isPipeName(s) {
136135
return typeof s === 'string' && toNumber(s) === false;
137136
}
@@ -335,7 +334,8 @@ function Socket(options) {
335334
this[kBytesRead] = 0;
336335
this[kBytesWritten] = 0;
337336
}
338-
util.inherits(Socket, stream.Duplex);
337+
Object.setPrototypeOf(Socket.prototype, stream.Duplex.prototype);
338+
Object.setPrototypeOf(Socket, stream.Duplex);
339339

340340
// Refresh existing timeouts.
341341
Socket.prototype._unrefTimer = function _unrefTimer() {
@@ -1094,17 +1094,17 @@ function Server(options, connectionListener) {
10941094
this._connections = 0;
10951095

10961096
Object.defineProperty(this, 'connections', {
1097-
get: internalUtil.deprecate(() => {
1097+
get: deprecate(() => {
10981098

10991099
if (this._usingWorkers) {
11001100
return null;
11011101
}
11021102
return this._connections;
11031103
}, 'Server.connections property is deprecated. ' +
11041104
'Use Server.getConnections method instead.', 'DEP0020'),
1105-
set: internalUtil.deprecate((val) => (this._connections = val),
1106-
'Server.connections property is deprecated.',
1107-
'DEP0020'),
1105+
set: deprecate((val) => (this._connections = val),
1106+
'Server.connections property is deprecated.',
1107+
'DEP0020'),
11081108
configurable: true, enumerable: false
11091109
});
11101110

@@ -1406,7 +1406,7 @@ Server.prototype.listen = function(...args) {
14061406
'must have the property "port" or "path"');
14071407
}
14081408

1409-
throw new ERR_INVALID_OPT_VALUE('options', util.inspect(options));
1409+
throw new ERR_INVALID_OPT_VALUE('options', inspect(options));
14101410
};
14111411

14121412
function lookupAndListen(self, port, address, backlog, exclusive, flags) {
@@ -1590,10 +1590,10 @@ Object.defineProperty(Socket.prototype, '_handle', {
15901590
});
15911591

15921592

1593-
Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) {
1593+
Server.prototype.listenFD = deprecate(function(fd, type) {
15941594
return this.listen({ fd: fd });
15951595
}, 'Server.listenFD is deprecated. Use Server.listen({fd: <number>}) instead.',
1596-
'DEP0021');
1596+
'DEP0021');
15971597

15981598
Server.prototype._setupWorker = function(socketList) {
15991599
this._usingWorkers = true;

test/parallel/test-net-access-byteswritten.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ const tty = require('tty');
1212
// Check that the bytesWritten getter doesn't crash if object isn't
1313
// constructed.
1414
assert.strictEqual(net.Socket.prototype.bytesWritten, undefined);
15-
assert.strictEqual(tls.TLSSocket.super_.prototype.bytesWritten, undefined);
15+
assert.strictEqual(Object.getPrototypeOf(tls.TLSSocket).prototype.bytesWritten,
16+
undefined);
1617
assert.strictEqual(tls.TLSSocket.prototype.bytesWritten, undefined);
17-
assert.strictEqual(tty.ReadStream.super_.prototype.bytesWritten, undefined);
18+
assert.strictEqual(Object.getPrototypeOf(tty.ReadStream).prototype.bytesWritten,
19+
undefined);
1820
assert.strictEqual(tty.ReadStream.prototype.bytesWritten, undefined);
1921
assert.strictEqual(tty.WriteStream.prototype.bytesWritten, undefined);

0 commit comments

Comments
 (0)