Auto merge of #8068 - martiansideofthemoon:my-code-fix, r=Manishearth

Implementing getAttributeNode() and similar methods

Attempting to solve #8066 Does it look good so far @Manishearth ?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8068)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-19 07:58:41 -06:00
commit 2e308e9ecc
4 changed files with 18 additions and 32 deletions

View file

@ -1182,7 +1182,7 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-getattribute
fn GetAttribute(&self, name: DOMString) -> Option<DOMString> {
self.get_attribute_by_name(name)
self.GetAttributeNode(name)
.map(|s| s.r().Value())
}
@ -1190,9 +1190,21 @@ impl ElementMethods for Element {
fn GetAttributeNS(&self,
namespace: Option<DOMString>,
local_name: DOMString) -> Option<DOMString> {
self.GetAttributeNodeNS(namespace, local_name)
.map(|attr| attr.r().Value())
}
// https://dom.spec.whatwg.org/#dom-element-getattributenode
fn GetAttributeNode(&self, name: DOMString) -> Option<Root<Attr>> {
self.get_attribute_by_name(name)
}
// https://dom.spec.whatwg.org/#dom-element-getattributenodens
fn GetAttributeNodeNS(&self,
namespace: Option<DOMString>,
local_name: DOMString) -> Option<Root<Attr>> {
let namespace = &namespace_from_domstring(namespace);
self.get_attribute(namespace, &Atom::from_slice(&local_name))
.map(|attr| attr.r().Value())
}
// https://dom.spec.whatwg.org/#dom-element-setattribute

View file

@ -37,6 +37,10 @@ interface Element : Node {
DOMString? getAttribute(DOMString name);
[Pure]
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[Pure]
Attr? getAttributeNode(DOMString name);
[Pure]
Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
[Throws]
void setAttribute(DOMString name, DOMString value);
[Throws]

View file

@ -150,12 +150,6 @@
[Element interface: operation hasAttributes()]
expected: FAIL
[Element interface: operation getAttributeNode(DOMString)]
expected: FAIL
[Element interface: operation getAttributeNodeNS(DOMString,DOMString)]
expected: FAIL
[Element interface: operation setAttributeNode(Attr)]
expected: FAIL
@ -174,18 +168,6 @@
[Element interface: element must inherit property "hasAttributes" with the proper type (7)]
expected: FAIL
[Element interface: element must inherit property "getAttributeNode" with the proper type (17)]
expected: FAIL
[Element interface: calling getAttributeNode(DOMString) on element with too few arguments must throw TypeError]
expected: FAIL
[Element interface: element must inherit property "getAttributeNodeNS" with the proper type (18)]
expected: FAIL
[Element interface: calling getAttributeNodeNS(DOMString,DOMString) on element with too few arguments must throw TypeError]
expected: FAIL
[Element interface: element must inherit property "setAttributeNode" with the proper type (19)]
expected: FAIL

View file

@ -2064,18 +2064,6 @@
[Element interface: document.createElement("noscript") must inherit property "hasAttributes" with the proper type (7)]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "getAttributeNode" with the proper type (17)]
expected: FAIL
[Element interface: calling getAttributeNode(DOMString) on document.createElement("noscript") with too few arguments must throw TypeError]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "getAttributeNodeNS" with the proper type (18)]
expected: FAIL
[Element interface: calling getAttributeNodeNS(DOMString,DOMString) on document.createElement("noscript") with too few arguments must throw TypeError]
expected: FAIL
[Element interface: document.createElement("noscript") must inherit property "setAttributeNode" with the proper type (19)]
expected: FAIL