stream: fix removeAllListeners() for Stream.Readable

Fixes: https://github.com/nodejs/node/issues/20923

PR-URL: https://github.com/nodejs/node/pull/20924
Refs: https://github.com/nodejs/node/issues/20923
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Kael Zhang 2018-05-24 15:17:17 +08:00 committed by Matteo Collina
parent 4dbfb096f0
commit 9f4bf4ca43
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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);
}