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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
kaelzhang authored and MylesBorins committed May 29, 2018
1 parent 5f9c01b commit 8f52c3f
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 8f52c3f

Please sign in to comment.