rusty_v8 icon indicating copy to clipboard operation
rusty_v8 copied to clipboard

[WIP] feat: Guaranteed finalizers

Open andreubotella opened this issue 3 years ago • 1 comments

Currently, when a finalizer callback is registered, it is not guaranteed to be called if there is a global reference to the corresponding object that survives the isolate. This is because the finalizer callback takes a &mut Isolate, and so it must be called before the isolate is fully destroyed, but all existing globals (including possibly the one being currently finalized) are still usable while there still exists a mutable reference to the isolate.

However, there are still use cases for having finalizers that are guaranteed to run regardless of any remaining globals, but that don't require any interaction with the isolate. This change adds them.

This change also changes the context annex to use a guaranteed finalizer, fixing a bug with context slots not being freed if there were any globals to the context at the time the isolate is dropped.

Closes #1066.

andreubotella avatar Sep 20 '22 03:09 andreubotella

This is a way to fix #1066, which was blocking denoland/deno#15760, but it has not been discussed with the core team and might not be a good idea. I'm raising this PR as a way to initiate the discussion.

andreubotella avatar Sep 20 '22 03:09 andreubotella

I added tests for the guaranteed finalization API. PTAL

andreubotella avatar Oct 06 '22 08:10 andreubotella