auto merge of #2031 : saneyuki/servo/2027, r=jdm

Fix #2027

@jdm
This change will decrease the generics for `Document::create_collection`.
Do you have any good idea to avoid this?

Or don't we have to consider it now?
This commit is contained in:
bors-servo 2014-04-03 12:01:49 -04:00
commit 897c679be2

View file

@ -563,31 +563,21 @@ impl Document {
HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter) HTMLCollection::create(&self.window, &NodeCast::from(abstract_self), filter)
} }
pub fn create_collection<T>(&self, callback: |elem: &JS<Node>| -> Option<JS<T>>) -> ~[JS<T>] { pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> {
let mut nodes = ~[]; let mut nodes: ~[JS<Node>] = ~[];
match self.GetDocumentElement() { match self.GetDocumentElement() {
None => {}, None => {},
Some(root) => { Some(root) => {
let root: JS<Node> = NodeCast::from(&root); let root: JS<Node> = NodeCast::from(&root);
for child in root.traverse_preorder() { for child in root.traverse_preorder() {
match callback(&child) { if callback(&child) {
Some(node) => nodes.push(node), nodes.push(child.clone());
None => (),
} }
} }
} }
} }
nodes
}
pub fn createNodeList(&self, callback: |node: &JS<Node>| -> bool) -> JS<NodeList> { NodeList::new_simple_list(&self.window, nodes)
NodeList::new_simple_list(&self.window, self.create_collection(|node| {
if !callback(node) {
return None;
}
Some(node.clone())
}))
} }
pub fn content_changed(&self) { pub fn content_changed(&self) {