diff options
author | cjihrig <cjihrig@gmail.com> | 2019-05-14 16:38:09 +0300 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-05-16 18:55:32 +0300 |
commit | cca375f4af235ed7e7f763b2e35532ae843a5854 (patch) | |
tree | 12aebdad65d2deee89856b6f60c6c383aef438f7 /lib/internal/console | |
parent | a92ad36894dc91af765e7cc9bfce4a7ea64c27fa (diff) |
console: don't attach unnecessary error handlers
A noop error handler is attached to the console's stream on
write. The handler is then immediately removed after the write.
This commit skips adding the error handler if one already
exists.
PR-URL: https://github.com/nodejs/node/pull/27691
Fixes: https://github.com/nodejs/node/issues/27687
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/console')
-rw-r--r-- | lib/internal/console/constructor.js | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 04b6087b77f..9c262aef62b 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -231,7 +231,8 @@ Console.prototype[kWriteToConsole] = function(streamSymbol, string) { // handle both situations. try { // Add and later remove a noop error handler to catch synchronous errors. - stream.once('error', noop); + if (stream.listenerCount('error') === 0) + stream.once('error', noop); stream.write(string, errorHandler); } catch (e) { |