Skip to content

Commit

Permalink
stream: apply special logic in removeListener for readable.off()
Browse files Browse the repository at this point in the history
We have special logic in removeListener() which must apply
to off() as well.

PR-URL: #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>
  • Loading branch information
ronag authored and BridgeAR committed Sep 25, 2019
1 parent 9150c4d commit 123437b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,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);
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-stream-readable-readable-then-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

0 comments on commit 123437b

Please sign in to comment.