Skip to content

Commit 43fa556

Browse files
committed
lib: remove internal util.inherits() usage
It is recommended not to use this function anymore. Therefore all internal usage is removed and switched to `Object.setPrototypeOf()`.
1 parent 1c7b5db commit 43fa556

7 files changed

Lines changed: 22 additions & 14 deletions

File tree

lib/_http_server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
'use strict';
2323

24-
const util = require('util');
2524
const net = require('net');
2625
const assert = require('assert').ok;
2726
const {
@@ -309,7 +308,8 @@ function Server(options, requestListener) {
309308
this.maxHeadersCount = null;
310309
this.headersTimeout = 40 * 1000; // 40 seconds
311310
}
312-
util.inherits(Server, net.Server);
311+
Object.setPrototypeOf(Server, net.Server);
312+
Object.setPrototypeOf(Server.prototype, net.Server.prototype);
313313

314314

315315
Server.prototype.setTimeout = function setTimeout(msecs, callback) {

lib/_tls_wrap.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ function TLSSocket(socket, opts) {
347347
// Read on next tick so the caller has a chance to setup listeners
348348
process.nextTick(initRead, this, socket);
349349
}
350-
util.inherits(TLSSocket, net.Socket);
350+
Object.setPrototypeOf(TLSSocket, net.Socket);
351+
Object.setPrototypeOf(TLSSocket.prototype, net.Socket.prototype);
352+
351353
exports.TLSSocket = TLSSocket;
352354

353355
var proxiedMethods = [
@@ -881,7 +883,9 @@ function Server(options, listener) {
881883
}
882884
}
883885

884-
util.inherits(Server, net.Server);
886+
Object.setPrototypeOf(Server, net.Server);
887+
Object.setPrototypeOf(Server.prototype, net.Server.prototype);
888+
885889
exports.Server = Server;
886890
exports.createServer = function createServer(options, listener) {
887891
return new Server(options, listener);

lib/https.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const {
3333
kServerResponse
3434
} = require('_http_server');
3535
const { ClientRequest } = require('_http_client');
36-
const { inherits } = util;
3736
const debug = util.debuglog('https');
3837
const { URL, urlToOptions, searchParamsSymbol } = require('internal/url');
3938
const { IncomingMessage, ServerResponse } = require('http');
@@ -76,7 +75,8 @@ function Server(opts, requestListener) {
7675
this.maxHeadersCount = null;
7776
this.headersTimeout = 40 * 1000; // 40 seconds
7877
}
79-
inherits(Server, tls.Server);
78+
Object.setPrototypeOf(Server, tls.Server);
79+
Object.setPrototypeOf(Server.prototype, tls.Server.prototype);
8080

8181
Server.prototype.setTimeout = HttpServer.prototype.setTimeout;
8282

lib/internal/streams/lazy_transform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'use strict';
55

66
const stream = require('stream');
7-
const util = require('util');
87

98
const {
109
getDefaultEncoding
@@ -17,7 +16,8 @@ function LazyTransform(options) {
1716
this.writable = true;
1817
this.readable = true;
1918
}
20-
util.inherits(LazyTransform, stream.Transform);
19+
Object.setPrototypeOf(LazyTransform, stream.Transform);
20+
Object.setPrototypeOf(LazyTransform.prototype, stream.Transform.prototype);
2121

2222
function makeGetter(name) {
2323
return function() {

lib/net.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ function Socket(options) {
331331
this[kBytesRead] = 0;
332332
this[kBytesWritten] = 0;
333333
}
334-
util.inherits(Socket, stream.Duplex);
334+
Object.setPrototypeOf(Socket, stream.Duplex);
335+
Object.setPrototypeOf(Socket.prototype, stream.Duplex.prototype);
335336

336337
// Refresh existing timeouts.
337338
Socket.prototype._unrefTimer = function _unrefTimer() {

lib/tty.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
'use strict';
2323

24-
const { inherits } = require('util');
2524
const net = require('net');
2625
const { TTY, isTTY } = internalBinding('tty_wrap');
2726
const errors = require('internal/errors');
@@ -58,7 +57,8 @@ function ReadStream(fd, options) {
5857
this.isRaw = false;
5958
this.isTTY = true;
6059
}
61-
inherits(ReadStream, net.Socket);
60+
Object.setPrototypeOf(ReadStream, net.Socket);
61+
Object.setPrototypeOf(ReadStream.prototype, net.Socket.prototype);
6262

6363
ReadStream.prototype.setRawMode = function(flag) {
6464
flag = !!flag;
@@ -103,7 +103,8 @@ function WriteStream(fd) {
103103
this.rows = winSize[1];
104104
}
105105
}
106-
inherits(WriteStream, net.Socket);
106+
Object.setPrototypeOf(WriteStream, net.Socket);
107+
Object.setPrototypeOf(WriteStream.prototype, net.Socket.prototype);
107108

108109
WriteStream.prototype.isTTY = true;
109110

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

Lines changed: 4 additions & 2 deletions
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)