mirror of
https://github.com/servo/servo.git
synced 2025-06-25 17:44:33 +01:00
Reimplement SetAttribute.
This commit is contained in:
parent
883d67882a
commit
bf73a47ce0
2 changed files with 25 additions and 2 deletions
|
@ -299,13 +299,27 @@ impl AttributeHandlers for JS<Element> {
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-element-setattribute
|
// http://dom.spec.whatwg.org/#dom-element-setattribute
|
||||||
fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult {
|
fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||||
// FIXME: If name does not match the Name production in XML, throw an "InvalidCharacterError" exception.
|
let node: JS<Node> = NodeCast::from(self);
|
||||||
|
node.get().wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
|
// Step 1.
|
||||||
|
match xml_name_type(name) {
|
||||||
|
InvalidXMLName => return Err(InvalidCharacter),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
let name = if self.get().html_element_in_html_document() {
|
let name = if self.get().html_element_in_html_document() {
|
||||||
name.to_ascii_lower()
|
name.to_ascii_lower()
|
||||||
} else {
|
} else {
|
||||||
name
|
name
|
||||||
};
|
};
|
||||||
self.set_attr(name, value)
|
|
||||||
|
// Step 3-5.
|
||||||
|
self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| {
|
||||||
|
attr.get().name == name
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>,
|
fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>,
|
||||||
|
|
|
@ -41,6 +41,15 @@
|
||||||
is(r2, null, "test4-1, Element.removeAttribute().");
|
is(r2, null, "test4-1, Element.removeAttribute().");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
test.setAttribute("xml:lang", "en");
|
||||||
|
|
||||||
|
let r1 = test.hasAttribute("xml:lang");
|
||||||
|
is(r1, true, "test5-0, Element.setAttribute('xml:lang').");
|
||||||
|
let r2 = test.getAttribute("xml:lang");
|
||||||
|
is_not(r2, null, "test5-1, Element.setAttribute('xml:lang').");
|
||||||
|
}
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue