Skip to content
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

Handle the FinalizationRegistry's context in HostEnqueueFinalizationRegistryCleanupJob #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreubotella
Copy link
Member

@andreubotella andreubotella commented Jan 23, 2025

Each FinalizationRegistry object has a context associated with it, which was the context at its construction. This context is used for calling its callback when any registered object is GC'd, which takes place in the CleanupFinalizationRegistry AO.

In the current spec, CleanupFinalizationRegistry handles the swapping of this context, and restores it back at the end. This, however, causes a problem for hosts that report uncaught JS exceptions by running JS code (such as the "error" event on window in the web, or the "unhandledException" event on process in Node.js), since they should run this event in the FinalizationRegistry's creation context, but CleanupFinalizationRegistry exits that context before the end of the function.

Since CleanupFinalizationRegistry (and HostEnqueueFinalizationRegistryCleanupJob) only clean up a single FinalizationRegitry, however, the context swapping can be pushed to the host hook instead, with the step about host-defined error reporting being inside that context. This ensures that such error reporting events are fired in the right context.

…RegistryCleanupJob`

Each FinalizationRegistry object has a context associated with it, which was the
context at its construction. This context is used for calling its callback when
any registered object is GC'd, which takes place in the
`CleanupFinalizationRegistry` AO.

In the current spec, `CleanupFinalizationRegistry` handles the swapping of this
context, and restores it back at the end. This, however, causes a problem for
hosts that report uncaught JS exceptions by running JS code (such as the
`"error"` event on `window` in the web, or the `"unhandledException"` event on
`process` in Node.js), since they should run this event in the
FinalizationRegistry's creation context, but `CleanupFinalizationRegistry` exits
that context before the end of the function.

Since `CleanupFinalizationRegistry` (and
`HostEnqueueFinalizationRegistryCleanupJob`) only clean up a single
FinalizationRegitry, however, the context swapping can be pushed to the host
hook instead, with the step about host-defined error reporting being inside that
context. This ensures that such error reporting events are fired in the right
context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants