Skip to content

Commit 9f4bf4c

Browse files
kaelzhangmcollina
authored andcommitted
stream: fix removeAllListeners() for Stream.Readable
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>
1 parent 4dbfb09 commit 9f4bf4c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/_stream_readable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ Readable.prototype.removeListener = function(ev, fn) {
846846
};
847847

848848
Readable.prototype.removeAllListeners = function(ev) {
849-
const res = Stream.prototype.removeAllListeners.call(this, ev);
849+
const res = Stream.prototype.removeAllListeners.apply(this, arguments);
850850

851851
if (ev === 'readable' || ev === undefined) {
852852
// We need to check if there is someone still listening to

test/parallel/test-stream-readable-event.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,16 @@ const Readable = require('stream').Readable;
113113
assert.deepStrictEqual(result, expected);
114114
}));
115115
}
116+
117+
{
118+
// #20923
119+
const r = new Readable();
120+
r._read = function() {
121+
// actually doing thing here
122+
};
123+
r.on('data', function() {});
124+
125+
r.removeAllListeners();
126+
127+
assert.strictEqual(r.eventNames().length, 0);
128+
}

0 commit comments

Comments
 (0)