Skip to content

fix(core): store Global<Context> ptr for libuv-compat callbacks#32361

Merged
bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju:fix/global-context-ptr-libuv
Feb 28, 2026
Merged

fix(core): store Global<Context> ptr for libuv-compat callbacks#32361
bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju:fix/global-context-ptr-libuv

Conversation

@bartlomieju
Copy link
Member

Summary

  • Store a v8::Global<Context> via Global::into_raw() once during register_uv_loop instead of storing a v8::Local<Context> pointer at the start of each event loop tick
  • V8 keeps the persistent-handle slot updated across GC cycles, so the pointer remains valid for the lifetime of the runtime
  • The raw Global is reconstructed and properly dropped in JsRealmInner::destroy
  • Remove the per-tick transmute + const size assert that was previously needed

Ported from denoland/deno_core#1315

Original author: @littledivy

Test plan

  • cargo check -p deno_core passes

🤖 Generated with Claude Code

Instead of storing a `v8::Local<Context>` pointer in `loop_.data` at
the start of each event loop tick (which is only valid for that tick),
store a `v8::Global<Context>` via `Global::into_raw()` once during
`register_uv_loop`. V8 keeps the persistent-handle slot updated across
GC cycles, so the pointer remains valid for the lifetime of the runtime.
The raw Global is reconstructed and dropped in `JsRealmInner::destroy`.

Ported from denoland/deno_core#1315

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju merged commit 8e5efb0 into denoland:main Feb 28, 2026
112 checks passed
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