-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
events: repurpose events.listenerCount() to accept EventTargets
#60214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
events: repurpose events.listenerCount() to accept EventTargets
#60214
Conversation
|
Review requested:
|
336f0e5 to
f723962
Compare
| @@ -59,7 +59,8 @@ Stream.prototype.pipe = function(dest, options) { | |||
| // Don't leave dangling pipes when there are errors. | |||
| function onerror(er) { | |||
| cleanup(); | |||
| if (EE.listenerCount(this, 'error') === 0) { | |||
| // If we removed the last error handler, trigger an unhandled error event. | |||
| if (this.listenerCount?.('error') === 0) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legacy behaviour dictates that stream.pipe() targets do not need to be true EventEmitters; this.listenerCount might not exist at all (#2655).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60214 +/- ##
==========================================
+ Coverage 88.04% 88.53% +0.49%
==========================================
Files 703 703
Lines 208260 208263 +3
Branches 40068 40163 +95
==========================================
+ Hits 183360 184385 +1025
+ Misses 16840 15876 -964
+ Partials 8060 8002 -58
🚀 New features to boost your workflow:
|
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
f723962 to
b3c7ae2
Compare
b3c7ae2 to
206f4bd
Compare
|
Landed in 9c25002 |
PR-URL: #60214 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Resolves #60212.
Makes
events.listenerCount()agnostic over both EventEmitters and EventTargets.For EventTargets, this is faster than the
events.getEventListeners(...).lengthpattern currently in use within the test suite, as it doesn't need to traverse the linked list.Note that this now validates the emitter argument, whereas the previous version did not (it just returned 0 if the target wasn't an EventEmitter). Dealer's choice as to whether or not this constitutes a minor or major change.