JS<T> contains '*T' instead of RefCell.

This commit is contained in:
Tetsuharu OHZEKI 2014-05-26 14:46:31 +09:00
parent 3e558fdcb1
commit da703d6a80
2 changed files with 15 additions and 8 deletions

View file

@ -136,6 +136,10 @@ pub struct LayoutNode<'a> {
/// Being chained to a ContravariantLifetime prevents `LayoutNode`s from escaping. /// Being chained to a ContravariantLifetime prevents `LayoutNode`s from escaping.
pub chain: ContravariantLifetime<'a>, pub chain: ContravariantLifetime<'a>,
/// Padding to ensure the transmute `JS<T>` -> `LayoutNode`, `LayoutNode` -> `UnsafeLayoutNode`,
/// and `UnsafeLayoutNode` -> others.
pad: uint
} }
impl<'ln> Clone for LayoutNode<'ln> { impl<'ln> Clone for LayoutNode<'ln> {
@ -143,6 +147,7 @@ impl<'ln> Clone for LayoutNode<'ln> {
LayoutNode { LayoutNode {
node: self.node.clone(), node: self.node.clone(),
chain: self.chain, chain: self.chain,
pad: 0,
} }
} }
} }
@ -160,6 +165,7 @@ impl<'ln> TLayoutNode for LayoutNode<'ln> {
LayoutNode { LayoutNode {
node: node.transmute_copy(), node: node.transmute_copy(),
chain: self.chain, chain: self.chain,
pad: 0,
} }
} }
@ -196,6 +202,7 @@ impl<'ln> LayoutNode<'ln> {
f(LayoutNode { f(LayoutNode {
node: node, node: node,
chain: ContravariantLifetime, chain: ContravariantLifetime,
pad: 0,
}) })
} }
@ -425,6 +432,7 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> {
node: LayoutNode { node: LayoutNode {
node: node.transmute_copy(), node: node.transmute_copy(),
chain: self.node.chain, chain: self.node.chain,
pad: 0,
}, },
pseudo: Normal, pseudo: Normal,
} }

View file

@ -111,7 +111,7 @@ impl<T: Reflectable> Temporary<T> {
/// A rooted, JS-owned value. Must only be used as a field in other JS-owned types. /// A rooted, JS-owned value. Must only be used as a field in other JS-owned types.
pub struct JS<T> { pub struct JS<T> {
ptr: RefCell<*mut T> ptr: *T
} }
impl<T> Eq for JS<T> { impl<T> Eq for JS<T> {
@ -134,7 +134,7 @@ impl JS<Node> {
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> { pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> {
let TrustedNodeAddress(addr) = inner; let TrustedNodeAddress(addr) = inner;
JS { JS {
ptr: RefCell::new(addr as *mut Node) ptr: addr as *Node
} }
} }
} }
@ -143,7 +143,7 @@ impl JS<XMLHttpRequest> {
pub unsafe fn from_trusted_xhr_address(inner: TrustedXHRAddress) -> JS<XMLHttpRequest> { pub unsafe fn from_trusted_xhr_address(inner: TrustedXHRAddress) -> JS<XMLHttpRequest> {
let TrustedXHRAddress(addr) = inner; let TrustedXHRAddress(addr) = inner;
JS { JS {
ptr: RefCell::new(addr as *mut XMLHttpRequest) ptr: addr as *XMLHttpRequest
} }
} }
} }
@ -152,7 +152,7 @@ impl<T: Reflectable> JS<T> {
/// Create a new JS-owned value wrapped from a raw Rust pointer. /// Create a new JS-owned value wrapped from a raw Rust pointer.
pub unsafe fn from_raw(raw: *mut T) -> JS<T> { pub unsafe fn from_raw(raw: *mut T) -> JS<T> {
JS { JS {
ptr: RefCell::new(raw) ptr: raw as *T
} }
} }
@ -404,14 +404,13 @@ impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
/// It cannot not outlive its associated RootCollection, and it contains a JSRef /// It cannot not outlive its associated RootCollection, and it contains a JSRef
/// which cannot outlive this new Root. /// which cannot outlive this new Root.
fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, 'b, T> { fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, 'b, T> {
let ptr: *T = unrooted.ptr.borrow().clone() as *T;
let root = Root { let root = Root {
root_list: roots, root_list: roots,
jsref: JSRef { jsref: JSRef {
ptr: ptr, ptr: unrooted.ptr.clone(),
chain: ContravariantLifetime, chain: ContravariantLifetime,
}, },
ptr: ptr, ptr: unrooted.ptr.clone(),
js_ptr: unrooted.reflector().get_jsobject(), js_ptr: unrooted.reflector().get_jsobject(),
}; };
roots.root(&root); roots.root(&root);
@ -494,7 +493,7 @@ impl<'a,T> JSRef<'a,T> {
pub fn unrooted(&self) -> JS<T> { pub fn unrooted(&self) -> JS<T> {
JS { JS {
ptr: RefCell::new(self.ptr as *mut T) ptr: self.ptr
} }
} }
} }