From 3e558fdcb1667c162d8f27194696415dcb7eae1f Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Mon, 26 May 2014 03:43:47 +0900 Subject: [PATCH] JSRef & Root contains '*T' instead of RefCell. --- src/components/script/dom/bindings/js.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 67642c32573..44178cb93c3 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -394,7 +394,7 @@ pub struct Root<'a, 'b, T> { /// Reference to rooted value that must not outlive this container jsref: JSRef<'b, T>, /// Pointer to underlying Rust data - ptr: RefCell<*mut T>, + ptr: *T, /// On-stack JS pointer to assuage conservative stack scanner js_ptr: *mut JSObject, } @@ -404,13 +404,14 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> { /// It cannot not outlive its associated RootCollection, and it contains a JSRef /// which cannot outlive this new Root. fn new(roots: &'a RootCollection, unrooted: &JS) -> Root<'a, 'b, T> { + let ptr: *T = unrooted.ptr.borrow().clone() as *T; let root = Root { root_list: roots, jsref: JSRef { - ptr: unrooted.ptr.clone(), + ptr: ptr, chain: ContravariantLifetime, }, - ptr: unrooted.ptr.clone(), + ptr: ptr, js_ptr: unrooted.reflector().get_jsobject(), }; roots.root(&root); @@ -445,25 +446,23 @@ impl<'a, 'b, T: Reflectable> DerefMut> for Root<'a, 'b, T> { impl<'a, T: Reflectable> Deref for JSRef<'a, T> { fn deref<'b>(&'b self) -> &'b T { - let borrow = self.ptr.borrow(); unsafe { - &**borrow + &*self.ptr } } } impl<'a, T: Reflectable> DerefMut for JSRef<'a, T> { fn deref_mut<'b>(&'b mut self) -> &'b mut T { - let mut borrowed = self.ptr.borrow_mut(); unsafe { - &mut **borrowed + &mut *(self.ptr as *mut T) } } } /// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable. pub struct JSRef<'a, T> { - ptr: RefCell<*mut T>, + ptr: *T, chain: ContravariantLifetime<'a>, } @@ -495,7 +494,7 @@ impl<'a,T> JSRef<'a,T> { pub fn unrooted(&self) -> JS { JS { - ptr: self.ptr.clone() + ptr: RefCell::new(self.ptr as *mut T) } } }