Puts a root inside this root set. The returned handle can be freely stored outside the current arena, and will keep the root alive across garbage collections.
(
&self,
mc: &Mutation<'gc>,
root: Gc<'gc, Root<'gc, R>>,
)
| 47 | /// The returned handle can be freely stored outside the current arena, and will keep the root |
| 48 | /// alive across garbage collections. |
| 49 | pub fn stash<R: for<'a> Rootable<'a>>( |
| 50 | &self, |
| 51 | mc: &Mutation<'gc>, |
| 52 | root: Gc<'gc, Root<'gc, R>>, |
| 53 | ) -> DynamicRoot<R> { |
| 54 | // SAFETY: We are adopting a new `Gc` pointer, so we must invoke a write barrier. |
| 55 | mc.backward_barrier(Gc::erase(self.0), Some(Gc::erase(root))); |
| 56 | |
| 57 | let mut slots = self.0.slots.borrow_mut(); |
| 58 | let index = slots.add(unsafe { Gc::cast(root) }); |
| 59 | |
| 60 | let ptr = |
| 61 | unsafe { mem::transmute::<Gc<'gc, Root<'gc, R>>, Gc<'static, Root<'static, R>>>(root) }; |
| 62 | let slots = unsafe { |
| 63 | mem::transmute::<Weak<RefCell<Slots<'gc>>>, Weak<RefCell<Slots<'static>>>>( |
| 64 | Rc::downgrade(&self.0.slots), |
| 65 | ) |
| 66 | }; |
| 67 | |
| 68 | DynamicRoot { ptr, slots, index } |
| 69 | } |
| 70 | |
| 71 | /// Gets immutable access to the given root. |
| 72 | /// |
nothing calls this directly
no test coverage detected