mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
JSRef<T> & Root<T> contains '*T' instead of RefCell.
This commit is contained in:
parent
43b647feff
commit
3e558fdcb1
1 changed files with 8 additions and 9 deletions
|
@ -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<T>) -> 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<JSRef<'b, T>> for Root<'a, 'b, T> {
|
|||
|
||||
impl<'a, T: Reflectable> Deref<T> 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<T> 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<T> {
|
||||
JS {
|
||||
ptr: self.ptr.clone()
|
||||
ptr: RefCell::new(self.ptr as *mut T)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue