Skip to content

Commit

Permalink
lib: use ES6 class inheritance style
Browse files Browse the repository at this point in the history
PR-URL: nodejs#24755
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
BridgeAR authored and refack committed Jan 10, 2019
1 parent 2f443fd commit 0feffff
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function Agent(options) {
});
}
Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Agent, EventEmitter);

Agent.defaultMaxSockets = Infinity;

Expand Down
1 change: 1 addition & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ function ClientRequest(input, options, cb) {
this._deferToConnect(null, null, () => this._flush());
}
Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
Object.setPrototypeOf(ClientRequest, OutgoingMessage);

ClientRequest.prototype._finish = function _finish() {
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
Expand Down
1 change: 1 addition & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function IncomingMessage(socket) {
this._dumped = false;
}
Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype);
Object.setPrototypeOf(IncomingMessage, Stream.Readable);

IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
if (callback)
Expand Down
1 change: 1 addition & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function OutgoingMessage() {
this._onPendingData = noopPendingOutput;
}
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
Object.setPrototypeOf(OutgoingMessage, Stream);


Object.defineProperty(OutgoingMessage.prototype, '_headers', {
Expand Down
1 change: 1 addition & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function ServerResponse(req) {
}
}
Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
Object.setPrototypeOf(ServerResponse, OutgoingMessage);

ServerResponse.prototype._finish = function _finish() {
DTRACE_HTTP_SERVER_RESPONSE(this.connection);
Expand Down
1 change: 1 addition & 0 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Readable = require('_stream_readable');
const Writable = require('_stream_writable');

Object.setPrototypeOf(Duplex.prototype, Readable.prototype);
Object.setPrototypeOf(Duplex, Readable);

{
// Allow the keys array to be GC'ed.
Expand Down
1 change: 1 addition & 0 deletions lib/_stream_passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = PassThrough;

const Transform = require('_stream_transform');
Object.setPrototypeOf(PassThrough.prototype, Transform.prototype);
Object.setPrototypeOf(PassThrough, Transform);

function PassThrough(options) {
if (!(this instanceof PassThrough))
Expand Down
1 change: 1 addition & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let StringDecoder;
let createReadableStreamAsyncIterator;

Object.setPrototypeOf(Readable.prototype, Stream.prototype);
Object.setPrototypeOf(Readable, Stream);

const { errorOrDestroy } = destroyImpl;
const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
Expand Down
1 change: 1 addition & 0 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const {
} = require('internal/errors').codes;
const Duplex = require('_stream_duplex');
Object.setPrototypeOf(Transform.prototype, Duplex.prototype);
Object.setPrototypeOf(Transform, Duplex);


function afterTransform(er, data) {
Expand Down
1 change: 1 addition & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const {
const { errorOrDestroy } = destroyImpl;

Object.setPrototypeOf(Writable.prototype, Stream.prototype);
Object.setPrototypeOf(Writable, Stream);

function nop() {}

Expand Down
1 change: 1 addition & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function Socket(type, listener) {
};
}
Object.setPrototypeOf(Socket.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Socket, EventEmitter);


function createSocket(type, listener) {
Expand Down
1 change: 1 addition & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function Agent(options) {
};
}
Object.setPrototypeOf(Agent.prototype, HttpAgent.prototype);
Object.setPrototypeOf(Agent, HttpAgent);
Agent.prototype.createConnection = createConnection;

Agent.prototype.getName = function getName(options) {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ function ChildProcess() {
};
}
Object.setPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
Object.setPrototypeOf(ChildProcess, EventEmitter);


function flushStdio(subprocess) {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/cluster/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function Worker(options) {
}

Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Worker, EventEmitter);

Worker.prototype.kill = function() {
this.destroy.apply(this, arguments);
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/crypto/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function Cipher(cipher, password, options) {
}

Object.setPrototypeOf(Cipher.prototype, LazyTransform.prototype);
Object.setPrototypeOf(Cipher, LazyTransform);

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

Object.setPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
Object.setPrototypeOf(Cipheriv, LazyTransform);
addCipherPrototypeFunctions(Cipheriv);
legacyNativeHandle(Cipheriv);

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

Object.setPrototypeOf(Decipher.prototype, LazyTransform.prototype);
Object.setPrototypeOf(Decipher, LazyTransform);
addCipherPrototypeFunctions(Decipher);
legacyNativeHandle(Decipher);

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

Object.setPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
Object.setPrototypeOf(Decipheriv, LazyTransform);
addCipherPrototypeFunctions(Decipheriv);
legacyNativeHandle(Decipheriv);

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/crypto/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function Hash(algorithm, options) {
}

Object.setPrototypeOf(Hash.prototype, LazyTransform.prototype);
Object.setPrototypeOf(Hash, LazyTransform);

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

Object.setPrototypeOf(Hmac.prototype, LazyTransform.prototype);
Object.setPrototypeOf(Hmac, LazyTransform);

Hmac.prototype.update = Hash.prototype.update;

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/crypto/sig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function Sign(algorithm, options) {
}

Object.setPrototypeOf(Sign.prototype, Writable.prototype);
Object.setPrototypeOf(Sign, Writable);

Sign.prototype._write = function _write(chunk, encoding, callback) {
this.update(chunk, encoding);
Expand Down Expand Up @@ -101,6 +102,7 @@ function Verify(algorithm, options) {
}

Object.setPrototypeOf(Verify.prototype, Writable.prototype);
Object.setPrototypeOf(Verify, Writable);

Verify.prototype._write = Sign.prototype._write;
Verify.prototype.update = Sign.prototype.update;
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function ReadStream(path, options) {
});
}
Object.setPrototypeOf(ReadStream.prototype, Readable.prototype);
Object.setPrototypeOf(ReadStream, Readable);

ReadStream.prototype.open = function() {
fs.open(this.path, this.flags, this.mode, (er, fd) => {
Expand Down Expand Up @@ -273,6 +274,7 @@ function WriteStream(path, options) {
this.open();
}
Object.setPrototypeOf(WriteStream.prototype, Writable.prototype);
Object.setPrototypeOf(WriteStream, Writable);

WriteStream.prototype._final = function(callback) {
if (this.autoClose) {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/fs/sync_write_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function SyncWriteStream(fd, options) {
}

Object.setPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
Object.setPrototypeOf(SyncWriteStream, Writable);

SyncWriteStream.prototype._write = function(chunk, encoding, cb) {
writeSync(this.fd, chunk, 0, chunk.length);
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function StatWatcher(bigint) {
this[kUseBigint] = bigint;
}
Object.setPrototypeOf(StatWatcher.prototype, EventEmitter.prototype);
Object.setPrototypeOf(StatWatcher, EventEmitter);

function onchange(newStatus, stats) {
const self = this[owner_symbol];
Expand Down Expand Up @@ -132,6 +133,7 @@ function FSWatcher() {
};
}
Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype);
Object.setPrototypeOf(FSWatcher, EventEmitter);


// FIXME(joyeecheung): this method is not documented.
Expand Down
1 change: 1 addition & 0 deletions lib/internal/streams/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function Stream() {
EE.call(this);
}
Object.setPrototypeOf(Stream.prototype, EE.prototype);
Object.setPrototypeOf(Stream, EE);

Stream.prototype.pipe = function(dest, options) {
var source = this;
Expand Down
1 change: 1 addition & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ function Server(options, connectionListener) {
this.pauseOnConnect = !!options.pauseOnConnect;
}
Object.setPrototypeOf(Server.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Server, EventEmitter);


function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }
Expand Down
1 change: 1 addition & 0 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class PerformanceNodeTiming {
}
Object.setPrototypeOf(
PerformanceNodeTiming.prototype, PerformanceEntry.prototype);
Object.setPrototypeOf(PerformanceNodeTiming, PerformanceEntry);

const nodeTiming = new PerformanceNodeTiming();

Expand Down
1 change: 1 addition & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ function Interface(input, output, completer, terminal) {
}

Object.setPrototypeOf(Interface.prototype, EventEmitter.prototype);
Object.setPrototypeOf(Interface, EventEmitter);

Object.defineProperty(Interface.prototype, 'columns', {
configurable: true,
Expand Down
4 changes: 4 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ function REPLServer(prompt,
self.displayPrompt();
}
Object.setPrototypeOf(REPLServer.prototype, Interface.prototype);
Object.setPrototypeOf(REPLServer, Interface);

exports.REPLServer = REPLServer;

exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
Expand Down Expand Up @@ -923,6 +925,7 @@ function ArrayStream() {
};
}
Object.setPrototypeOf(ArrayStream.prototype, Stream.prototype);
Object.setPrototypeOf(ArrayStream, Stream);
ArrayStream.prototype.readable = true;
ArrayStream.prototype.writable = true;
ArrayStream.prototype.resume = function() {};
Expand Down Expand Up @@ -1514,4 +1517,5 @@ function Recoverable(err) {
this.err = err;
}
Object.setPrototypeOf(Recoverable.prototype, SyntaxError.prototype);
Object.setPrototypeOf(Recoverable, SyntaxError);
exports.Recoverable = Recoverable;
8 changes: 8 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ function Zlib(opts, mode) {
this.once('end', this.close);
}
Object.setPrototypeOf(Zlib.prototype, Transform.prototype);
Object.setPrototypeOf(Zlib, Transform);

Object.defineProperty(Zlib.prototype, '_closed', {
configurable: true,
Expand Down Expand Up @@ -648,27 +649,31 @@ function Deflate(opts) {
Zlib.call(this, opts, DEFLATE);
}
Object.setPrototypeOf(Deflate.prototype, Zlib.prototype);
Object.setPrototypeOf(Deflate, Zlib);

function Inflate(opts) {
if (!(this instanceof Inflate))
return new Inflate(opts);
Zlib.call(this, opts, INFLATE);
}
Object.setPrototypeOf(Inflate.prototype, Zlib.prototype);
Object.setPrototypeOf(Inflate, Zlib);

function Gzip(opts) {
if (!(this instanceof Gzip))
return new Gzip(opts);
Zlib.call(this, opts, GZIP);
}
Object.setPrototypeOf(Gzip.prototype, Zlib.prototype);
Object.setPrototypeOf(Gzip, Zlib);

function Gunzip(opts) {
if (!(this instanceof Gunzip))
return new Gunzip(opts);
Zlib.call(this, opts, GUNZIP);
}
Object.setPrototypeOf(Gunzip.prototype, Zlib.prototype);
Object.setPrototypeOf(Gunzip, Zlib);

function DeflateRaw(opts) {
if (opts && opts.windowBits === 8) opts.windowBits = 9;
Expand All @@ -677,20 +682,23 @@ function DeflateRaw(opts) {
Zlib.call(this, opts, DEFLATERAW);
}
Object.setPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
Object.setPrototypeOf(DeflateRaw, Zlib);

function InflateRaw(opts) {
if (!(this instanceof InflateRaw))
return new InflateRaw(opts);
Zlib.call(this, opts, INFLATERAW);
}
Object.setPrototypeOf(InflateRaw.prototype, Zlib.prototype);
Object.setPrototypeOf(InflateRaw, Zlib);

function Unzip(opts) {
if (!(this instanceof Unzip))
return new Unzip(opts);
Zlib.call(this, opts, UNZIP);
}
Object.setPrototypeOf(Unzip.prototype, Zlib.prototype);
Object.setPrototypeOf(Unzip, Zlib);

function createConvenienceMethod(ctor, sync) {
if (sync) {
Expand Down

0 comments on commit 0feffff

Please sign in to comment.