Files
tubestation/servo/components/script/dom/namednodemap.rs
Simon Sapin b3423c8393 servo: Merge #3487 - Upgrade Rust and enable style crate rustdoc (from servo:rustup-20140923); r=Ms2ger
The biggest language change is that enum variants now also reserve (for future use) a name in the type namespace, which must not collide with other types. Some things were renamed, and others qualified as `module::name`.

Source-Repo: https://github.com/servo/servo
Source-Revision: 7409685589c550ee7a9f94182f511acddab4c6fd
2014-09-29 10:45:27 -06:00

56 lines
1.7 KiB
Rust

/* 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::attr::Attr;
use dom::bindings::codegen::Bindings::NamedNodeMapBinding;
use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
use dom::window::Window;
#[jstraceable]
#[must_root]
pub struct NamedNodeMap {
reflector_: Reflector,
owner: JS<Element>,
}
impl NamedNodeMap {
fn new_inherited(elem: JSRef<Element>) -> NamedNodeMap {
NamedNodeMap {
reflector_: Reflector::new(),
owner: JS::from_rooted(elem),
}
}
pub fn new(window: JSRef<Window>, elem: JSRef<Element>) -> Temporary<NamedNodeMap> {
reflect_dom_object(box NamedNodeMap::new_inherited(elem),
&global::Window(window), NamedNodeMapBinding::Wrap)
}
}
impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
fn Length(self) -> u32 {
self.owner.root().attrs.borrow().len() as u32
}
fn Item(self, index: u32) -> Option<Temporary<Attr>> {
self.owner.root().attrs.borrow().as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
}
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
let item = self.Item(index);
*found = item.is_some();
item
}
}
impl Reflectable for NamedNodeMap {
fn reflector<'a>(&'a self) -> &'a Reflector {
&self.reflector_
}
}