From 30cefde302389b06921096ca4bddfae74f9a224f Mon Sep 17 00:00:00 2001 From: Kael Zhang Date: Thu, 24 May 2018 15:17:17 +0800 Subject: [PATCH] stream: fix removeAllListeners() for Stream.Readable Fixes: https://github.com/nodejs/node/issues/20923 --- lib/_stream_readable.js | 2 +- test/parallel/test-stream-readable-event.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 7c11978c12b65c..a8e52f5f1d6c5b 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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 diff --git a/test/parallel/test-stream-readable-event.js b/test/parallel/test-stream-readable-event.js index 33b912e71ec98f..06fac7dc8bd125 100644 --- a/test/parallel/test-stream-readable-event.js +++ b/test/parallel/test-stream-readable-event.js @@ -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); +}