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:
parent
34a61d5630
commit
1665a9330c
@ -918,6 +918,7 @@ Readable.prototype.removeListener = function(ev, fn) {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
Readable.prototype.off = Readable.prototype.removeListener;
|
||||||
|
|
||||||
Readable.prototype.removeAllListeners = function(ev) {
|
Readable.prototype.removeAllListeners = function(ev) {
|
||||||
const res = Stream.prototype.removeAllListeners.apply(this, arguments);
|
const res = Stream.prototype.removeAllListeners.apply(this, arguments);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const { Readable } = require('stream');
|
const { Readable } = require('stream');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
// This test verifies that a stream could be resumed after
|
// This test verifies that a stream could be resumed after
|
||||||
// removing the readable event in the same tick
|
// removing the readable event in the same tick
|
||||||
@ -24,6 +25,7 @@ function check(s) {
|
|||||||
const readableListener = common.mustNotCall();
|
const readableListener = common.mustNotCall();
|
||||||
s.on('readable', readableListener);
|
s.on('readable', readableListener);
|
||||||
s.on('end', common.mustCall());
|
s.on('end', common.mustCall());
|
||||||
|
assert.strictEqual(s.removeListener, s.off);
|
||||||
s.removeListener('readable', readableListener);
|
s.removeListener('readable', readableListener);
|
||||||
s.resume();
|
s.resume();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user