From 123437bcc370e21d24c367dec8705644214c39e3 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 7 Sep 2019 23:29:18 +0200 Subject: [PATCH] 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 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Luigi Pinca --- lib/_stream_readable.js | 1 + test/parallel/test-stream-readable-readable-then-resume.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index d0c7fcfc81b20e..6c2bbb3495a3a3 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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); diff --git a/test/parallel/test-stream-readable-readable-then-resume.js b/test/parallel/test-stream-readable-readable-then-resume.js index 83cf49333a8d83..63dbc306e739f2 100644 --- a/test/parallel/test-stream-readable-readable-then-resume.js +++ b/test/parallel/test-stream-readable-readable-then-resume.js @@ -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(); }