Skip to content

Truly independent web browser

LibJS: Let a CellRoot give its cell back to Rust embedders

Shannon Boothabb6204d2e95
diff --git a/Libraries/LibJS/Rust/src/gc/root.rs b/Libraries/LibJS/Rust/src/gc/root.rs
index 211307d8fe8..0377bd7a959 100644
--- a/Libraries/LibJS/Rust/src/gc/root.rs
+++ b/Libraries/LibJS/Rust/src/gc/root.rs
@@ -98,6 +98,14 @@ impl<T> CellRoot<T> {
_cell: PhantomData,
}
}
+
+ pub fn cell(&self) -> Gc<T> {
+ // SAFETY: The root holds the live cell it was created with, of type T.
+ unsafe {
+ let cell = capi::gc_root_cell(self.root.as_ptr());
+ Gc::from_non_null(NonNull::new(cell.cast()).expect("a root holds a cell"))
+ }
+ }
}
impl<T> Drop for CellRoot<T> {