From f122cdd762df18e0ca96d52c9c4f43d5cb056274 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Fri, 11 Oct 2024 22:41:04 +0800 Subject: [PATCH] feat(js/binding): allow owned stack and memory Signed-off-by: jsvisa --- src/tracing/js/bindings.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tracing/js/bindings.rs b/src/tracing/js/bindings.rs index f1d155c1..364e3bc1 100644 --- a/src/tracing/js/bindings.rs +++ b/src/tracing/js/bindings.rs @@ -237,12 +237,18 @@ impl StepLog { pub(crate) struct MemoryRef(GuardedNullableGc); impl MemoryRef { - /// Creates a new stack reference + /// Creates a new memory reference pub(crate) fn new(mem: &SharedMemory) -> (Self, GcGuard<'_, SharedMemory>) { let (inner, guard) = GuardedNullableGc::new_ref(mem); (Self(inner), guard) } + /// Creates a new owned memory + pub(crate) fn new_owned(mem: SharedMemory) -> (Self, GcGuard<'static, SharedMemory>) { + let (inner, guard) = GuardedNullableGc::new_owned(mem); + (Self(inner), guard) + } + fn len(&self) -> usize { self.0.with_inner(|mem| mem.len()).unwrap_or_default() } @@ -428,6 +434,12 @@ impl StackRef { (Self(inner), guard) } + /// Creates a new owned stack + pub(crate) fn new_owned(stack: Stack) -> (Self, GcGuard<'static, Stack>) { + let (inner, guard) = GuardedNullableGc::new_owned(stack); + (Self(inner), guard) + } + fn peek(&self, idx: usize, ctx: &mut Context) -> JsResult { self.0 .with_inner(|stack| {