Created
January 14, 2013 23:54
-
-
Save isaacs/4534672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js | |
index 7ad3974..a0caa3b 100644 | |
--- a/lib/_stream_readable.js | |
+++ b/lib/_stream_readable.js | |
@@ -48,6 +48,9 @@ function ReadableState(options, stream) { | |
this.lowWaterMark = ~~this.lowWaterMark; | |
this.highWaterMark = ~~this.highWaterMark; | |
+ if (this.lowWaterMark > this.highWaterMark) | |
+ throw new Error('lowWaterMark cannot be higher than highWaterMark'); | |
+ | |
this.buffer = []; | |
this.length = 0; | |
this.pipes = null; | |
diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js | |
index 1a907da..2d63c4d 100644 | |
--- a/lib/_stream_writable.js | |
+++ b/lib/_stream_writable.js | |
@@ -49,6 +49,9 @@ function WritableState(options, stream) { | |
this.lowWaterMark = ~~this.lowWaterMark; | |
this.highWaterMark = ~~this.highWaterMark; | |
+ if (this.lowWaterMark > this.highWaterMark) | |
+ throw new Error('lowWaterMark cannot be higher than highWaterMark'); | |
+ | |
this.needDrain = false; | |
// at the start of calling end() | |
this.ending = false; | |
diff --git a/test/simple/test-stream2-basic.js b/test/simple/test-stream2-basic.js | |
index 0b4f4cf..dff3340 100644 | |
--- a/test/simple/test-stream2-basic.js | |
+++ b/test/simple/test-stream2-basic.js | |
@@ -318,3 +318,18 @@ test('multipipe', function(t) { | |
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 | |
+ }); | |
+}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment