Skip to content

Commit

Permalink
feat(js/binding): allow owned stack and memory
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa committed Oct 11, 2024
1 parent 0b1240d commit f122cdd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/tracing/js/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,18 @@ impl StepLog {
pub(crate) struct MemoryRef(GuardedNullableGc<SharedMemory>);

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()
}
Expand Down Expand Up @@ -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<JsValue> {
self.0
.with_inner(|stack| {
Expand Down

0 comments on commit f122cdd

Please sign in to comment.