Browse Source

streams2: ctor guards on Stream classes

v0.9.4-release
isaacs 12 years ago
parent
commit
545f512619
  1. 3
      lib/_stream_duplex.js
  2. 3
      lib/_stream_passthrough.js
  3. 3
      lib/_stream_readable.js
  4. 3
      lib/_stream_transform.js
  5. 6
      lib/_stream_writable.js

3
lib/_stream_duplex.js

@ -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);

3
lib/_stream_passthrough.js

@ -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);
}

3
lib/_stream_readable.js

@ -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);
}

3
lib/_stream_transform.js

@ -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.

6
lib/_stream_writable.js

@ -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.

Loading…
Cancel
Save