mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
lib: use ES6 class inheritance style
PR-URL: https://github.com/nodejs/node/pull/24755 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
dcc82b37b6
commit
59257543c3
@ -106,6 +106,7 @@ function Agent(options) {
|
||||
});
|
||||
}
|
||||
Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype);
|
||||
Object.setPrototypeOf(Agent, EventEmitter);
|
||||
|
||||
Agent.defaultMaxSockets = Infinity;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -107,6 +107,7 @@ function OutgoingMessage() {
|
||||
this._onPendingData = noopPendingOutput;
|
||||
}
|
||||
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
|
||||
Object.setPrototypeOf(OutgoingMessage, Stream);
|
||||
|
||||
|
||||
Object.defineProperty(OutgoingMessage.prototype, '_headers', {
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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))
|
||||
|
@ -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'];
|
||||
|
@ -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) {
|
||||
|
@ -47,6 +47,7 @@ const {
|
||||
const { errorOrDestroy } = destroyImpl;
|
||||
|
||||
Object.setPrototypeOf(Writable.prototype, Stream.prototype);
|
||||
Object.setPrototypeOf(Writable, Stream);
|
||||
|
||||
function nop() {}
|
||||
|
||||
|
@ -109,6 +109,7 @@ function Socket(type, listener) {
|
||||
};
|
||||
}
|
||||
Object.setPrototypeOf(Socket.prototype, EventEmitter.prototype);
|
||||
Object.setPrototypeOf(Socket, EventEmitter);
|
||||
|
||||
|
||||
function createSocket(type, listener) {
|
||||
|
@ -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) {
|
||||
|
@ -266,6 +266,7 @@ function ChildProcess() {
|
||||
};
|
||||
}
|
||||
Object.setPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
|
||||
Object.setPrototypeOf(ChildProcess, EventEmitter);
|
||||
|
||||
|
||||
function flushStdio(subprocess) {
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
@ -254,6 +255,7 @@ function addCipherPrototypeFunctions(constructor) {
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
|
||||
Object.setPrototypeOf(Cipheriv, LazyTransform);
|
||||
addCipherPrototypeFunctions(Cipheriv);
|
||||
legacyNativeHandle(Cipheriv);
|
||||
|
||||
@ -265,6 +267,7 @@ function Decipher(cipher, password, options) {
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(Decipher.prototype, LazyTransform.prototype);
|
||||
Object.setPrototypeOf(Decipher, LazyTransform);
|
||||
addCipherPrototypeFunctions(Decipher);
|
||||
legacyNativeHandle(Decipher);
|
||||
|
||||
@ -277,6 +280,7 @@ function Decipheriv(cipher, key, iv, options) {
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
|
||||
Object.setPrototypeOf(Decipheriv, LazyTransform);
|
||||
addCipherPrototypeFunctions(Decipheriv);
|
||||
legacyNativeHandle(Decipheriv);
|
||||
|
||||
|
@ -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);
|
||||
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
@ -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;
|
||||
|
@ -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) => {
|
||||
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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];
|
||||
@ -132,6 +133,7 @@ function FSWatcher() {
|
||||
};
|
||||
}
|
||||
Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype);
|
||||
Object.setPrototypeOf(FSWatcher, EventEmitter);
|
||||
|
||||
|
||||
// FIXME(joyeecheung): this method is not documented.
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
|
@ -209,6 +209,7 @@ class PerformanceNodeTiming {
|
||||
}
|
||||
Object.setPrototypeOf(
|
||||
PerformanceNodeTiming.prototype, PerformanceEntry.prototype);
|
||||
Object.setPrototypeOf(PerformanceNodeTiming, PerformanceEntry);
|
||||
|
||||
const nodeTiming = new PerformanceNodeTiming();
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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');
|
||||
@ -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() {};
|
||||
@ -1514,4 +1517,5 @@ function Recoverable(err) {
|
||||
this.err = err;
|
||||
}
|
||||
Object.setPrototypeOf(Recoverable.prototype, SyntaxError.prototype);
|
||||
Object.setPrototypeOf(Recoverable, SyntaxError);
|
||||
exports.Recoverable = Recoverable;
|
||||
|
@ -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,
|
||||
@ -648,6 +649,7 @@ 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))
|
||||
@ -655,6 +657,7 @@ function Inflate(opts) {
|
||||
Zlib.call(this, opts, INFLATE);
|
||||
}
|
||||
Object.setPrototypeOf(Inflate.prototype, Zlib.prototype);
|
||||
Object.setPrototypeOf(Inflate, Zlib);
|
||||
|
||||
function Gzip(opts) {
|
||||
if (!(this instanceof Gzip))
|
||||
@ -662,6 +665,7 @@ function Gzip(opts) {
|
||||
Zlib.call(this, opts, GZIP);
|
||||
}
|
||||
Object.setPrototypeOf(Gzip.prototype, Zlib.prototype);
|
||||
Object.setPrototypeOf(Gzip, Zlib);
|
||||
|
||||
function Gunzip(opts) {
|
||||
if (!(this instanceof Gunzip))
|
||||
@ -669,6 +673,7 @@ function 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;
|
||||
@ -677,6 +682,7 @@ 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))
|
||||
@ -684,6 +690,7 @@ function InflateRaw(opts) {
|
||||
Zlib.call(this, opts, INFLATERAW);
|
||||
}
|
||||
Object.setPrototypeOf(InflateRaw.prototype, Zlib.prototype);
|
||||
Object.setPrototypeOf(InflateRaw, Zlib);
|
||||
|
||||
function Unzip(opts) {
|
||||
if (!(this instanceof Unzip))
|
||||
@ -691,6 +698,7 @@ function Unzip(opts) {
|
||||
Zlib.call(this, opts, UNZIP);
|
||||
}
|
||||
Object.setPrototypeOf(Unzip.prototype, Zlib.prototype);
|
||||
Object.setPrototypeOf(Unzip, Zlib);
|
||||
|
||||
function createConvenienceMethod(ctor, sync) {
|
||||
if (sync) {
|
||||
|
Loading…
Reference in New Issue
Block a user