From 28061b1c913c432d46e935e632862e0164d2cbfd Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Mon, 13 Oct 2014 00:32:48 +0200 Subject: [PATCH] Privatize Node --- components/layout/util.rs | 6 +++--- components/layout/wrapper.rs | 4 ++-- components/script/dom/node.rs | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/components/layout/util.rs b/components/layout/util.rs index 198607473f1..9bb1a3ffa1f 100644 --- a/components/layout/util.rs +++ b/components/layout/util.rs @@ -78,20 +78,20 @@ pub trait LayoutDataAccess { impl<'ln> LayoutDataAccess for LayoutNode<'ln> { #[inline(always)] unsafe fn borrow_layout_data_unchecked(&self) -> *const Option { - mem::transmute(self.get().layout_data.borrow_unchecked()) + mem::transmute(self.get().layout_data_unchecked()) } #[inline(always)] fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow()) + mem::transmute(self.get().layout_data()) } } #[inline(always)] fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow_mut()) + mem::transmute(self.get().layout_data_mut()) } } } diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index f7b14cff10c..2aac0411c4a 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -721,7 +721,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { #[inline(always)] pub fn borrow_layout_data<'a>(&'a self) -> Ref<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow()) + mem::transmute(self.get().layout_data()) } } @@ -729,7 +729,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { #[inline(always)] pub fn mutate_layout_data<'a>(&'a self) -> RefMut<'a,Option> { unsafe { - mem::transmute(self.get().layout_data.borrow_mut()) + mem::transmute(self.get().layout_data_mut()) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 448d50620fb..81946a2738e 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -73,9 +73,10 @@ use uuid; /// An HTML node. #[jstraceable] #[must_root] +#[privatize] pub struct Node { /// The JavaScript reflector for this node. - pub eventtarget: EventTarget, + eventtarget: EventTarget, /// The type of node that this is. type_id: NodeTypeId, @@ -108,7 +109,7 @@ pub struct Node { /// /// Must be sent back to the layout task to be destroyed when this /// node is finalized. - pub layout_data: LayoutDataRef, + layout_data: LayoutDataRef, unique_id: RefCell, } @@ -1149,6 +1150,21 @@ impl Node { &self.eventtarget } + #[inline] + pub fn layout_data(&self) -> Ref> { + self.layout_data.borrow() + } + + #[inline] + pub fn layout_data_mut(&self) -> RefMut> { + self.layout_data.borrow_mut() + } + + #[inline] + pub unsafe fn layout_data_unchecked(&self) -> *const Option { + self.layout_data.borrow_unchecked() + } + // http://dom.spec.whatwg.org/#concept-node-adopt pub fn adopt(node: JSRef, document: JSRef) { // Step 1.