From 9768c249715484df74182570740645bceb54004c Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 7 Sep 2019 23:29:18 +0200 Subject: [PATCH] stream: readable.off We have special logic in removeListener() which must apply to off() as well. --- 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 cfa36731e3d661..c63bf027a20f91 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -914,6 +914,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(); }