Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: remove usage of require('util') #26920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

const EventEmitter = require('events');
const stream = require('stream');
const util = require('util');
const internalUtil = require('internal/util');
const { inspect } = require('internal/util/inspect');
const debug = require('internal/util/debuglog').debuglog('net');
const { deprecate } = require('internal/util');
const {
isIP,
isIPv4,
Expand Down Expand Up @@ -130,8 +131,6 @@ function getNewAsyncId(handle) {
}


const debug = util.debuglog('net');

function isPipeName(s) {
return typeof s === 'string' && toNumber(s) === false;
}
Expand Down Expand Up @@ -335,7 +334,8 @@ function Socket(options) {
this[kBytesRead] = 0;
this[kBytesWritten] = 0;
}
util.inherits(Socket, stream.Duplex);
Object.setPrototypeOf(Socket.prototype, stream.Duplex.prototype);
Object.setPrototypeOf(Socket, stream.Duplex);

// Refresh existing timeouts.
Socket.prototype._unrefTimer = function _unrefTimer() {
Expand Down Expand Up @@ -1094,17 +1094,17 @@ function Server(options, connectionListener) {
this._connections = 0;

Object.defineProperty(this, 'connections', {
get: internalUtil.deprecate(() => {
get: deprecate(() => {

if (this._usingWorkers) {
return null;
}
return this._connections;
}, 'Server.connections property is deprecated. ' +
'Use Server.getConnections method instead.', 'DEP0020'),
set: internalUtil.deprecate((val) => (this._connections = val),
'Server.connections property is deprecated.',
'DEP0020'),
set: deprecate((val) => (this._connections = val),
'Server.connections property is deprecated.',
'DEP0020'),
configurable: true, enumerable: false
});

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

throw new ERR_INVALID_OPT_VALUE('options', util.inspect(options));
throw new ERR_INVALID_OPT_VALUE('options', inspect(options));
};

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


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

Server.prototype._setupWorker = function(socketList) {
this._usingWorkers = true;
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-net-access-byteswritten.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const tty = require('tty');
// Check that the bytesWritten getter doesn't crash if object isn't
// constructed.
assert.strictEqual(net.Socket.prototype.bytesWritten, undefined);
assert.strictEqual(tls.TLSSocket.super_.prototype.bytesWritten, undefined);
assert.strictEqual(Object.getPrototypeOf(tls.TLSSocket).prototype.bytesWritten,
undefined);
assert.strictEqual(tls.TLSSocket.prototype.bytesWritten, undefined);
assert.strictEqual(tty.ReadStream.super_.prototype.bytesWritten, undefined);
assert.strictEqual(Object.getPrototypeOf(tty.ReadStream).prototype.bytesWritten,
undefined);
assert.strictEqual(tty.ReadStream.prototype.bytesWritten, undefined);
assert.strictEqual(tty.WriteStream.prototype.bytesWritten, undefined);