Browse Source

streams2: Do not allow hwm < lwm

There was previously an assert() in there, but this part of the code is
so high-volume that the added cost made a measurable dent in http_simple.

Just checking inline is fine, though, and prevents a lot of potential
hazards.
v0.9.7-release
isaacs 12 years ago
parent
commit
20a3c5d09c
  1. 3
      lib/_stream_readable.js
  2. 3
      lib/_stream_writable.js
  3. 15
      test/simple/test-stream2-basic.js

3
lib/_stream_readable.js

@ -48,6 +48,9 @@ function ReadableState(options, stream) {
this.lowWaterMark = ~~this.lowWaterMark; this.lowWaterMark = ~~this.lowWaterMark;
this.highWaterMark = ~~this.highWaterMark; this.highWaterMark = ~~this.highWaterMark;
if (this.lowWaterMark > this.highWaterMark)
throw new Error('lowWaterMark cannot be higher than highWaterMark');
this.buffer = []; this.buffer = [];
this.length = 0; this.length = 0;
this.pipes = null; this.pipes = null;

3
lib/_stream_writable.js

@ -49,6 +49,9 @@ function WritableState(options, stream) {
this.lowWaterMark = ~~this.lowWaterMark; this.lowWaterMark = ~~this.lowWaterMark;
this.highWaterMark = ~~this.highWaterMark; this.highWaterMark = ~~this.highWaterMark;
if (this.lowWaterMark > this.highWaterMark)
throw new Error('lowWaterMark cannot be higher than highWaterMark');
this.needDrain = false; this.needDrain = false;
// at the start of calling end() // at the start of calling end()
this.ending = false; this.ending = false;

15
test/simple/test-stream2-basic.js

@ -318,3 +318,18 @@ test('multipipe', function(t) {
r.pipe(w[2]); r.pipe(w[2]);
}); });
}); });
assert.throws(function() {
var bad = new R({
highWaterMark: 10,
lowWaterMark: 1000
});
});
assert.throws(function() {
var W = require('stream').Writable;
var bad = new W({
highWaterMark: 10,
lowWaterMark: 1000
});
});

Loading…
Cancel
Save