streams2: ctor guards on Stream classes
This commit is contained in:
Родитель
9b1b85490b
Коммит
545f512619
|
@ -37,6 +37,9 @@ Object.keys(Writable.prototype).forEach(function(method) {
|
|||
});
|
||||
|
||||
function Duplex(options) {
|
||||
if (!(this instanceof Duplex))
|
||||
return new Duplex(options);
|
||||
|
||||
Readable.call(this, options);
|
||||
Writable.call(this, options);
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ var util = require('util');
|
|||
util.inherits(PassThrough, Transform);
|
||||
|
||||
function PassThrough(options) {
|
||||
if (!(this instanceof PassThrough))
|
||||
return new PassThrough(options);
|
||||
|
||||
Transform.call(this, options);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,9 @@ function ReadableState(options) {
|
|||
}
|
||||
|
||||
function Readable(options) {
|
||||
if (!(this instanceof Readable))
|
||||
return new Readable(options);
|
||||
|
||||
this._readableState = new ReadableState(options, this);
|
||||
Stream.apply(this);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,9 @@ function TransformState() {
|
|||
}
|
||||
|
||||
function Transform(options) {
|
||||
if (!(this instanceof Transform))
|
||||
return new Transform(options);
|
||||
|
||||
Duplex.call(this, options);
|
||||
|
||||
// bind output so that it can be passed around as a regular function.
|
||||
|
|
|
@ -27,6 +27,7 @@ module.exports = Writable
|
|||
|
||||
var util = require('util');
|
||||
var Stream = require('stream');
|
||||
var Duplex = Stream.Duplex;
|
||||
|
||||
util.inherits(Writable, Stream);
|
||||
|
||||
|
@ -51,6 +52,11 @@ function WritableState(options) {
|
|||
}
|
||||
|
||||
function Writable(options) {
|
||||
// Writable ctor is applied to Duplexes, though they're not
|
||||
// instanceof Writable, they're instanceof Readable.
|
||||
if (!(this instanceof Writable) && !(this instanceof Duplex))
|
||||
return new Writable(options);
|
||||
|
||||
this._writableState = new WritableState(options);
|
||||
|
||||
// legacy.
|
||||
|
|
Загрузка…
Ссылка в новой задаче