diff options
Diffstat (limited to 'src/components/script/dom/bindings/js.rs')
-rw-r--r-- | src/components/script/dom/bindings/js.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 2386777cac9..3a3b6bd7166 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -106,31 +106,23 @@ impl<T: Reflectable> JS<T> { } } +//XXXjdm This is disappointing. This only gets called from trace hooks, in theory, +// so it's safe to assume that self is rooted and thereby safe to access. impl<T: Reflectable> Reflectable for JS<T> { fn reflector<'a>(&'a self) -> &'a Reflector { - self.get().reflector() - } - - fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { - self.get_mut().mut_reflector() - } -} - -impl<T: Reflectable> JS<T> { - pub fn get<'a>(&'a self) -> &'a T { - let borrowed = self.ptr.borrow(); unsafe { - &**borrowed + (*self.unsafe_get()).reflector() } } - pub fn get_mut<'a>(&'a mut self) -> &'a mut T { - let mut borrowed = self.ptr.borrow_mut(); + fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector { unsafe { - &mut **borrowed + (*self.unsafe_get()).mut_reflector() } } +} +impl<T: Reflectable> JS<T> { /// Returns an unsafe pointer to the interior of this JS object without touching the borrow /// flags. This is the only method that be safely accessed from layout. (The fact that this /// is unsafe is what necessitates the layout wrappers.) @@ -213,6 +205,16 @@ impl<T: Reflectable> OptionalRootable<T> for Option<Unrooted<T>> { } } +pub trait OptionalRootedRootable<T> { + fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>>; +} + +impl<T: Reflectable> OptionalRootedRootable<T> for Option<JS<T>> { + fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>> { + self.as_ref().map(|inner| inner.root(roots)) + } +} + pub trait ResultRootable<T,U> { fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U>; } |