diff --git a/core/extension_set.rs b/core/extension_set.rs index 4be2485257143b..c56c7f493cc9a7 100644 --- a/core/extension_set.rs +++ b/core/extension_set.rs @@ -129,6 +129,7 @@ pub fn create_op_ctxs( let op_count = op_decls.len(); let mut op_ctxs = Vec::with_capacity(op_count); + let runtime_state_ptr = runtime_state.as_ref() as *const _; for (index, decl) in op_decls.into_iter().enumerate() { let metrics_fn = op_metrics_factory_fn .as_ref() @@ -140,7 +141,7 @@ pub fn create_op_ctxs( op_driver.clone(), decl, op_state.clone(), - runtime_state.clone(), + runtime_state_ptr, get_error_class_fn, metrics_fn, ); diff --git a/core/lib.rs b/core/lib.rs index 20001d6ca243bc..a292a5f7bad7a0 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -136,6 +136,7 @@ pub use crate::ops_metrics::OpMetricsSummaryTracker; pub use crate::path::strip_unc_prefix; pub use crate::runtime::stats; pub use crate::runtime::CompiledWasmModuleStore; +pub use crate::runtime::ContextState; pub use crate::runtime::CreateRealmOptions; pub use crate::runtime::CrossIsolateStore; pub use crate::runtime::JsRuntime; diff --git a/core/ops.rs b/core/ops.rs index 12c37308131ec8..470978255d19a1 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -96,7 +96,7 @@ pub struct OpCtx { pub(crate) last_fast_error: UnsafeCell>, op_driver: Rc, - runtime_state: Rc, + runtime_state: *const JsRuntimeState, } impl OpCtx { @@ -107,7 +107,7 @@ impl OpCtx { op_driver: Rc, decl: OpDecl, state: Rc>, - runtime_state: Rc, + runtime_state: *const JsRuntimeState, get_error_class_fn: GetErrorClassFn, metrics_fn: Option, ) -> Self { @@ -245,7 +245,8 @@ impl OpCtx { /// Get the [`JsRuntimeState`] for this op. pub(crate) fn runtime_state(&self) -> &JsRuntimeState { - &self.runtime_state + // SAFETY: JsRuntimeState outlives OpCtx + unsafe { &*self.runtime_state } } } diff --git a/core/runtime/jsrealm.rs b/core/runtime/jsrealm.rs index c2a85be521a3fe..ab8e15c89de705 100644 --- a/core/runtime/jsrealm.rs +++ b/core/runtime/jsrealm.rs @@ -49,7 +49,7 @@ impl Hasher for IdentityHasher { /// We may wish to experiment with alternative drivers in the future. pub(crate) type OpDriverImpl = super::op_driver::FuturesUnorderedDriver; -pub(crate) struct ContextState { +pub struct ContextState { pub(crate) task_spawner_factory: Arc, pub(crate) timers: WebTimers<(v8::Global, u32)>, pub(crate) js_event_loop_tick_cb: diff --git a/core/runtime/mod.rs b/core/runtime/mod.rs index 4ef8412c707e96..53125916dd6c50 100644 --- a/core/runtime/mod.rs +++ b/core/runtime/mod.rs @@ -18,7 +18,7 @@ mod tests; pub const V8_WRAPPER_TYPE_INDEX: i32 = 0; pub const V8_WRAPPER_OBJECT_INDEX: i32 = 1; -pub(crate) use jsrealm::ContextState; +pub use jsrealm::ContextState; pub(crate) use jsrealm::JsRealm; pub(crate) use jsrealm::OpDriverImpl; pub use jsruntime::CompiledWasmModuleStore;