aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-12-09 13:33:53 -0400
committerMs2ger <ms2ger@gmail.com>2014-12-23 14:23:30 +0100
commit285a06ff590b194f28da09971982b7c726f55bba (patch)
treeea93d2c59ff86f6b31e205cfbcf31b97e93b9ffc /components/script/dom/element.rs
parent63ed36cfce42ae4491da9b50ab05c626542c15f1 (diff)
downloadservo-285a06ff590b194f28da09971982b7c726f55bba.tar.gz
servo-285a06ff590b194f28da09971982b7c726f55bba.zip
Implement Element::set_custom_attribute.
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 275a72161ce..1c069ea3aa3 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -619,6 +619,7 @@ pub trait AttributeHandlers {
value: DOMString,
prefix: Option<DOMString>);
fn set_attribute(self, name: &Atom, value: AttrValue);
+ fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult;
fn do_set_attribute(self, local_name: Atom, value: AttrValue,
name: Atom, namespace: Namespace,
prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool);
@@ -688,6 +689,23 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
ns!(""), None, |attr| *attr.local_name() == *name);
}
+ // https://html.spec.whatwg.org/multipage/dom.html#attr-data-*
+ fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult {
+ // Step 1.
+ match xml_name_type(name.as_slice()) {
+ InvalidXMLName => return Err(InvalidCharacter),
+ _ => {}
+ }
+
+ // Steps 2-5.
+ let name = Atom::from_slice(name.as_slice());
+ let value = self.parse_attribute(&ns!(""), &name, value);
+ self.do_set_attribute(name.clone(), value, name.clone(), ns!(""), None, |attr| {
+ *attr.name() == name && *attr.namespace() == ns!("")
+ });
+ Ok(())
+ }
+
fn do_set_attribute(self, local_name: Atom, value: AttrValue,
name: Atom, namespace: Namespace,
prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool) {
@@ -943,7 +961,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let name = Atom::from_slice(name.as_slice());
let value = self.parse_attribute(&ns!(""), &name, value);
self.do_set_attribute(name.clone(), value, name.clone(), ns!(""), None, |attr| {
- attr.name().as_slice() == name.as_slice()
+ *attr.name() == name
});
Ok(())
}