Skip to content

Commit

Permalink
stream: fix removeAllListeners() for Stream.Readable
Browse files Browse the repository at this point in the history
Fixes: #20923
  • Loading branch information
kaelzhang committed May 24, 2018
1 parent 5823938 commit 30cefde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ Readable.prototype.removeListener = function(ev, fn) {
};

Readable.prototype.removeAllListeners = function(ev) {
const res = Stream.prototype.removeAllListeners.call(this, ev);
const res = Stream.prototype.removeAllListeners.apply(this, arguments);

if (ev === 'readable' || ev === undefined) {
// We need to check if there is someone still listening to
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-stream-readable-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,16 @@ const Readable = require('stream').Readable;
assert.deepStrictEqual(result, expected);
}));
}

{
// #20923
const r = new Readable();
r._read = function() {
// actually doing thing here
};
r.on('data', function() {});

r.removeAllListeners();

assert.strictEqual(r.eventNames().length, 0);
}

0 comments on commit 30cefde

Please sign in to comment.