Skip to content

events: separate Node-style dispatch from passive event cleanup - #67709

Draft
ethanresnick wants to merge 1 commit into
nodejs:mainfrom
ethanresnick:codex/event-target-separate-listener-paths
Draft

ethanresnick wants to merge 1 commit into
nodejs:mainfrom
ethanresnick:codex/event-target-separate-listener-paths

Conversation

@ethanresnick

@ethanresnick ethanresnick commented Nov 22, 2026 •

Copy link
Copy Markdown

EventTarget's hybrid dispatcher currently checks the passive-listener symbol on the callback argument in a shared finally block. For Node-style listeners that argument is an arbitrary payload, rather than a DOM Event. This PR splits the work into Node-style and DOM-style branches using the existing listener-type decision, so that limiting passive state management entirely to the DOM branch.

The main goal is to increase performance: the symbol lookup on arbitrary, non-Event payloads is unnecessary and, in my codebase, it caused a lot of v8 code recompilations, because the symbol lookup happens on so many different payload shapes.

However, the lookup in the current code could also invoke a Proxy trap on the payload object, which probably isn’t intentional or desirable, so the semantics of this version may be better in that respect too.

The PR add regression coverage for untouched Proxy payloads, once listeners, mixed Node/DOM listeners, passive cancellation cleanup, thrown callback errors, and rejected callback returns.

Searched open PRs for passive-listener cleanup and kInPassiveListener; no duplicate was found. No directly matching issue was identified.

The code in this PR was generated by a frontier model, but I’ve reviewed it thoroughly.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@ethanresnick
ethanresnick force-pushed the codex/event-target-separate-listener-paths branch from 040a906 to 9b2945a Compare November 22, 2026 21:02
@ethanresnick
ethanresnick marked this pull request as ready for review November 22, 2026 21:08
Copilot AI balanced review requested due to automatic review settings November 22, 2026 21:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The regression test can pass even if rejection handling is removed because it does not assert the exception origin to distinguish explicit error forwarding from an unhandled rejection.

1 open issue
What changed in this PR

This PR separates Node-style and DOM-style dispatch in the internal EventTarget implementation, avoiding passive-state property access on arbitrary Node payloads while preserving DOM event cleanup.

Changes:

  • Moves Node-style callback invocation into a separate branch, keeping passive-state handling in the DOM branch.
  • Adds regression tests for Proxy payloads, once listeners, mixed listener types, passive cancellation, and callback error handling.
File Description
test/​parallel/​test-eventtarget-node-payload.js Adds payload, listener cleanup, and error-routing regression tests.
lib/​internal/​event_target.js Separates dispatch paths to avoid passive-state checks on Node payloads.

Review effort: Balanced

@ethanresnick
ethanresnick force-pushed the codex/event-target-separate-listener-paths branch from 9b2945a to 0a65ff2 Compare November 22, 2026 21:18
@MikeMcC399

Copy link
Copy Markdown
Member

The recommendations in:

advise you should tackle only one issue at a time and that you should not open any new PRs until your first PR has been approved.

You already have another unapproved PR #65038 open at this time. To stay within the guidelines, you may de-prioritize this PR or other open PRs by setting them to draft status.

Until the first PR has been approved and has landed in the main branch, GitHub classifies you as "first-time contributor". Each PR commit you push needs to be individually approved by team members to run in GitHub Actions CI. This causes delays for you as a contributor, and it adds to the work load for the team.

Waiting until the first PR has landed ensures that you as a contributor have experienced the complete process from PR submission to successful landing. After this has been completed, any new PRs or new commits to an existing PR are treated to rules for regular Contributors. GitHub Actions CI workflows are then run automatically without intervention by a team member.

@MikeMcC399

Copy link
Copy Markdown
Member

Setting to draft, since #65038 is open and unapproved.

@MikeMcC399
MikeMcC399 marked this pull request as draft November 27, 2026 08:41
@ethanresnick

Copy link
Copy Markdown
Author

Ok, got it @MikeMcC399. In that case, would you mind reviewing #65038, or telling me how to advance it? It is a four-line, docs-only change that has been sitting for several months.

@MikeMcC399

Copy link
Copy Markdown
Member

Ok, got it @MikeMcC399. In that case, would you mind reviewing #65038, or telling me how to advance it? It is a four-line, docs-only change that has been sitting for several months.

See replies in #65038

@MikeMcC399

Copy link
Copy Markdown
Member

Although I put this PR into draft, I did approve GitHub Actions workflows to run. They are showing an error.

There was an issue in the main branch that you have based your PR on and it has caused a failure in Test Shared Libraries. This issue has since been fixed. Please rebase the branch in this PR according to the Pull requests documentation so that you pick up the fix. GitHub Actions CI can then be run again.

Signed-off-by: Ethan Resnick <ethan.resnick@gmail.com>
@ethanresnick
ethanresnick force-pushed the codex/event-target-separate-listener-paths branch from 0a65ff2 to 796f824 Compare December 4, 2026 12:03
@ethanresnick

Copy link
Copy Markdown
Author

@MikeMcC399 Ok, thanks. I've addressed your comment on the other PR and rebased both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants