deno
28b2cf5f - refactor(node/vm): own the vm microtask queue instead of leaking it

Commit
86 days ago
refactor(node/vm): own the vm microtask queue instead of leaking it v8 152 replaced the `UniqueRef<MicrotaskQueue>` from `MicrotaskQueue::new` with an owning `MicrotaskQueueHandle`. Two things followed from that which the first pass got wrong. `MicrotaskQueue` no longer implements `Drop` — only the handle does — so the `drop_in_place` in `ContextifyContext::drop` silently became a no-op, and forgetting the handle to recover a raw pointer leaked it outright. Under the default `v8_cppgc_microtask_queue` setting the handle is a root into the isolate's heap that contexts outlive on their own, so it wants to be held and dropped, not leaked. `ContextifyContext` now stores an `Option<OwnedMicrotaskQueue>` and lets ordinary ownership release it, which drops the hand-written `Drop` impl, the `mem::forget`, and the `unsafe { drop_in_place }` along with it. `ContextifyModule` keeps borrowing the queue as a raw alias, which is now sounder: a context keeps its queue alive independently of the handle, so the alias survives even if the owning `ContextifyContext` is collected first. `OwnedMicrotaskQueue` is aliased in the deno_v8 facade because the QuickJS backend still returns `UniqueRef<MicrotaskQueue>`; both are RAII wrappers that deref to `MicrotaskQueue`, so callers just name the alias.
Author
Parents
Loading