diff --git a/components/script/dom/domstringmap.rs b/components/script/dom/domstringmap.rs index 95f727c93cb..bed48031786 100644 --- a/components/script/dom/domstringmap.rs +++ b/components/script/dom/domstringmap.rs @@ -61,7 +61,6 @@ impl DOMStringMapMethods for DOMStringMap { // https://html.spec.whatwg.org/multipage/#the-domstringmap-interface:supported-property-names fn SupportedPropertyNames(&self) -> Vec { - // FIXME: unimplemented (https://github.com/servo/servo/issues/7273) - vec![] + self.element.supported_prop_names_custom_attr().iter().cloned().collect() } } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index b04082eae4d..ba2bcdacc16 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -27,6 +27,7 @@ use dom::node::{Node, SEQUENTIALLY_FOCUSABLE}; use dom::node::{document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; use msg::constellation_msg::FocusType; +use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::default::Default; use std::intrinsics; @@ -275,6 +276,45 @@ fn to_snake_case(name: DOMString) -> DOMString { attr_name } + +// https://html.spec.whatwg.org/multipage/#attr-data-* +// if this attribute is in snake case with a data- prefix, +// this function returns a name converted to camel case +// without the data prefix. + +fn to_camel_case(name: &str) -> Option { + if !name.starts_with("data-") { + return None; + } + let name = &name[5..]; + let has_uppercase = name.chars().any(|curr_char| { + curr_char.is_ascii() && curr_char.is_uppercase() + }); + if has_uppercase { + return None; + } + let mut result = "".to_owned(); + let mut name_chars = name.chars(); + while let Some(curr_char) = name_chars.next() { + //check for hyphen followed by character + if curr_char == '\x2d' { + if let Some(next_char) = name_chars.next() { + if next_char.is_ascii() && next_char.is_lowercase() { + result.push(next_char.to_ascii_uppercase()); + } else { + result.push(curr_char); + result.push(next_char); + } + } else { + result.push(curr_char); + } + } else { + result.push(curr_char); + } + } + Some(result) +} + impl HTMLElement { pub fn set_custom_attr(&self, name: DOMString, value: DOMString) -> ErrorResult { if name.chars() @@ -316,6 +356,14 @@ impl HTMLElement { _ => false, } } + + pub fn supported_prop_names_custom_attr(&self) -> Vec { + let element = self.upcast::(); + element.attrs().iter().map(JS::root).filter_map(|attr| { + let raw_name = attr.r().local_name(); + to_camel_case(&raw_name) + }).collect() + } } impl VirtualMethods for HTMLElement { diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs index 6070c0bb0c2..5c78de0ed51 100644 --- a/components/script/dom/namednodemap.rs +++ b/components/script/dom/namednodemap.rs @@ -85,8 +85,10 @@ impl NamedNodeMapMethods for NamedNodeMap { item } + // https://heycam.github.io/webidl/#dfn-supported-property-names fn SupportedPropertyNames(&self) -> Vec { - // FIXME: unimplemented (https://github.com/servo/servo/issues/7273) - vec![] + self.owner.attrs().iter().map(JS::root).map(|attr| { + (**attr.name()).to_owned() + }).collect() } } diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index d2d65fe522c..d642e0762be 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -13281,6 +13281,14 @@ "path": "dom/collections/HTMLCollection-supported-property-names.html", "url": "/dom/collections/HTMLCollection-supported-property-names.html" }, + { + "path": "dom/collections/domstringmap-supported-property-names.html", + "url": "/dom/collections/domstringmap-supported-property-names.html" + }, + { + "path": "dom/collections/namednodemap-supported-property-names.html", + "url": "/dom/collections/namednodemap-supported-property-names.html" + }, { "path": "dom/events/Event-constants.html", "url": "/dom/events/Event-constants.html" diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/dataset-enumeration.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/dataset-enumeration.html.ini deleted file mode 100644 index 7b228c9e6ea..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/dataset-enumeration.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[dataset-enumeration.html] - type: testharness - [A dataset should be enumeratable.] - expected: FAIL - - [Only attributes who qualify as dataset properties should be enumeratable in the dataset.] - expected: FAIL - diff --git a/tests/wpt/web-platform-tests/dom/collections/domstringmap-supported-property-names.html b/tests/wpt/web-platform-tests/dom/collections/domstringmap-supported-property-names.html new file mode 100644 index 00000000000..f84ee27ae29 --- /dev/null +++ b/tests/wpt/web-platform-tests/dom/collections/domstringmap-supported-property-names.html @@ -0,0 +1,54 @@ + + +DOMStringMap Test: Supported property names + + +
+ +
Simple
+ +
Simple
+ +
+ John Doe +
+ +
Jane Doe
+ +
Jim Doe
+ + \ No newline at end of file diff --git a/tests/wpt/web-platform-tests/dom/collections/namednodemap-supported-property-names.html b/tests/wpt/web-platform-tests/dom/collections/namednodemap-supported-property-names.html new file mode 100644 index 00000000000..2c5dee4efd6 --- /dev/null +++ b/tests/wpt/web-platform-tests/dom/collections/namednodemap-supported-property-names.html @@ -0,0 +1,30 @@ + + +NamedNodeMap Test: Supported property names + + +
+
Simple
+ + \ No newline at end of file