Make dictionaries contain Root<T> values instead of JS<T>, ensuring that they will not be collected while the dictionary is alive.

This commit is contained in:
Josh Matthews 2014-04-24 11:44:53 -04:00
parent 0f2d0b1dc3
commit 895e9ee37f
5 changed files with 20 additions and 11 deletions

View file

@ -284,6 +284,12 @@ impl<T: Reflectable, U> ResultRootable<T, U> for Result<Temporary<T>, U> {
}
}
impl<T: Reflectable, U> ResultRootable<T, U> for Result<JS<T>, U> {
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U> {
self.map(|inner| inner.root())
}
}
/// Provides a facility to push unrooted values onto lists of rooted values. This is safe
/// under the assumption that said lists are reachable via the GC graph, and therefore the
/// new values are transitively rooted for the lifetime of their new owner.