diff --git a/crates/core/src/host/v8/syscall/hooks.rs b/crates/core/src/host/v8/syscall/hooks.rs index d2fef8ac88f..8043061fb98 100644 --- a/crates/core/src/host/v8/syscall/hooks.rs +++ b/crates/core/src/host/v8/syscall/hooks.rs @@ -93,7 +93,7 @@ impl ModuleHookKey { } /// Context embedder slot holding the receiver (`this`) value used for hook calls. -const RECV_SLOT_INDEX: i32 = ModuleHookKey::SenderErrorClass as i32 + 1; +pub(super) const RECV_SLOT_INDEX: i32 = ModuleHookKey::SenderErrorClass as i32 + 1; /// Holds the `AbiVersion` used by the module /// and the module hooks registered by the module diff --git a/crates/core/src/host/v8/syscall/mod.rs b/crates/core/src/host/v8/syscall/mod.rs index 7def5bf19ce..4ad8b0ec1ba 100644 --- a/crates/core/src/host/v8/syscall/mod.rs +++ b/crates/core/src/host/v8/syscall/mod.rs @@ -125,6 +125,11 @@ pub(super) fn get_hooks<'scope>( scope: &mut PinScope<'scope, '_>, exports_obj: Local<'_, v8::Object>, ) -> Result>, ErrorOrException> { + // We only set RECV_SLOT_INDEX in set_registered_hooks, which is only called in + // the v2 code path. Set it to undefined ahead of time so it's not a garbage value. + scope + .get_current_context() + .set_embedder_data(hooks::RECV_SLOT_INDEX, v8::undefined(scope).into()); if let Some(hooks) = get_registered_hooks(scope) { return Ok(Some(hooks)); }