From fbe2e4b6260c1858289cc8d9a89160191725341d Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 2 Apr 2015 19:17:52 +0200 Subject: [PATCH 1/3] Add dom::bindings::error::Error::InUseAttribute --- components/script/dom/bindings/error.rs | 3 +++ components/script/dom/domexception.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index c62216d4683..b6a3497d019 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -34,6 +34,8 @@ pub enum Error { InvalidCharacter, /// NotSupportedError DOMException NotSupported, + /// InUseAttributeError DOMException + InUseAttribute, /// InvalidStateError DOMException InvalidState, /// SyntaxError DOMException @@ -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::NamespaceError => DOMErrorName::NamespaceError, diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs index 59f8c0a0743..d066021e304 100644 --- a/components/script/dom/domexception.rs +++ b/components/script/dom/domexception.rs @@ -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, @@ -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.", From de97b98c14ddc49f03859742f0bb4ec448062fc5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 2 Apr 2015 19:21:39 +0200 Subject: [PATCH 2/3] Add missing items to NamedNodeMap --- components/script/dom/webidls/NamedNodeMap.webidl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/script/dom/webidls/NamedNodeMap.webidl b/components/script/dom/webidls/NamedNodeMap.webidl index 636c4a2782f..9279af57de5 100644 --- a/components/script/dom/webidls/NamedNodeMap.webidl +++ b/components/script/dom/webidls/NamedNodeMap.webidl @@ -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); }; From 5d58dc8f54774a6f9a9cfd364247b0d0d3834bd2 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 2 Apr 2015 19:35:34 +0200 Subject: [PATCH 3/3] Implement NamedNodeMap::getNamedItem*() (fixes #5454) --- components/script/dom/namednodemap.rs | 32 ++++++++++++++++++- .../script/dom/webidls/NamedNodeMap.webidl | 4 +-- tests/wpt/metadata/dom/interfaces.html.ini | 6 ---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs index bfa8f1652f1..239fff86fbb 100644 --- a/components/script/dom/namednodemap.rs +++ b/components/script/dom/namednodemap.rs @@ -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> { 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> { + 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, name: DOMString) -> Option> { + 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> { let item = self.Item(index); *found = item.is_some(); item } + + fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option> { + let item = self.GetNamedItem(name); + *found = item.is_some(); + item + } } diff --git a/components/script/dom/webidls/NamedNodeMap.webidl b/components/script/dom/webidls/NamedNodeMap.webidl index 9279af57de5..f15151b8ce9 100644 --- a/components/script/dom/webidls/NamedNodeMap.webidl +++ b/components/script/dom/webidls/NamedNodeMap.webidl @@ -5,8 +5,8 @@ interface NamedNodeMap { readonly attribute unsigned long length; getter Attr? item(unsigned long index); - //getter Attr? getNamedItem(DOMString name); - //Attr? getNamedItemNS(DOMString? namespace, DOMString localName); + getter Attr? getNamedItem(DOMString name); + Attr? getNamedItemNS(DOMString? namespace, DOMString localName); //[Throws] //Attr? setNamedItem(Attr attr); //[Throws] diff --git a/tests/wpt/metadata/dom/interfaces.html.ini b/tests/wpt/metadata/dom/interfaces.html.ini index 5c7e946e5d1..c3913ed9046 100644 --- a/tests/wpt/metadata/dom/interfaces.html.ini +++ b/tests/wpt/metadata/dom/interfaces.html.ini @@ -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