aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/servo/dom/htmlcollection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/servo/dom/htmlcollection.rs')
-rw-r--r--src/components/servo/dom/htmlcollection.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/components/servo/dom/htmlcollection.rs b/src/components/servo/dom/htmlcollection.rs
new file mode 100644
index 00000000000..0641987b341
--- /dev/null
+++ b/src/components/servo/dom/htmlcollection.rs
@@ -0,0 +1,47 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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::utils::WrapperCache;
+use dom::bindings::utils::{DOMString, ErrorResult};
+use dom::node::AbstractNode;
+
+use js::jsapi::{JSObject, JSContext};
+
+pub struct HTMLCollection {
+ elements: ~[AbstractNode],
+ wrapper: WrapperCache
+}
+
+pub impl HTMLCollection {
+ fn new(elements: ~[AbstractNode]) -> @mut HTMLCollection {
+ let collection = @mut HTMLCollection {
+ elements: elements,
+ wrapper: WrapperCache::new()
+ };
+ collection.init_wrapper();
+ collection
+ }
+
+ fn Length(&self) -> u32 {
+ self.elements.len() as u32
+ }
+
+ fn Item(&self, index: u32) -> Option<AbstractNode> {
+ if index < self.Length() {
+ Some(self.elements[index])
+ } else {
+ None
+ }
+ }
+
+ fn NamedItem(&self, _cx: *JSContext, _name: DOMString, rv: &mut ErrorResult) -> *JSObject {
+ *rv = Ok(());
+ ptr::null()
+ }
+
+ fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<AbstractNode> {
+ *found = true;
+ self.Item(index)
+ }
+}