MarshallOfSound

#53981: refactor: follow-ups to emitting WebContents' forwarded events natively

Merged
Created: Sep 15, 2026, 8:59:04 PM
Merged: Sep 16, 2026, 11:22:26 AM
2 comments
Target: main

Description of Change

Follow-up to #53975 addressing @ckerr's review:

  • render-process-gone / login: the WebContents' own listeners now run off the wrapper captured before the app emit, so they still run if an app listener destroys the WebContents (as the remainder of an in-progress emit() did before), and the native object is not touched after the app emit.
  • select-bluetooth-device: the chooser and the WebContents are re-checked after calling listenerCount(), which an app can replace.
  • Removed the unused weak pointer in OnFirstNonEmptyLayout; const isolate locals; brace-initialised the callback scopes.
  • Specs for the ordering guarantees: app listeners before the webContents', one microtask/nextTick drain after both, and the destroyed-by-app-listener case.

On the microtask question: the paired emits share one outer node::CallbackScope, so the inner MakeCallback scopes are nested (depth > 1) and neither they nor gin's kRunMicrotasks scope (explicit microtask policy in the browser process) checkpoint; ticks and microtasks run once when the outer scope closes, after both emits — the new spec asserts exactly that and matches the pre-#53975 behaviour. One ordering difference does remain and is intentional: a webContents.prependListener('login' | 'render-process-gone', …) listener used to run before app listeners (it sat ahead of the internal forwarding listener) and now runs after them.

Checklist

Release Notes

Notes: none

Backports

45-x-y
Pending
Waiting for a manual backport

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron