mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Implement NamedNodeMap::getNamedItem*() (fixes #5454)
This commit is contained in:
parent
de97b98c14
commit
5d58dc8f54
3 changed files with 33 additions and 9 deletions
|
@ -8,8 +8,12 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
|||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::element::{Element, ElementHelpers};
|
||||
use dom::element::{AttributeHandlers, Element, ElementHelpers};
|
||||
use dom::window::Window;
|
||||
use util::namespace;
|
||||
use util::str::DOMString;
|
||||
|
||||
use string_cache::Atom;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct NamedNodeMap {
|
||||
|
@ -32,6 +36,7 @@ impl NamedNodeMap {
|
|||
}
|
||||
|
||||
impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-length
|
||||
fn Length(self) -> u32 {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
|
@ -40,6 +45,7 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
|||
attrs.len() as u32
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
||||
fn Item(self, index: u32) -> Option<Temporary<Attr>> {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
|
@ -48,10 +54,34 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
|||
attrs.as_slice().get(index as usize).map(|x| Temporary::new(x.clone()))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem
|
||||
fn GetNamedItem(self, name: DOMString) -> Option<Temporary<Attr>> {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let owner = owner.r();
|
||||
let name = owner.parsed_name(name);
|
||||
owner.get_attribute_by_name(&Atom::from_slice(&name))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns
|
||||
fn GetNamedItemNS(self, namespace: Option<DOMString>, name: DOMString) -> Option<Temporary<Attr>> {
|
||||
let owner = self.owner.root();
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let owner = owner.r();
|
||||
let ns = namespace::from_domstring(namespace);
|
||||
owner.get_attribute(&ns, &Atom::from_slice(&name))
|
||||
}
|
||||
|
||||
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||
let item = self.Item(index);
|
||||
*found = item.is_some();
|
||||
item
|
||||
}
|
||||
|
||||
fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||
let item = self.GetNamedItem(name);
|
||||
*found = item.is_some();
|
||||
item
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue