stream: apply special logic in removeListener for readable.off()

We have special logic in removeListener() which must apply
to off() as well.

PR-URL: https://github.com/nodejs/node/pull/29486
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Robert Nagy 2019-09-07 23:29:18 +02:00 committed by Rich Trott
parent 34a61d5630
commit 1665a9330c
2 changed files with 3 additions and 0 deletions

View File

@ -918,6 +918,7 @@ Readable.prototype.removeListener = function(ev, fn) {
return res;
};
Readable.prototype.off = Readable.prototype.removeListener;
Readable.prototype.removeAllListeners = function(ev) {
const res = Stream.prototype.removeAllListeners.apply(this, arguments);

View File

@ -2,6 +2,7 @@
const common = require('../common');
const { Readable } = require('stream');
const assert = require('assert');
// This test verifies that a stream could be resumed after
// removing the readable event in the same tick
@ -24,6 +25,7 @@ function check(s) {
const readableListener = common.mustNotCall();
s.on('readable', readableListener);
s.on('end', common.mustCall());
assert.strictEqual(s.removeListener, s.off);
s.removeListener('readable', readableListener);
s.resume();
}