diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs
index bb4cffc227e..3f176f4bc31 100644
--- a/src/components/script/dom/htmlcollection.rs
+++ b/src/components/script/dom/htmlcollection.rs
@@ -2,10 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use dom::bindings::codegen::InheritTypes::{ElementCast};
use dom::bindings::codegen::HTMLCollectionBinding;
use dom::bindings::js::JS;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
+use dom::node::{Node, NodeHelpers};
use dom::window::Window;
use servo_util::str::DOMString;
@@ -31,6 +33,21 @@ impl HTMLCollection {
}
}
+impl HTMLCollection {
+ pub fn create(window: &JS, root: &JS, predicate: |elem: &JS| -> bool) -> JS {
+ let mut elements = ~[];
+ for child in root.traverse_preorder() {
+ if child.is_element() {
+ let elem: JS = ElementCast::to(&child);
+ if predicate(&elem) {
+ elements.push(elem);
+ }
+ }
+ }
+ HTMLCollection::new(window, elements)
+ }
+}
+
impl HTMLCollection {
// http://dom.spec.whatwg.org/#dom-htmlcollection-length
pub fn Length(&self) -> u32 {