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: https://github.com/nodejs/node/pull/24755 Refs: https://github.com/nodejs/node/issues/24395 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
6ccc80c82a
commit
dcc82b37b6
@ -105,8 +105,7 @@ function Agent(options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype);
|
||||||
util.inherits(Agent, EventEmitter);
|
|
||||||
|
|
||||||
Agent.defaultMaxSockets = Infinity;
|
Agent.defaultMaxSockets = Infinity;
|
||||||
|
|
||||||
|
@ -279,9 +279,7 @@ function ClientRequest(input, options, cb) {
|
|||||||
|
|
||||||
this._deferToConnect(null, null, () => this._flush());
|
this._deferToConnect(null, null, () => this._flush());
|
||||||
}
|
}
|
||||||
|
Object.setPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
|
||||||
util.inherits(ClientRequest, OutgoingMessage);
|
|
||||||
|
|
||||||
|
|
||||||
ClientRequest.prototype._finish = function _finish() {
|
ClientRequest.prototype._finish = function _finish() {
|
||||||
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
|
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
|
|
||||||
function readStart(socket) {
|
function readStart(socket) {
|
||||||
@ -72,8 +71,7 @@ function IncomingMessage(socket) {
|
|||||||
// read by the user, so there's no point continuing to handle it.
|
// read by the user, so there's no point continuing to handle it.
|
||||||
this._dumped = false;
|
this._dumped = false;
|
||||||
}
|
}
|
||||||
util.inherits(IncomingMessage, Stream.Readable);
|
Object.setPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype);
|
||||||
|
|
||||||
|
|
||||||
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
|
IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
|
||||||
if (callback)
|
if (callback)
|
||||||
|
@ -106,7 +106,7 @@ function OutgoingMessage() {
|
|||||||
|
|
||||||
this._onPendingData = noopPendingOutput;
|
this._onPendingData = noopPendingOutput;
|
||||||
}
|
}
|
||||||
util.inherits(OutgoingMessage, Stream);
|
Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype);
|
||||||
|
|
||||||
|
|
||||||
Object.defineProperty(OutgoingMessage.prototype, '_headers', {
|
Object.defineProperty(OutgoingMessage.prototype, '_headers', {
|
||||||
|
@ -137,7 +137,7 @@ function ServerResponse(req) {
|
|||||||
this.shouldKeepAlive = false;
|
this.shouldKeepAlive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
util.inherits(ServerResponse, OutgoingMessage);
|
Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
|
||||||
|
|
||||||
ServerResponse.prototype._finish = function _finish() {
|
ServerResponse.prototype._finish = function _finish() {
|
||||||
DTRACE_HTTP_SERVER_RESPONSE(this.connection);
|
DTRACE_HTTP_SERVER_RESPONSE(this.connection);
|
||||||
|
@ -28,11 +28,10 @@
|
|||||||
|
|
||||||
module.exports = Duplex;
|
module.exports = Duplex;
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
const Readable = require('_stream_readable');
|
const Readable = require('_stream_readable');
|
||||||
const Writable = require('_stream_writable');
|
const Writable = require('_stream_writable');
|
||||||
|
|
||||||
util.inherits(Duplex, Readable);
|
Object.setPrototypeOf(Duplex.prototype, Readable.prototype);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Allow the keys array to be GC'ed.
|
// Allow the keys array to be GC'ed.
|
||||||
|
@ -28,8 +28,7 @@
|
|||||||
module.exports = PassThrough;
|
module.exports = PassThrough;
|
||||||
|
|
||||||
const Transform = require('_stream_transform');
|
const Transform = require('_stream_transform');
|
||||||
const util = require('util');
|
Object.setPrototypeOf(PassThrough.prototype, Transform.prototype);
|
||||||
util.inherits(PassThrough, Transform);
|
|
||||||
|
|
||||||
function PassThrough(options) {
|
function PassThrough(options) {
|
||||||
if (!(this instanceof PassThrough))
|
if (!(this instanceof PassThrough))
|
||||||
|
@ -44,7 +44,7 @@ const { emitExperimentalWarning } = require('internal/util');
|
|||||||
let StringDecoder;
|
let StringDecoder;
|
||||||
let createReadableStreamAsyncIterator;
|
let createReadableStreamAsyncIterator;
|
||||||
|
|
||||||
util.inherits(Readable, Stream);
|
Object.setPrototypeOf(Readable.prototype, Stream.prototype);
|
||||||
|
|
||||||
const { errorOrDestroy } = destroyImpl;
|
const { errorOrDestroy } = destroyImpl;
|
||||||
const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
||||||
|
@ -71,8 +71,7 @@ const {
|
|||||||
ERR_TRANSFORM_WITH_LENGTH_0
|
ERR_TRANSFORM_WITH_LENGTH_0
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const Duplex = require('_stream_duplex');
|
const Duplex = require('_stream_duplex');
|
||||||
const util = require('util');
|
Object.setPrototypeOf(Transform.prototype, Duplex.prototype);
|
||||||
util.inherits(Transform, Duplex);
|
|
||||||
|
|
||||||
|
|
||||||
function afterTransform(er, data) {
|
function afterTransform(er, data) {
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
module.exports = Writable;
|
module.exports = Writable;
|
||||||
Writable.WritableState = WritableState;
|
Writable.WritableState = WritableState;
|
||||||
|
|
||||||
const util = require('util');
|
|
||||||
const internalUtil = require('internal/util');
|
const internalUtil = require('internal/util');
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
@ -47,7 +46,7 @@ const {
|
|||||||
|
|
||||||
const { errorOrDestroy } = destroyImpl;
|
const { errorOrDestroy } = destroyImpl;
|
||||||
|
|
||||||
util.inherits(Writable, Stream);
|
Object.setPrototypeOf(Writable.prototype, Stream.prototype);
|
||||||
|
|
||||||
function nop() {}
|
function nop() {}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ function Socket(type, listener) {
|
|||||||
sendBufferSize
|
sendBufferSize
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
util.inherits(Socket, EventEmitter);
|
Object.setPrototypeOf(Socket.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
|
|
||||||
function createSocket(type, listener) {
|
function createSocket(type, listener) {
|
||||||
|
@ -149,7 +149,7 @@ function Agent(options) {
|
|||||||
list: []
|
list: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
inherits(Agent, HttpAgent);
|
Object.setPrototypeOf(Agent.prototype, HttpAgent.prototype);
|
||||||
Agent.prototype.createConnection = createConnection;
|
Agent.prototype.createConnection = createConnection;
|
||||||
|
|
||||||
Agent.prototype.getName = function getName(options) {
|
Agent.prototype.getName = function getName(options) {
|
||||||
|
@ -265,7 +265,7 @@ function ChildProcess() {
|
|||||||
maybeClose(this);
|
maybeClose(this);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
util.inherits(ChildProcess, EventEmitter);
|
Object.setPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
|
|
||||||
function flushStdio(subprocess) {
|
function flushStdio(subprocess) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
module.exports = Worker;
|
module.exports = Worker;
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ function Worker(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(Worker, EventEmitter);
|
Object.setPrototypeOf(Worker.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
Worker.prototype.kill = function() {
|
Worker.prototype.kill = function() {
|
||||||
this.destroy.apply(this, arguments);
|
this.destroy.apply(this, arguments);
|
||||||
|
@ -32,7 +32,6 @@ const {
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const LazyTransform = require('internal/streams/lazy_transform');
|
const LazyTransform = require('internal/streams/lazy_transform');
|
||||||
|
|
||||||
const { inherits } = require('util');
|
|
||||||
const { deprecate, normalizeEncoding } = require('internal/util');
|
const { deprecate, normalizeEncoding } = require('internal/util');
|
||||||
|
|
||||||
// Lazy loaded for startup performance.
|
// Lazy loaded for startup performance.
|
||||||
@ -124,7 +123,7 @@ function Cipher(cipher, password, options) {
|
|||||||
createCipher.call(this, cipher, password, options, true);
|
createCipher.call(this, cipher, password, options, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Cipher, LazyTransform);
|
Object.setPrototypeOf(Cipher.prototype, LazyTransform.prototype);
|
||||||
|
|
||||||
Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
|
Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
|
||||||
this.push(this[kHandle].update(chunk, encoding));
|
this.push(this[kHandle].update(chunk, encoding));
|
||||||
@ -254,7 +253,7 @@ function addCipherPrototypeFunctions(constructor) {
|
|||||||
constructor.prototype.setAAD = Cipher.prototype.setAAD;
|
constructor.prototype.setAAD = Cipher.prototype.setAAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Cipheriv, LazyTransform);
|
Object.setPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
|
||||||
addCipherPrototypeFunctions(Cipheriv);
|
addCipherPrototypeFunctions(Cipheriv);
|
||||||
legacyNativeHandle(Cipheriv);
|
legacyNativeHandle(Cipheriv);
|
||||||
|
|
||||||
@ -265,7 +264,7 @@ function Decipher(cipher, password, options) {
|
|||||||
createCipher.call(this, cipher, password, options, false);
|
createCipher.call(this, cipher, password, options, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Decipher, LazyTransform);
|
Object.setPrototypeOf(Decipher.prototype, LazyTransform.prototype);
|
||||||
addCipherPrototypeFunctions(Decipher);
|
addCipherPrototypeFunctions(Decipher);
|
||||||
legacyNativeHandle(Decipher);
|
legacyNativeHandle(Decipher);
|
||||||
|
|
||||||
@ -277,7 +276,7 @@ function Decipheriv(cipher, key, iv, options) {
|
|||||||
createCipherWithIV.call(this, cipher, key, options, false, iv);
|
createCipherWithIV.call(this, cipher, key, options, false, iv);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Decipheriv, LazyTransform);
|
Object.setPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
|
||||||
addCipherPrototypeFunctions(Decipheriv);
|
addCipherPrototypeFunctions(Decipheriv);
|
||||||
legacyNativeHandle(Decipheriv);
|
legacyNativeHandle(Decipheriv);
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ const {
|
|||||||
ERR_INVALID_ARG_TYPE
|
ERR_INVALID_ARG_TYPE
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const { validateString } = require('internal/validators');
|
const { validateString } = require('internal/validators');
|
||||||
const { inherits } = require('util');
|
|
||||||
const { normalizeEncoding } = require('internal/util');
|
const { normalizeEncoding } = require('internal/util');
|
||||||
const { isArrayBufferView } = require('internal/util/types');
|
const { isArrayBufferView } = require('internal/util/types');
|
||||||
const LazyTransform = require('internal/streams/lazy_transform');
|
const LazyTransform = require('internal/streams/lazy_transform');
|
||||||
@ -39,7 +38,7 @@ function Hash(algorithm, options) {
|
|||||||
LazyTransform.call(this, options);
|
LazyTransform.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Hash, LazyTransform);
|
Object.setPrototypeOf(Hash.prototype, LazyTransform.prototype);
|
||||||
|
|
||||||
Hash.prototype._transform = function _transform(chunk, encoding, callback) {
|
Hash.prototype._transform = function _transform(chunk, encoding, callback) {
|
||||||
this[kHandle].update(chunk, encoding);
|
this[kHandle].update(chunk, encoding);
|
||||||
@ -100,7 +99,7 @@ function Hmac(hmac, key, options) {
|
|||||||
LazyTransform.call(this, options);
|
LazyTransform.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Hmac, LazyTransform);
|
Object.setPrototypeOf(Hmac.prototype, LazyTransform.prototype);
|
||||||
|
|
||||||
Hmac.prototype.update = Hash.prototype.update;
|
Hmac.prototype.update = Hash.prototype.update;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ const {
|
|||||||
validateArrayBufferView,
|
validateArrayBufferView,
|
||||||
} = require('internal/crypto/util');
|
} = require('internal/crypto/util');
|
||||||
const { Writable } = require('stream');
|
const { Writable } = require('stream');
|
||||||
const { inherits } = require('util');
|
|
||||||
|
|
||||||
function Sign(algorithm, options) {
|
function Sign(algorithm, options) {
|
||||||
if (!(this instanceof Sign))
|
if (!(this instanceof Sign))
|
||||||
@ -30,7 +29,7 @@ function Sign(algorithm, options) {
|
|||||||
Writable.call(this, options);
|
Writable.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Sign, Writable);
|
Object.setPrototypeOf(Sign.prototype, Writable.prototype);
|
||||||
|
|
||||||
Sign.prototype._write = function _write(chunk, encoding, callback) {
|
Sign.prototype._write = function _write(chunk, encoding, callback) {
|
||||||
this.update(chunk, encoding);
|
this.update(chunk, encoding);
|
||||||
@ -101,7 +100,7 @@ function Verify(algorithm, options) {
|
|||||||
Writable.call(this, options);
|
Writable.call(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Verify, Writable);
|
Object.setPrototypeOf(Verify.prototype, Writable.prototype);
|
||||||
|
|
||||||
Verify.prototype._write = Sign.prototype._write;
|
Verify.prototype._write = Sign.prototype._write;
|
||||||
Verify.prototype.update = Sign.prototype.update;
|
Verify.prototype.update = Sign.prototype.update;
|
||||||
|
@ -17,7 +17,6 @@ const {
|
|||||||
} = require('internal/fs/utils');
|
} = require('internal/fs/utils');
|
||||||
const { Readable, Writable } = require('stream');
|
const { Readable, Writable } = require('stream');
|
||||||
const { toPathIfFileURL } = require('internal/url');
|
const { toPathIfFileURL } = require('internal/url');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
const kMinPoolSpace = 128;
|
const kMinPoolSpace = 128;
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ function ReadStream(path, options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
util.inherits(ReadStream, Readable);
|
Object.setPrototypeOf(ReadStream.prototype, Readable.prototype);
|
||||||
|
|
||||||
ReadStream.prototype.open = function() {
|
ReadStream.prototype.open = function() {
|
||||||
fs.open(this.path, this.flags, this.mode, (er, fd) => {
|
fs.open(this.path, this.flags, this.mode, (er, fd) => {
|
||||||
@ -273,7 +272,7 @@ function WriteStream(path, options) {
|
|||||||
if (typeof this.fd !== 'number')
|
if (typeof this.fd !== 'number')
|
||||||
this.open();
|
this.open();
|
||||||
}
|
}
|
||||||
util.inherits(WriteStream, Writable);
|
Object.setPrototypeOf(WriteStream.prototype, Writable.prototype);
|
||||||
|
|
||||||
WriteStream.prototype._final = function(callback) {
|
WriteStream.prototype._final = function(callback) {
|
||||||
if (this.autoClose) {
|
if (this.autoClose) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Writable } = require('stream');
|
const { Writable } = require('stream');
|
||||||
const { inherits } = require('util');
|
|
||||||
const { closeSync, writeSync } = require('fs');
|
const { closeSync, writeSync } = require('fs');
|
||||||
|
|
||||||
function SyncWriteStream(fd, options) {
|
function SyncWriteStream(fd, options) {
|
||||||
@ -16,7 +15,7 @@ function SyncWriteStream(fd, options) {
|
|||||||
this.on('end', () => this._destroy());
|
this.on('end', () => this._destroy());
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(SyncWriteStream, Writable);
|
Object.setPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
|
||||||
|
|
||||||
SyncWriteStream.prototype._write = function(chunk, encoding, cb) {
|
SyncWriteStream.prototype._write = function(chunk, encoding, cb) {
|
||||||
writeSync(this.fd, chunk, 0, chunk.length);
|
writeSync(this.fd, chunk, 0, chunk.length);
|
||||||
|
@ -19,7 +19,6 @@ const {
|
|||||||
const { toNamespacedPath } = require('path');
|
const { toNamespacedPath } = require('path');
|
||||||
const { validateUint32 } = require('internal/validators');
|
const { validateUint32 } = require('internal/validators');
|
||||||
const { toPathIfFileURL } = require('internal/url');
|
const { toPathIfFileURL } = require('internal/url');
|
||||||
const util = require('util');
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const kOldStatus = Symbol('kOldStatus');
|
const kOldStatus = Symbol('kOldStatus');
|
||||||
@ -36,7 +35,7 @@ function StatWatcher(bigint) {
|
|||||||
this[kOldStatus] = -1;
|
this[kOldStatus] = -1;
|
||||||
this[kUseBigint] = bigint;
|
this[kUseBigint] = bigint;
|
||||||
}
|
}
|
||||||
util.inherits(StatWatcher, EventEmitter);
|
Object.setPrototypeOf(StatWatcher.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
function onchange(newStatus, stats) {
|
function onchange(newStatus, stats) {
|
||||||
const self = this[owner_symbol];
|
const self = this[owner_symbol];
|
||||||
@ -132,7 +131,7 @@ function FSWatcher() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
util.inherits(FSWatcher, EventEmitter);
|
Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
|
|
||||||
// FIXME(joyeecheung): this method is not documented.
|
// FIXME(joyeecheung): this method is not documented.
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const EE = require('events');
|
const EE = require('events');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
function Stream() {
|
function Stream() {
|
||||||
EE.call(this);
|
EE.call(this);
|
||||||
}
|
}
|
||||||
util.inherits(Stream, EE);
|
Object.setPrototypeOf(Stream.prototype, EE.prototype);
|
||||||
|
|
||||||
Stream.prototype.pipe = function(dest, options) {
|
Stream.prototype.pipe = function(dest, options) {
|
||||||
var source = this;
|
var source = this;
|
||||||
|
@ -1145,7 +1145,7 @@ function Server(options, connectionListener) {
|
|||||||
this.allowHalfOpen = options.allowHalfOpen || false;
|
this.allowHalfOpen = options.allowHalfOpen || false;
|
||||||
this.pauseOnConnect = !!options.pauseOnConnect;
|
this.pauseOnConnect = !!options.pauseOnConnect;
|
||||||
}
|
}
|
||||||
util.inherits(Server, EventEmitter);
|
Object.setPrototypeOf(Server.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
|
|
||||||
function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }
|
function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }
|
||||||
|
@ -33,7 +33,6 @@ const {
|
|||||||
const { AsyncResource } = require('async_hooks');
|
const { AsyncResource } = require('async_hooks');
|
||||||
const L = require('internal/linkedlist');
|
const L = require('internal/linkedlist');
|
||||||
const kInspect = require('internal/util').customInspectSymbol;
|
const kInspect = require('internal/util').customInspectSymbol;
|
||||||
const { inherits } = require('util');
|
|
||||||
|
|
||||||
const kCallback = Symbol('callback');
|
const kCallback = Symbol('callback');
|
||||||
const kTypes = Symbol('types');
|
const kTypes = Symbol('types');
|
||||||
@ -208,10 +207,8 @@ class PerformanceNodeTiming {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Use this instead of Extends because we want PerformanceEntry in the
|
Object.setPrototypeOf(
|
||||||
// prototype chain but we do not want to use the PerformanceEntry
|
PerformanceNodeTiming.prototype, PerformanceEntry.prototype);
|
||||||
// constructor for this.
|
|
||||||
inherits(PerformanceNodeTiming, PerformanceEntry);
|
|
||||||
|
|
||||||
const nodeTiming = new PerformanceNodeTiming();
|
const nodeTiming = new PerformanceNodeTiming();
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ const {
|
|||||||
ERR_INVALID_CURSOR_POS,
|
ERR_INVALID_CURSOR_POS,
|
||||||
ERR_INVALID_OPT_VALUE
|
ERR_INVALID_OPT_VALUE
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
const { debug, inherits } = require('util');
|
const { debug } = require('util');
|
||||||
const { emitExperimentalWarning } = require('internal/util');
|
const { emitExperimentalWarning } = require('internal/util');
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
@ -245,7 +245,7 @@ function Interface(input, output, completer, terminal) {
|
|||||||
input.resume();
|
input.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Interface, EventEmitter);
|
Object.setPrototypeOf(Interface.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
Object.defineProperty(Interface.prototype, 'columns', {
|
Object.defineProperty(Interface.prototype, 'columns', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
19
lib/repl.js
19
lib/repl.js
@ -53,7 +53,6 @@ const {
|
|||||||
} = require('internal/deps/acorn/dist/acorn');
|
} = require('internal/deps/acorn/dist/acorn');
|
||||||
const internalUtil = require('internal/util');
|
const internalUtil = require('internal/util');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const { inherits } = util;
|
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -669,9 +668,9 @@ function REPLServer(prompt,
|
|||||||
|
|
||||||
// handle multiline history
|
// handle multiline history
|
||||||
if (self[kBufferedCommandSymbol].length)
|
if (self[kBufferedCommandSymbol].length)
|
||||||
REPLServer.super_.prototype.multilineHistory.call(self, false);
|
Interface.prototype.multilineHistory.call(self, false);
|
||||||
else {
|
else {
|
||||||
REPLServer.super_.prototype.multilineHistory.call(self, true);
|
Interface.prototype.multilineHistory.call(self, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear buffer if no SyntaxErrors
|
// Clear buffer if no SyntaxErrors
|
||||||
@ -753,7 +752,7 @@ function REPLServer(prompt,
|
|||||||
|
|
||||||
self.displayPrompt();
|
self.displayPrompt();
|
||||||
}
|
}
|
||||||
inherits(REPLServer, Interface);
|
Object.setPrototypeOf(REPLServer.prototype, Interface.prototype);
|
||||||
exports.REPLServer = REPLServer;
|
exports.REPLServer = REPLServer;
|
||||||
|
|
||||||
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
|
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
|
||||||
@ -894,18 +893,18 @@ REPLServer.prototype.displayPrompt = function(preserveCursor) {
|
|||||||
const len = this.lines.level.length ? this.lines.level.length - 1 : 0;
|
const len = this.lines.level.length ? this.lines.level.length - 1 : 0;
|
||||||
const levelInd = '..'.repeat(len);
|
const levelInd = '..'.repeat(len);
|
||||||
prompt += levelInd + ' ';
|
prompt += levelInd + ' ';
|
||||||
REPLServer.super_.prototype.undoHistory.call(this);
|
Interface.prototype.undoHistory.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not overwrite `_initialPrompt` here
|
// Do not overwrite `_initialPrompt` here
|
||||||
REPLServer.super_.prototype.setPrompt.call(this, prompt);
|
Interface.prototype.setPrompt.call(this, prompt);
|
||||||
this.prompt(preserveCursor);
|
this.prompt(preserveCursor);
|
||||||
};
|
};
|
||||||
|
|
||||||
// When invoked as an API method, overwrite _initialPrompt
|
// When invoked as an API method, overwrite _initialPrompt
|
||||||
REPLServer.prototype.setPrompt = function setPrompt(prompt) {
|
REPLServer.prototype.setPrompt = function setPrompt(prompt) {
|
||||||
this._initialPrompt = prompt;
|
this._initialPrompt = prompt;
|
||||||
REPLServer.super_.prototype.setPrompt.call(this, prompt);
|
Interface.prototype.setPrompt.call(this, prompt);
|
||||||
};
|
};
|
||||||
|
|
||||||
REPLServer.prototype.turnOffEditorMode = util.deprecate(
|
REPLServer.prototype.turnOffEditorMode = util.deprecate(
|
||||||
@ -923,7 +922,7 @@ function ArrayStream() {
|
|||||||
this.emit('data', `${data[n]}\n`);
|
this.emit('data', `${data[n]}\n`);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
util.inherits(ArrayStream, Stream);
|
Object.setPrototypeOf(ArrayStream.prototype, Stream.prototype);
|
||||||
ArrayStream.prototype.readable = true;
|
ArrayStream.prototype.readable = true;
|
||||||
ArrayStream.prototype.writable = true;
|
ArrayStream.prototype.writable = true;
|
||||||
ArrayStream.prototype.resume = function() {};
|
ArrayStream.prototype.resume = function() {};
|
||||||
@ -1396,7 +1395,7 @@ function addStandardGlobals(completionGroups, filter) {
|
|||||||
|
|
||||||
function _turnOnEditorMode(repl) {
|
function _turnOnEditorMode(repl) {
|
||||||
repl.editorMode = true;
|
repl.editorMode = true;
|
||||||
REPLServer.super_.prototype.setPrompt.call(repl, '');
|
Interface.prototype.setPrompt.call(repl, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function _turnOffEditorMode(repl) {
|
function _turnOffEditorMode(repl) {
|
||||||
@ -1514,5 +1513,5 @@ function regexpEscape(s) {
|
|||||||
function Recoverable(err) {
|
function Recoverable(err) {
|
||||||
this.err = err;
|
this.err = err;
|
||||||
}
|
}
|
||||||
inherits(Recoverable, SyntaxError);
|
Object.setPrototypeOf(Recoverable.prototype, SyntaxError.prototype);
|
||||||
exports.Recoverable = Recoverable;
|
exports.Recoverable = Recoverable;
|
||||||
|
17
lib/zlib.js
17
lib/zlib.js
@ -31,7 +31,6 @@ const Transform = require('_stream_transform');
|
|||||||
const {
|
const {
|
||||||
deprecate,
|
deprecate,
|
||||||
_extend,
|
_extend,
|
||||||
inherits,
|
|
||||||
types: {
|
types: {
|
||||||
isAnyArrayBuffer,
|
isAnyArrayBuffer,
|
||||||
isArrayBufferView
|
isArrayBufferView
|
||||||
@ -318,7 +317,7 @@ function Zlib(opts, mode) {
|
|||||||
this._info = opts && opts.info;
|
this._info = opts && opts.info;
|
||||||
this.once('end', this.close);
|
this.once('end', this.close);
|
||||||
}
|
}
|
||||||
inherits(Zlib, Transform);
|
Object.setPrototypeOf(Zlib.prototype, Transform.prototype);
|
||||||
|
|
||||||
Object.defineProperty(Zlib.prototype, '_closed', {
|
Object.defineProperty(Zlib.prototype, '_closed', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
@ -648,28 +647,28 @@ function Deflate(opts) {
|
|||||||
return new Deflate(opts);
|
return new Deflate(opts);
|
||||||
Zlib.call(this, opts, DEFLATE);
|
Zlib.call(this, opts, DEFLATE);
|
||||||
}
|
}
|
||||||
inherits(Deflate, Zlib);
|
Object.setPrototypeOf(Deflate.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function Inflate(opts) {
|
function Inflate(opts) {
|
||||||
if (!(this instanceof Inflate))
|
if (!(this instanceof Inflate))
|
||||||
return new Inflate(opts);
|
return new Inflate(opts);
|
||||||
Zlib.call(this, opts, INFLATE);
|
Zlib.call(this, opts, INFLATE);
|
||||||
}
|
}
|
||||||
inherits(Inflate, Zlib);
|
Object.setPrototypeOf(Inflate.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function Gzip(opts) {
|
function Gzip(opts) {
|
||||||
if (!(this instanceof Gzip))
|
if (!(this instanceof Gzip))
|
||||||
return new Gzip(opts);
|
return new Gzip(opts);
|
||||||
Zlib.call(this, opts, GZIP);
|
Zlib.call(this, opts, GZIP);
|
||||||
}
|
}
|
||||||
inherits(Gzip, Zlib);
|
Object.setPrototypeOf(Gzip.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function Gunzip(opts) {
|
function Gunzip(opts) {
|
||||||
if (!(this instanceof Gunzip))
|
if (!(this instanceof Gunzip))
|
||||||
return new Gunzip(opts);
|
return new Gunzip(opts);
|
||||||
Zlib.call(this, opts, GUNZIP);
|
Zlib.call(this, opts, GUNZIP);
|
||||||
}
|
}
|
||||||
inherits(Gunzip, Zlib);
|
Object.setPrototypeOf(Gunzip.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function DeflateRaw(opts) {
|
function DeflateRaw(opts) {
|
||||||
if (opts && opts.windowBits === 8) opts.windowBits = 9;
|
if (opts && opts.windowBits === 8) opts.windowBits = 9;
|
||||||
@ -677,21 +676,21 @@ function DeflateRaw(opts) {
|
|||||||
return new DeflateRaw(opts);
|
return new DeflateRaw(opts);
|
||||||
Zlib.call(this, opts, DEFLATERAW);
|
Zlib.call(this, opts, DEFLATERAW);
|
||||||
}
|
}
|
||||||
inherits(DeflateRaw, Zlib);
|
Object.setPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function InflateRaw(opts) {
|
function InflateRaw(opts) {
|
||||||
if (!(this instanceof InflateRaw))
|
if (!(this instanceof InflateRaw))
|
||||||
return new InflateRaw(opts);
|
return new InflateRaw(opts);
|
||||||
Zlib.call(this, opts, INFLATERAW);
|
Zlib.call(this, opts, INFLATERAW);
|
||||||
}
|
}
|
||||||
inherits(InflateRaw, Zlib);
|
Object.setPrototypeOf(InflateRaw.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function Unzip(opts) {
|
function Unzip(opts) {
|
||||||
if (!(this instanceof Unzip))
|
if (!(this instanceof Unzip))
|
||||||
return new Unzip(opts);
|
return new Unzip(opts);
|
||||||
Zlib.call(this, opts, UNZIP);
|
Zlib.call(this, opts, UNZIP);
|
||||||
}
|
}
|
||||||
inherits(Unzip, Zlib);
|
Object.setPrototypeOf(Unzip.prototype, Zlib.prototype);
|
||||||
|
|
||||||
function createConvenienceMethod(ctor, sync) {
|
function createConvenienceMethod(ctor, sync) {
|
||||||
if (sync) {
|
if (sync) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user