diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 2d5582e73f1..e627ee55911 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -162,9 +162,7 @@ impl Reflectable for Document { impl Document { pub fn GetDocumentElement(&self) -> Option { - do self.node.children().find |c| { - c.is_element() - } + self.node.child_elements().next() } fn get_cx(&self) -> *JSContext { diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index f9f11a280c7..b002715eb1c 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -25,6 +25,7 @@ use std::cast::transmute; use std::cast; use std::unstable::raw::Box; use std::util; +use std::iter::Filter; // // The basic Node structure @@ -486,6 +487,10 @@ impl<'self> AbstractNode { self.node().children() } + pub fn child_elements(&self) -> Filter { + self.node().child_elements() + } + pub fn is_in_doc(&self) -> bool { self.node().flags.is_in_doc() } @@ -749,6 +754,10 @@ impl Node { } } + pub fn child_elements(&self) -> Filter { + self.children().filter(|node| node.is_element()) + } + pub fn reflect_node (node: @mut N, document: AbstractDocument, @@ -1041,11 +1050,13 @@ impl Node { if node.children().any(|c| c.is_text()) { return Err(HierarchyRequest); } - match node.children().count(|c| c.is_element()) { + match node.child_elements().len() { 0 => (), // Step 6.1.2 1 => { - if parent.children().any(|c| c.is_element()) { + // FIXME: change to empty() when https://github.com/mozilla/rust/issues/11218 + // will be fixed + if parent.child_elements().len() > 0 { return Err(HierarchyRequest); } if inclusively_followed_by_doctype(child) { @@ -1058,7 +1069,9 @@ impl Node { }, // Step 6.2 ElementNodeTypeId(_) => { - if parent.children().any(|c| c.is_element()) { + // FIXME: change to empty() when https://github.com/mozilla/rust/issues/11218 + // will be fixed + if parent.child_elements().len() > 0 { return Err(HierarchyRequest); } if inclusively_followed_by_doctype(child) { @@ -1079,7 +1092,9 @@ impl Node { } }, None => { - if parent.children().any(|c| c.is_element()) { + // FIXME: change to empty() when https://github.com/mozilla/rust/issues/11218 + // will be fixed + if parent.child_elements().len() > 0 { return Err(HierarchyRequest); } },