Remove unrooted() methods

This commit is contained in:
Anthony Ramine 2015-04-27 18:13:32 +02:00
parent af21229c0e
commit 2770886196
3 changed files with 10 additions and 33 deletions

View file

@ -174,10 +174,6 @@ impl<T: Reflectable> Temporary<T> {
pub fn from_rooted<'a>(root: JSRef<'a, T>) -> Temporary<T> { pub fn from_rooted<'a>(root: JSRef<'a, T>) -> Temporary<T> {
Temporary::new(JS::from_rooted(root)) Temporary::new(JS::from_rooted(root))
} }
unsafe fn inner(&self) -> JS<T> {
self.inner.clone()
}
} }
impl<T: Reflectable> Rootable<T> for Temporary<T> { impl<T: Reflectable> Rootable<T> for Temporary<T> {
@ -406,7 +402,7 @@ impl<T: Reflectable> JS<T> {
/// are reachable in the GC graph, so this unrooted value becomes /// are reachable in the GC graph, so this unrooted value becomes
/// transitively rooted for the lifetime of its new owner. /// transitively rooted for the lifetime of its new owner.
pub fn assign(&mut self, val: Temporary<T>) { pub fn assign(&mut self, val: Temporary<T>) {
*self = unsafe { val.inner() }; *self = val.inner.clone();
} }
} }
@ -461,13 +457,15 @@ impl<T> Assignable<T> for JS<T> {
impl<'a, T: Reflectable> Assignable<T> for JSRef<'a, T> { impl<'a, T: Reflectable> Assignable<T> for JSRef<'a, T> {
unsafe fn get_js(&self) -> JS<T> { unsafe fn get_js(&self) -> JS<T> {
self.unrooted() JS {
ptr: self.ptr
}
} }
} }
impl<T: Reflectable> Assignable<T> for Temporary<T> { impl<T: Reflectable> Assignable<T> for Temporary<T> {
unsafe fn get_js(&self) -> JS<T> { unsafe fn get_js(&self) -> JS<T> {
self.inner() self.inner.clone()
} }
} }
@ -484,18 +482,6 @@ impl<T: Reflectable, U: Rootable<T>> OptionalRootable<T> for Option<U> {
} }
} }
/// Return an unrooted type for storing in optional DOM fields
pub trait OptionalUnrootable<T> {
/// Returns a `JS<T>` for the inner value, if it exists.
fn unrooted(&self) -> Option<JS<T>>;
}
impl<'a, T: Reflectable> OptionalUnrootable<T> for Option<JSRef<'a, T>> {
fn unrooted(&self) -> Option<JS<T>> {
self.as_ref().map(|inner| JS::from_rooted(*inner))
}
}
/// Root a rootable `Option<Option>` type (used for `Option<Option<JS<T>>>`) /// Root a rootable `Option<Option>` type (used for `Option<Option<JS<T>>>`)
pub trait OptionalOptionalRootable<T> { pub trait OptionalOptionalRootable<T> {
/// Root the inner value, if it exists. /// Root the inner value, if it exists.
@ -692,15 +678,6 @@ impl<'a, 'b, T> PartialEq<JSRef<'b, T>> for JSRef<'a, T> {
} }
} }
impl<'a,T> JSRef<'a,T> {
/// Return an unrooted `JS<T>` for the inner pointer.
pub fn unrooted(&self) -> JS<T> {
JS {
ptr: self.ptr
}
}
}
impl<'a, T: Reflectable> JSRef<'a, T> { impl<'a, T: Reflectable> JSRef<'a, T> {
/// Returns the inner pointer directly. /// Returns the inner pointer directly.
pub fn extended_deref(self) -> &'a T { pub fn extended_deref(self) -> &'a T {

View file

@ -341,7 +341,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
match idmap.entry(id) { match idmap.entry(id) {
Vacant(entry) => { Vacant(entry) => {
entry.insert(vec!(element.unrooted())); entry.insert(vec![JS::from_rooted(element)]);
} }
Occupied(entry) => { Occupied(entry) => {
let elements = entry.into_mut(); let elements = entry.into_mut();
@ -889,7 +889,7 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> {
for node in NodeCast::from_ref(root.r()).traverse_preorder() { for node in NodeCast::from_ref(root.r()).traverse_preorder() {
let node = node.root(); let node = node.root();
if callback(node.r()) { if callback(node.r()) {
nodes.push(node.r().unrooted()); nodes.push(JS::from_rooted(node.r()));
} }
} }
}; };

View file

@ -129,7 +129,7 @@ impl<'a> HTMLCanvasElementHelpers for JSRef<'a, HTMLCanvasElement> {
let context = self.GetContext(String::from_str("2d")); let context = self.GetContext(String::from_str("2d"));
match context.unwrap() { match context.unwrap() {
CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D(context) => { CanvasRenderingContext2DOrWebGLRenderingContext::eCanvasRenderingContext2D(context) => {
Temporary::new(context.root().r().unrooted()) Temporary::from_unrooted(context)
} }
_ => panic!("Wrong Context Type: Expected 2d context"), _ => panic!("Wrong Context Type: Expected 2d context"),
} }
@ -139,8 +139,8 @@ impl<'a> HTMLCanvasElementHelpers for JSRef<'a, HTMLCanvasElement> {
let context = self.GetContext(String::from_str("webgl")); let context = self.GetContext(String::from_str("webgl"));
match context.unwrap() { match context.unwrap() {
CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext(context) => { CanvasRenderingContext2DOrWebGLRenderingContext::eWebGLRenderingContext(context) => {
return Temporary::new(context.root().r().unrooted()); Temporary::from_unrooted(context)
} },
_ => panic!("Wrong Context Type: Expected webgl context"), _ => panic!("Wrong Context Type: Expected webgl context"),
} }
} }