mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +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::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::element::{Element, ElementHelpers};
|
use dom::element::{AttributeHandlers, Element, ElementHelpers};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
use util::namespace;
|
||||||
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
use string_cache::Atom;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct NamedNodeMap {
|
pub struct NamedNodeMap {
|
||||||
|
@ -32,6 +36,7 @@ impl NamedNodeMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
||||||
|
// https://dom.spec.whatwg.org/#dom-namednodemap-length
|
||||||
fn Length(self) -> u32 {
|
fn Length(self) -> u32 {
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
|
@ -40,6 +45,7 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
|
||||||
attrs.len() as u32
|
attrs.len() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-namednodemap-item
|
||||||
fn Item(self, index: u32) -> Option<Temporary<Attr>> {
|
fn Item(self, index: u32) -> Option<Temporary<Attr>> {
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// 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()))
|
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>> {
|
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||||
let item = self.Item(index);
|
let item = self.Item(index);
|
||||||
*found = item.is_some();
|
*found = item.is_some();
|
||||||
item
|
item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||||
|
let item = self.GetNamedItem(name);
|
||||||
|
*found = item.is_some();
|
||||||
|
item
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
interface NamedNodeMap {
|
interface NamedNodeMap {
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
getter Attr? item(unsigned long index);
|
getter Attr? item(unsigned long index);
|
||||||
//getter Attr? getNamedItem(DOMString name);
|
getter Attr? getNamedItem(DOMString name);
|
||||||
//Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
|
Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
|
||||||
//[Throws]
|
//[Throws]
|
||||||
//Attr? setNamedItem(Attr attr);
|
//Attr? setNamedItem(Attr attr);
|
||||||
//[Throws]
|
//[Throws]
|
||||||
|
|
|
@ -384,12 +384,6 @@
|
||||||
[Element interface: calling after([object Object\],[object Object\]) on element with too few arguments must throw TypeError]
|
[Element interface: calling after([object Object\],[object Object\]) on element with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[NamedNodeMap interface: operation getNamedItem(DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[NamedNodeMap interface: operation getNamedItemNS(DOMString,DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[NamedNodeMap interface: operation setNamedItem(Attr)]
|
[NamedNodeMap interface: operation setNamedItem(Attr)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue