diff options
author | Josh Matthews <josh@joshmatthews.net> | 2014-04-10 17:11:08 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2014-05-03 14:18:30 -0400 |
commit | dfdda0098a3f169a37c100b36d4dd36ec1d815aa (patch) | |
tree | b4835f3c863c6e45849cf036faf5611925e10189 /src/components/script/dom/bindings/js.rs | |
parent | d7b96db33ca8f2b8a162df38e0f00e95f5ea6fa1 (diff) | |
download | servo-dfdda0098a3f169a37c100b36d4dd36ec1d815aa.tar.gz servo-dfdda0098a3f169a37c100b36d4dd36ec1d815aa.zip |
Remove JS::get/get_mut to enforce sound rooting practices.
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>; } |