aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2013-10-21 15:58:16 +0200
committerMs2ger <ms2ger@gmail.com>2013-10-21 15:58:16 +0200
commit364256e359c275b07d1daefaf48382aa8efdd53c (patch)
tree336b2d98021532fa4e4f7fa4716b22e90caf02f6 /src/components/script
parent5c725b31af4632407c201ae2727698a06e0bfd78 (diff)
downloadservo-364256e359c275b07d1daefaf48382aa8efdd53c.tar.gz
servo-364256e359c275b07d1daefaf48382aa8efdd53c.zip
Replace Node::{with_base, with_mut_base} by Node::{node, mut_node}.
Diffstat (limited to 'src/components/script')
-rw-r--r--src/components/script/dom/bindings/node.rs12
-rw-r--r--src/components/script/dom/document.rs16
-rw-r--r--src/components/script/dom/node.rs91
3 files changed, 51 insertions, 68 deletions
diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs
index f0eba2a341a..5adf545f14c 100644
--- a/src/components/script/dom/bindings/node.rs
+++ b/src/components/script/dom/bindings/node.rs
@@ -101,15 +101,11 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> *JSObject
impl Reflectable for AbstractNode<ScriptView> {
fn reflector<'a>(&'a self) -> &'a Reflector {
- do self.with_base |base| {
- unsafe { cast::transmute(base.reflector()) }
- }
+ self.node().reflector()
}
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
- do self.with_mut_base |base| {
- unsafe { cast::transmute(base.reflector()) }
- }
+ self.mut_node().mut_reflector()
}
fn wrap_object_shared(@mut self, _cx: *JSContext, _scope: *JSObject) -> *JSObject {
@@ -117,9 +113,7 @@ impl Reflectable for AbstractNode<ScriptView> {
}
fn GetParentObject(&self, cx: *JSContext) -> Option<@mut Reflectable> {
- do self.with_mut_base |base| {
- base.GetParentObject(cx)
- }
+ self.node().GetParentObject(cx)
}
}
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index 931221cabe0..59a24c879c8 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -88,11 +88,9 @@ impl AbstractDocument {
}
pub fn set_root(&self, root: AbstractNode<ScriptView>) {
- assert!(root.traverse_preorder().all(|node| {
- do node.with_base |node| {
- node.owner_doc() == *self
- }
- }));
+ assert!(do root.traverse_preorder().all |node| {
+ node.node().owner_doc() == *self
+ });
self.with_mut_base(|document| {
document.root = Some(root);
// Register elements having "id" attribute to the owner doc.
@@ -561,11 +559,9 @@ impl Traceable for Document {
do "root".to_c_str().with_ref |name| {
(*tracer).debugPrintArg = name as *libc::c_void;
debug!("tracing root node");
- do root.with_base |node| {
- JS_CallTracer(tracer as *JSTracer,
- node.reflector_.object,
- JSTRACE_OBJECT as u32);
- }
+ JS_CallTracer(tracer as *JSTracer,
+ root.reflector().get_jsobject(),
+ JSTRACE_OBJECT as u32);
}
}
}
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index d0b0ec81671..6583cf6985b 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -52,7 +52,7 @@ pub struct LayoutView;
/// FIXME: This should be replaced with a trait once they can inherit from structs.
#[deriving(Eq)]
pub struct AbstractNode<View> {
- priv obj: *mut Node<View>,
+ priv obj: *mut Box<Node<View>>,
}
pub struct AbstractNodeChildrenIterator<View> {
@@ -115,6 +115,18 @@ impl<View> Clone for AbstractNode<View> {
}
impl<View> TreeNodeRef<Node<View>> for AbstractNode<View> {
+ fn node<'a>(&'a self) -> &'a Node<View> {
+ unsafe {
+ &(*self.obj).data
+ }
+ }
+
+ fn mut_node<'a>(&'a self) -> &'a mut Node<View> {
+ unsafe {
+ &mut (*self.obj).data
+ }
+ }
+
fn parent_node(node: &Node<View>) -> Option<AbstractNode<View>> {
node.parent_node
}
@@ -147,15 +159,6 @@ impl<View> TreeNodeRef<Node<View>> for AbstractNode<View> {
node.next_sibling = new_next_sibling
}
- // FIXME: The duplication between `with_base` and `with_mut_base` is ugly.
- fn with_base<R>(&self, callback: &fn(&Node<View>) -> R) -> R {
- self.transmute(callback)
- }
-
- fn with_mut_base<R>(&self, callback: &fn(&mut Node<View>) -> R) -> R {
- self.transmute_mut(callback)
- }
-
fn is_element(&self) -> bool {
match self.type_id() {
ElementNodeTypeId(*) => true,
@@ -194,7 +197,7 @@ impl<'self, View> AbstractNode<View> {
/// chain for nodes.
pub fn from_box<T>(ptr: *mut Box<T>) -> AbstractNode<View> {
AbstractNode {
- obj: ptr as *mut Node<View>
+ obj: ptr as *mut Box<Node<View>>
}
}
@@ -202,32 +205,32 @@ impl<'self, View> AbstractNode<View> {
/// Returns the type ID of this node. Fails if this node is borrowed mutably.
pub fn type_id(self) -> NodeTypeId {
- self.with_base(|b| b.type_id)
+ self.node().type_id
}
/// Returns the parent node of this node. Fails if this node is borrowed mutably.
pub fn parent_node(self) -> Option<AbstractNode<View>> {
- self.with_base(|b| b.parent_node)
+ self.node().parent_node
}
/// Returns the first child of this node. Fails if this node is borrowed mutably.
pub fn first_child(self) -> Option<AbstractNode<View>> {
- self.with_base(|b| b.first_child)
+ self.node().first_child
}
/// Returns the last child of this node. Fails if this node is borrowed mutably.
pub fn last_child(self) -> Option<AbstractNode<View>> {
- self.with_base(|b| b.last_child)
+ self.node().last_child
}
/// Returns the previous sibling of this node. Fails if this node is borrowed mutably.
pub fn prev_sibling(self) -> Option<AbstractNode<View>> {
- self.with_base(|b| b.prev_sibling)
+ self.node().prev_sibling
}
/// Returns the next sibling of this node. Fails if this node is borrowed mutably.
pub fn next_sibling(self) -> Option<AbstractNode<View>> {
- self.with_base(|b| b.next_sibling)
+ self.node().next_sibling
}
/// Is this node a root?
@@ -381,11 +384,11 @@ impl<'self, View> AbstractNode<View> {
self.type_id() == ElementNodeTypeId(HTMLStyleElementTypeId)
}
- pub unsafe fn raw_object(self) -> *mut Node<View> {
+ pub unsafe fn raw_object(self) -> *mut Box<Node<View>> {
self.obj
}
- pub fn from_raw(raw: *mut Node<View>) -> AbstractNode<View> {
+ pub fn from_raw(raw: *mut Box<Node<View>>) -> AbstractNode<View> {
AbstractNode {
obj: raw
}
@@ -425,27 +428,25 @@ impl<'self, View> AbstractNode<View> {
// Issue #1030: should not walk the tree
pub fn is_in_doc(&self) -> bool {
- do self.with_base |node| {
- do node.owner_doc().with_base |document| {
- match document.GetDocumentElement() {
- None => false,
- Some(root) => {
- let mut node = *self;
- let mut in_doc;
- loop {
- match node.parent_node() {
- Some(parent) => {
- node = parent;
- },
- None => {
- // Issue #1029: this is horrible.
- in_doc = unsafe { node.raw_object() as uint == root.raw_object() as uint };
- break;
- }
+ do self.node().owner_doc().with_base |document| {
+ match document.GetDocumentElement() {
+ None => false,
+ Some(root) => {
+ let mut node = *self;
+ let mut in_doc;
+ loop {
+ match node.parent_node() {
+ Some(parent) => {
+ node = parent;
+ },
+ None => {
+ // Issue #1029: this is horrible.
+ in_doc = unsafe { node.raw_object() as uint == root.raw_object() as uint };
+ break;
}
}
- in_doc
}
+ in_doc
}
}
}
@@ -486,9 +487,7 @@ impl Node<ScriptView> {
let mut cur_node = self.first_child;
while cur_node.is_some() {
for node in cur_node.unwrap().traverse_preorder() {
- do node.with_mut_base |node_base| {
- node_base.set_owner_doc(doc);
- }
+ node.mut_node().set_owner_doc(doc);
};
cur_node = cur_node.unwrap().next_sibling();
}
@@ -784,9 +783,7 @@ impl Node<ScriptView> {
// If the node already exists it is removed from current parent node.
node.parent_node().map(|parent| parent.remove_child(node));
abstract_self.add_child(node);
- do node.with_mut_base |node| {
- node.add_to_doc(abstract_self, self.owner_doc());
- }
+ node.mut_node().add_to_doc(node, self.owner_doc());
Ok(node)
}
@@ -949,14 +946,10 @@ impl AbstractNode<LayoutView> {
// Node. Also this makes it easier to switch to RWArc if we decide that is
// necessary.
pub fn read_layout_data<R>(self, blk: &fn(data: &LayoutData) -> R) -> R {
- do self.with_base |b| {
- blk(&b.layout_data)
- }
+ blk(&self.node().layout_data)
}
pub fn write_layout_data<R>(self, blk: &fn(data: &mut LayoutData) -> R) -> R {
- do self.with_mut_base |b| {
- blk(&mut b.layout_data)
- }
+ blk(&mut self.mut_node().layout_data)
}
}