Skip to content

Commit 5925754

Browse files
BridgeARaddaleax
authored andcommitted
lib: use ES6 class inheritance style
PR-URL: #24755 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent dcc82b3 commit 5925754

26 files changed

+43
-0
lines changed

lib/_http_agent.js

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function Agent(options) {
106106
});
107107
}
108108
Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype);
109+
Object.setPrototypeOf(Agent, EventEmitter);
109110

110111
Agent.defaultMaxSockets = Infinity;
111112

lib/_http_client.js

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ function ClientRequest(input, options, cb) {
280280
this._deferToConnect(null, null, () => this._flush());
281281
}
282282
Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
283+
Object.setPrototypeOf(ClientRequest, OutgoingMessage);
283284

284285
ClientRequest.prototype._finish = function _finish() {
285286
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);

lib/_http_incoming.js

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function IncomingMessage(socket) {
7272
this._dumped = false;
7373
}
7474
Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype);
75+
Object.setPrototypeOf(IncomingMessage, Stream.Readable);
7576

7677
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
7778
if (callback)

lib/_http_outgoing.js

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function OutgoingMessage() {
107107
this._onPendingData = noopPendingOutput;
108108
}
109109
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
110+
Object.setPrototypeOf(OutgoingMessage, Stream);
110111

111112

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

lib/_http_server.js

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function ServerResponse(req) {
138138
}
139139
}
140140
Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
141+
Object.setPrototypeOf(ServerResponse, OutgoingMessage);
141142

142143
ServerResponse.prototype._finish = function _finish() {
143144
DTRACE_HTTP_SERVER_RESPONSE(this.connection);

lib/_stream_duplex.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const Readable = require('_stream_readable');
3232
const Writable = require('_stream_writable');
3333

3434
Object.setPrototypeOf(Duplex.prototype, Readable.prototype);
35+
Object.setPrototypeOf(Duplex, Readable);
3536

3637
{
3738
// Allow the keys array to be GC'ed.

lib/_stream_passthrough.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = PassThrough;
2929

3030
const Transform = require('_stream_transform');
3131
Object.setPrototypeOf(PassThrough.prototype, Transform.prototype);
32+
Object.setPrototypeOf(PassThrough, Transform);
3233

3334
function PassThrough(options) {
3435
if (!(this instanceof PassThrough))

lib/_stream_readable.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ let StringDecoder;
4545
let createReadableStreamAsyncIterator;
4646

4747
Object.setPrototypeOf(Readable.prototype, Stream.prototype);
48+
Object.setPrototypeOf(Readable, Stream);
4849

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

lib/_stream_transform.js

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const {
7272
} = require('internal/errors').codes;
7373
const Duplex = require('_stream_duplex');
7474
Object.setPrototypeOf(Transform.prototype, Duplex.prototype);
75+
Object.setPrototypeOf(Transform, Duplex);
7576

7677

7778
function afterTransform(er, data) {

lib/_stream_writable.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const {
4747
const { errorOrDestroy } = destroyImpl;
4848

4949
Object.setPrototypeOf(Writable.prototype, Stream.prototype);
50+
Object.setPrototypeOf(Writable, Stream);
5051

5152
function nop() {}
5253

lib/dgram.js

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function Socket(type, listener) {
109109
};
110110
}
111111
Object.setPrototypeOf(Socket.prototype, EventEmitter.prototype);
112+
Object.setPrototypeOf(Socket, EventEmitter);
112113

113114

114115
function createSocket(type, listener) {

lib/https.js

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function Agent(options) {
150150
};
151151
}
152152
Object.setPrototypeOf(Agent.prototype, HttpAgent.prototype);
153+
Object.setPrototypeOf(Agent, HttpAgent);
153154
Agent.prototype.createConnection = createConnection;
154155

155156
Agent.prototype.getName = function getName(options) {

lib/internal/child_process.js

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ function ChildProcess() {
266266
};
267267
}
268268
Object.setPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
269+
Object.setPrototypeOf(ChildProcess, EventEmitter);
269270

270271

271272
function flushStdio(subprocess) {

lib/internal/cluster/worker.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function Worker(options) {
3030
}
3131

3232
Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype);
33+
Object.setPrototypeOf(Worker, EventEmitter);
3334

3435
Worker.prototype.kill = function() {
3536
this.destroy.apply(this, arguments);

lib/internal/crypto/cipher.js

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function Cipher(cipher, password, options) {
124124
}
125125

126126
Object.setPrototypeOf(Cipher.prototype, LazyTransform.prototype);
127+
Object.setPrototypeOf(Cipher, LazyTransform);
127128

128129
Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
129130
this.push(this[kHandle].update(chunk, encoding));
@@ -254,6 +255,7 @@ function addCipherPrototypeFunctions(constructor) {
254255
}
255256

256257
Object.setPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
258+
Object.setPrototypeOf(Cipheriv, LazyTransform);
257259
addCipherPrototypeFunctions(Cipheriv);
258260
legacyNativeHandle(Cipheriv);
259261

@@ -265,6 +267,7 @@ function Decipher(cipher, password, options) {
265267
}
266268

267269
Object.setPrototypeOf(Decipher.prototype, LazyTransform.prototype);
270+
Object.setPrototypeOf(Decipher, LazyTransform);
268271
addCipherPrototypeFunctions(Decipher);
269272
legacyNativeHandle(Decipher);
270273

@@ -277,6 +280,7 @@ function Decipheriv(cipher, key, iv, options) {
277280
}
278281

279282
Object.setPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
283+
Object.setPrototypeOf(Decipheriv, LazyTransform);
280284
addCipherPrototypeFunctions(Decipheriv);
281285
legacyNativeHandle(Decipheriv);
282286

lib/internal/crypto/hash.js

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function Hash(algorithm, options) {
3939
}
4040

4141
Object.setPrototypeOf(Hash.prototype, LazyTransform.prototype);
42+
Object.setPrototypeOf(Hash, LazyTransform);
4243

4344
Hash.prototype._transform = function _transform(chunk, encoding, callback) {
4445
this[kHandle].update(chunk, encoding);
@@ -100,6 +101,7 @@ function Hmac(hmac, key, options) {
100101
}
101102

102103
Object.setPrototypeOf(Hmac.prototype, LazyTransform.prototype);
104+
Object.setPrototypeOf(Hmac, LazyTransform);
103105

104106
Hmac.prototype.update = Hash.prototype.update;
105107

lib/internal/crypto/sig.js

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function Sign(algorithm, options) {
3030
}
3131

3232
Object.setPrototypeOf(Sign.prototype, Writable.prototype);
33+
Object.setPrototypeOf(Sign, Writable);
3334

3435
Sign.prototype._write = function _write(chunk, encoding, callback) {
3536
this.update(chunk, encoding);
@@ -101,6 +102,7 @@ function Verify(algorithm, options) {
101102
}
102103

103104
Object.setPrototypeOf(Verify.prototype, Writable.prototype);
105+
Object.setPrototypeOf(Verify, Writable);
104106

105107
Verify.prototype._write = Sign.prototype._write;
106108
Verify.prototype.update = Sign.prototype.update;

lib/internal/fs/streams.js

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function ReadStream(path, options) {
119119
});
120120
}
121121
Object.setPrototypeOf(ReadStream.prototype, Readable.prototype);
122+
Object.setPrototypeOf(ReadStream, Readable);
122123

123124
ReadStream.prototype.open = function() {
124125
fs.open(this.path, this.flags, this.mode, (er, fd) => {
@@ -273,6 +274,7 @@ function WriteStream(path, options) {
273274
this.open();
274275
}
275276
Object.setPrototypeOf(WriteStream.prototype, Writable.prototype);
277+
Object.setPrototypeOf(WriteStream, Writable);
276278

277279
WriteStream.prototype._final = function(callback) {
278280
if (this.autoClose) {

lib/internal/fs/sync_write_stream.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function SyncWriteStream(fd, options) {
1616
}
1717

1818
Object.setPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
19+
Object.setPrototypeOf(SyncWriteStream, Writable);
1920

2021
SyncWriteStream.prototype._write = function(chunk, encoding, cb) {
2122
writeSync(this.fd, chunk, 0, chunk.length);

lib/internal/fs/watchers.js

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function StatWatcher(bigint) {
3636
this[kUseBigint] = bigint;
3737
}
3838
Object.setPrototypeOf(StatWatcher.prototype, EventEmitter.prototype);
39+
Object.setPrototypeOf(StatWatcher, EventEmitter);
3940

4041
function onchange(newStatus, stats) {
4142
const self = this[owner_symbol];
@@ -132,6 +133,7 @@ function FSWatcher() {
132133
};
133134
}
134135
Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype);
136+
Object.setPrototypeOf(FSWatcher, EventEmitter);
135137

136138

137139
// FIXME(joyeecheung): this method is not documented.

lib/internal/streams/legacy.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function Stream() {
66
EE.call(this);
77
}
88
Object.setPrototypeOf(Stream.prototype, EE.prototype);
9+
Object.setPrototypeOf(Stream, EE);
910

1011
Stream.prototype.pipe = function(dest, options) {
1112
var source = this;

lib/net.js

+1
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ function Server(options, connectionListener) {
11461146
this.pauseOnConnect = !!options.pauseOnConnect;
11471147
}
11481148
Object.setPrototypeOf(Server.prototype, EventEmitter.prototype);
1149+
Object.setPrototypeOf(Server, EventEmitter);
11491150

11501151

11511152
function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }

lib/perf_hooks.js

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class PerformanceNodeTiming {
209209
}
210210
Object.setPrototypeOf(
211211
PerformanceNodeTiming.prototype, PerformanceEntry.prototype);
212+
Object.setPrototypeOf(PerformanceNodeTiming, PerformanceEntry);
212213

213214
const nodeTiming = new PerformanceNodeTiming();
214215

lib/readline.js

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ function Interface(input, output, completer, terminal) {
246246
}
247247

248248
Object.setPrototypeOf(Interface.prototype, EventEmitter.prototype);
249+
Object.setPrototypeOf(Interface, EventEmitter);
249250

250251
Object.defineProperty(Interface.prototype, 'columns', {
251252
configurable: true,

lib/repl.js

+4
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ function REPLServer(prompt,
753753
self.displayPrompt();
754754
}
755755
Object.setPrototypeOf(REPLServer.prototype, Interface.prototype);
756+
Object.setPrototypeOf(REPLServer, Interface);
757+
756758
exports.REPLServer = REPLServer;
757759

758760
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
@@ -923,6 +925,7 @@ function ArrayStream() {
923925
};
924926
}
925927
Object.setPrototypeOf(ArrayStream.prototype, Stream.prototype);
928+
Object.setPrototypeOf(ArrayStream, Stream);
926929
ArrayStream.prototype.readable = true;
927930
ArrayStream.prototype.writable = true;
928931
ArrayStream.prototype.resume = function() {};
@@ -1514,4 +1517,5 @@ function Recoverable(err) {
15141517
this.err = err;
15151518
}
15161519
Object.setPrototypeOf(Recoverable.prototype, SyntaxError.prototype);
1520+
Object.setPrototypeOf(Recoverable, SyntaxError);
15171521
exports.Recoverable = Recoverable;

lib/zlib.js

+8
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ function Zlib(opts, mode) {
318318
this.once('end', this.close);
319319
}
320320
Object.setPrototypeOf(Zlib.prototype, Transform.prototype);
321+
Object.setPrototypeOf(Zlib, Transform);
321322

322323
Object.defineProperty(Zlib.prototype, '_closed', {
323324
configurable: true,
@@ -648,27 +649,31 @@ function Deflate(opts) {
648649
Zlib.call(this, opts, DEFLATE);
649650
}
650651
Object.setPrototypeOf(Deflate.prototype, Zlib.prototype);
652+
Object.setPrototypeOf(Deflate, Zlib);
651653

652654
function Inflate(opts) {
653655
if (!(this instanceof Inflate))
654656
return new Inflate(opts);
655657
Zlib.call(this, opts, INFLATE);
656658
}
657659
Object.setPrototypeOf(Inflate.prototype, Zlib.prototype);
660+
Object.setPrototypeOf(Inflate, Zlib);
658661

659662
function Gzip(opts) {
660663
if (!(this instanceof Gzip))
661664
return new Gzip(opts);
662665
Zlib.call(this, opts, GZIP);
663666
}
664667
Object.setPrototypeOf(Gzip.prototype, Zlib.prototype);
668+
Object.setPrototypeOf(Gzip, Zlib);
665669

666670
function Gunzip(opts) {
667671
if (!(this instanceof Gunzip))
668672
return new Gunzip(opts);
669673
Zlib.call(this, opts, GUNZIP);
670674
}
671675
Object.setPrototypeOf(Gunzip.prototype, Zlib.prototype);
676+
Object.setPrototypeOf(Gunzip, Zlib);
672677

673678
function DeflateRaw(opts) {
674679
if (opts && opts.windowBits === 8) opts.windowBits = 9;
@@ -677,20 +682,23 @@ function DeflateRaw(opts) {
677682
Zlib.call(this, opts, DEFLATERAW);
678683
}
679684
Object.setPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
685+
Object.setPrototypeOf(DeflateRaw, Zlib);
680686

681687
function InflateRaw(opts) {
682688
if (!(this instanceof InflateRaw))
683689
return new InflateRaw(opts);
684690
Zlib.call(this, opts, INFLATERAW);
685691
}
686692
Object.setPrototypeOf(InflateRaw.prototype, Zlib.prototype);
693+
Object.setPrototypeOf(InflateRaw, Zlib);
687694

688695
function Unzip(opts) {
689696
if (!(this instanceof Unzip))
690697
return new Unzip(opts);
691698
Zlib.call(this, opts, UNZIP);
692699
}
693700
Object.setPrototypeOf(Unzip.prototype, Zlib.prototype);
701+
Object.setPrototypeOf(Unzip, Zlib);
694702

695703
function createConvenienceMethod(ctor, sync) {
696704
if (sync) {

0 commit comments

Comments
 (0)