Browse Source

Use === instead of == for END_OF_FILE compares

This caused a very hard to track down bug. Thanks to Mikeal Rogers for this
fix. Unfortunately we were unable to put together a test case.
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
71dc232f93
  1. 6
      lib/net.js

6
lib/net.js

@ -382,7 +382,7 @@ Object.defineProperty(Stream.prototype, 'readyState', {
Stream.prototype.write = function (data, encoding) { Stream.prototype.write = function (data, encoding) {
if (this._writeQueue && this._writeQueue.length) { if (this._writeQueue && this._writeQueue.length) {
// Slow. There is already a write queue, so let's append to it. // Slow. There is already a write queue, so let's append to it.
if (this._writeQueueLast() == END_OF_FILE) { if (this._writeQueueLast() === END_OF_FILE) {
throw new Error('Stream.close() called already; cannot write.'); throw new Error('Stream.close() called already; cannot write.');
} }
this._writeQueue.push(data); // TODO if string of the same encoding concat? this._writeQueue.push(data); // TODO if string of the same encoding concat?
@ -511,7 +511,7 @@ Stream.prototype.flush = function () {
var data = this._writeQueue.shift(); var data = this._writeQueue.shift();
var encoding = this._writeQueueEncoding.shift(); var encoding = this._writeQueueEncoding.shift();
if (data == END_OF_FILE) { if (data === END_OF_FILE) {
this._shutdown(); this._shutdown();
return true; return true;
} }
@ -714,7 +714,7 @@ Stream.prototype.close = function (data, encoding) {
Stream.prototype.end = function (data, encoding) { Stream.prototype.end = function (data, encoding) {
if (this.writable) { if (this.writable) {
if (data) this.write(data, encoding); if (data) this.write(data, encoding);
if (this._writeQueueLast() != END_OF_FILE) { if (this._writeQueueLast() !== END_OF_FILE) {
this._writeQueue.push(END_OF_FILE); this._writeQueue.push(END_OF_FILE);
this.flush(); this.flush();
} }

Loading…
Cancel
Save