Skip to content

Commit

Permalink
Auto merge of #5490 - nox:namednodemap, r=jdm
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Apr 7, 2015
2 parents 48ee056 + 5d58dc8 commit e521860
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
3 changes: 3 additions & 0 deletions components/script/dom/bindings/error.rs
Expand Up @@ -34,6 +34,8 @@ pub enum Error {
InvalidCharacter,
/// NotSupportedError DOMException
NotSupported,
/// InUseAttributeError DOMException
InUseAttribute,
/// InvalidStateError DOMException
InvalidState,
/// SyntaxError DOMException
Expand Down Expand Up @@ -79,6 +81,7 @@ pub fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef,
Error::HierarchyRequest => DOMErrorName::HierarchyRequestError,
Error::InvalidCharacter => DOMErrorName::InvalidCharacterError,
Error::NotSupported => DOMErrorName::NotSupportedError,
Error::InUseAttribute => DOMErrorName::InUseAttributeError,
Error::InvalidState => DOMErrorName::InvalidStateError,
Error::Syntax => DOMErrorName::SyntaxError,
Error::Namespace => DOMErrorName::NamespaceError,
Expand Down
2 changes: 2 additions & 0 deletions components/script/dom/domexception.rs
Expand Up @@ -23,6 +23,7 @@ pub enum DOMErrorName {
NoModificationAllowedError = DOMExceptionConstants::NO_MODIFICATION_ALLOWED_ERR,
NotFoundError = DOMExceptionConstants::NOT_FOUND_ERR,
NotSupportedError = DOMExceptionConstants::NOT_SUPPORTED_ERR,
InUseAttributeError = DOMExceptionConstants::INUSE_ATTRIBUTE_ERR,
InvalidStateError = DOMExceptionConstants::INVALID_STATE_ERR,
SyntaxError = DOMExceptionConstants::SYNTAX_ERR,
InvalidModificationError = DOMExceptionConstants::INVALID_MODIFICATION_ERR,
Expand Down Expand Up @@ -83,6 +84,7 @@ impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> {
DOMErrorName::NoModificationAllowedError => "The object can not be modified.",
DOMErrorName::NotFoundError => "The object can not be found here.",
DOMErrorName::NotSupportedError => "The operation is not supported.",
DOMErrorName::InUseAttributeError => "The attribute already in use.",
DOMErrorName::InvalidStateError => "The object is in an invalid state.",
DOMErrorName::SyntaxError => "The string did not match the expected pattern.",
DOMErrorName::InvalidModificationError => "The object can not be modified in this way.",
Expand Down
32 changes: 31 additions & 1 deletion components/script/dom/namednodemap.rs
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
}
}

10 changes: 10 additions & 0 deletions components/script/dom/webidls/NamedNodeMap.webidl
Expand Up @@ -5,4 +5,14 @@
interface NamedNodeMap {
readonly attribute unsigned long length;
getter Attr? item(unsigned long index);
getter Attr? getNamedItem(DOMString name);
Attr? getNamedItemNS(DOMString? namespace, DOMString localName);
//[Throws]
//Attr? setNamedItem(Attr attr);
//[Throws]
//Attr? setNamedItemNS(Attr attr);
//[Throws]
//Attr removeNamedItem(DOMString name);
//[Throws]
//Attr removeNamedItemNS(DOMString? namespace, DOMString name);
};
6 changes: 0 additions & 6 deletions tests/wpt/metadata/dom/interfaces.html.ini
Expand Up @@ -384,12 +384,6 @@
[Element interface: calling after([object Object\],[object Object\]) on element with too few arguments must throw TypeError]
expected: FAIL
[NamedNodeMap interface: operation getNamedItem(DOMString)]
expected: FAIL
[NamedNodeMap interface: operation getNamedItemNS(DOMString,DOMString)]
expected: FAIL
[NamedNodeMap interface: operation setNamedItem(Attr)]
expected: FAIL
Expand Down

0 comments on commit e521860

Please sign in to comment.