Skip to content

Commit

Permalink
stream: fix removeAllListeners() for Stream.Readable
Browse files Browse the repository at this point in the history
Fixes: #20923

PR-URL: #20924
Refs: #20923
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
kaelzhang authored and mcollina committed May 28, 2018
1 parent 4dbfb09 commit 9f4bf4c
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 9f4bf4c

Please sign in to comment.