Skip to content

Conversation

@Renegade334
Copy link
Member

@Renegade334 Renegade334 commented Oct 11, 2025

Resolves #60212.

Makes events.listenerCount() agnostic over both EventEmitters and EventTargets.

For EventTargets, this is faster than the events.getEventListeners(...).length pattern 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.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added events Issues and PRs related to the events subsystem / EventEmitter. needs-ci PRs that need a full CI run. labels Oct 11, 2025
@Renegade334 Renegade334 force-pushed the events-listenercount branch 6 times, most recently from 336f0e5 to f723962 Compare October 11, 2025 21:40
@Renegade334 Renegade334 marked this pull request as ready for review October 11, 2025 22:41
@@ -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) {
Copy link
Member Author

@Renegade334 Renegade334 Oct 11, 2025

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
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.53%. Comparing base (0b6ae6d) to head (206f4bd).
⚠️ Report is 50 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/events.js 99.83% <100.00%> (+1.64%) ⬆️
lib/internal/streams/legacy.js 94.44% <100.00%> (+5.64%) ⬆️

... and 100 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 20, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 20, 2025
@nodejs-github-bot
Copy link
Collaborator

@Renegade334 Renegade334 added deprecations Issues and PRs related to deprecations. semver-minor PRs that contain new features and should be released in the next minor version. labels Nov 14, 2025
@Renegade334 Renegade334 requested a review from mcollina November 14, 2025 19:08
@Renegade334 Renegade334 removed the request for review from mcollina November 18, 2025 20:29
@Renegade334 Renegade334 added the review wanted PRs that need reviews. label Nov 18, 2025
@Renegade334 Renegade334 added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 18, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 18, 2025
@nodejs-github-bot
Copy link
Collaborator

@Renegade334 Renegade334 added commit-queue Add this label to land a pull request using GitHub Actions. and removed review wanted PRs that need reviews. labels Nov 26, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 26, 2025
@nodejs-github-bot nodejs-github-bot merged commit 9c25002 into nodejs:main Nov 26, 2025
70 of 71 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 9c25002

@Renegade334 Renegade334 deleted the events-listenercount branch November 26, 2025 11:16
targos pushed a commit that referenced this pull request Nov 27, 2025
PR-URL: #60214
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecations Issues and PRs related to deprecations. events Issues and PRs related to the events subsystem / EventEmitter. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: Re-purpose events.listenerCount() as agnostic function over EventEmitters/EventTargets

4 participants