Skip to content

Commit dcc82b3

Browse files
BridgeARaddaleax
authored andcommitted
lib: remove inherits() usage
This switches all `util.inherits()` calls to use `Object.setPrototypeOf()` instead. In fact, `util.inherits()` is mainly a small wrapper around exactly this function while adding the `_super` property on the object as well. Refs: #24395 PR-URL: #24755 Refs: #24395 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 6ccc80c commit dcc82b3

26 files changed

+50
-72
lines changed

lib/_http_agent.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ function Agent(options) {
105105
}
106106
});
107107
}
108-
109-
util.inherits(Agent, EventEmitter);
108+
Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype);
110109

111110
Agent.defaultMaxSockets = Infinity;
112111

lib/_http_client.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ function ClientRequest(input, options, cb) {
279279

280280
this._deferToConnect(null, null, () => this._flush());
281281
}
282-
283-
util.inherits(ClientRequest, OutgoingMessage);
284-
282+
Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
285283

286284
ClientRequest.prototype._finish = function _finish() {
287285
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);

lib/_http_incoming.js

Lines changed: 1 addition & 3 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 Stream = require('stream');
2625

2726
function readStart(socket) {
@@ -72,8 +71,7 @@ function IncomingMessage(socket) {
7271
// read by the user, so there's no point continuing to handle it.
7372
this._dumped = false;
7473
}
75-
util.inherits(IncomingMessage, Stream.Readable);
76-
74+
Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype);
7775

7876
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
7977
if (callback)

lib/_http_outgoing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function OutgoingMessage() {
106106

107107
this._onPendingData = noopPendingOutput;
108108
}
109-
util.inherits(OutgoingMessage, Stream);
109+
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
110110

111111

112112
Object.defineProperty(OutgoingMessage.prototype, '_headers', {

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function ServerResponse(req) {
137137
this.shouldKeepAlive = false;
138138
}
139139
}
140-
util.inherits(ServerResponse, OutgoingMessage);
140+
Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
141141

142142
ServerResponse.prototype._finish = function _finish() {
143143
DTRACE_HTTP_SERVER_RESPONSE(this.connection);

lib/_stream_duplex.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828

2929
module.exports = Duplex;
3030

31-
const util = require('util');
3231
const Readable = require('_stream_readable');
3332
const Writable = require('_stream_writable');
3433

35-
util.inherits(Duplex, Readable);
34+
Object.setPrototypeOf(Duplex.prototype, Readable.prototype);
3635

3736
{
3837
// Allow the keys array to be GC'ed.

lib/_stream_passthrough.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
module.exports = PassThrough;
2929

3030
const Transform = require('_stream_transform');
31-
const util = require('util');
32-
util.inherits(PassThrough, Transform);
31+
Object.setPrototypeOf(PassThrough.prototype, Transform.prototype);
3332

3433
function PassThrough(options) {
3534
if (!(this instanceof PassThrough))

lib/_stream_readable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const { emitExperimentalWarning } = require('internal/util');
4444
let StringDecoder;
4545
let createReadableStreamAsyncIterator;
4646

47-
util.inherits(Readable, Stream);
47+
Object.setPrototypeOf(Readable.prototype, Stream.prototype);
4848

4949
const { errorOrDestroy } = destroyImpl;
5050
const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];

lib/_stream_transform.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ const {
7171
ERR_TRANSFORM_WITH_LENGTH_0
7272
} = require('internal/errors').codes;
7373
const Duplex = require('_stream_duplex');
74-
const util = require('util');
75-
util.inherits(Transform, Duplex);
74+
Object.setPrototypeOf(Transform.prototype, Duplex.prototype);
7675

7776

7877
function afterTransform(er, data) {

lib/_stream_writable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
module.exports = Writable;
2929
Writable.WritableState = WritableState;
3030

31-
const util = require('util');
3231
const internalUtil = require('internal/util');
3332
const Stream = require('stream');
3433
const { Buffer } = require('buffer');
@@ -47,7 +46,7 @@ const {
4746

4847
const { errorOrDestroy } = destroyImpl;
4948

50-
util.inherits(Writable, Stream);
49+
Object.setPrototypeOf(Writable.prototype, Stream.prototype);
5150

5251
function nop() {}
5352

0 commit comments

Comments
 (0)