Auto merge of #17855 - asajeffrey:script-implement-more-stylepropertymaypreadonly, r=emilio

Implement getProperties for StylePropertyMapReadOnly

<!-- Please describe your changes on the following line: -->

Implement `getProperties` for `StylePropertyMapReadOnly`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #17579.
- [X] These changes do not require tests because the existing css-paint-api tests catch this (rather annoyingly, they all fail for different reasons, sigh)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17855)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-07 12:29:55 -05:00 committed by GitHub
commit b07f06ce92
5 changed files with 32 additions and 4 deletions

View file

@ -13,8 +13,10 @@ use dom::cssstylevalue::CSSStyleValue;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use servo_atoms::Atom; use servo_atoms::Atom;
use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use std::iter::Iterator; use std::iter::Iterator;
use style::custom_properties;
#[dom_struct] #[dom_struct]
pub struct StylePropertyMapReadOnly { pub struct StylePropertyMapReadOnly {
@ -63,4 +65,29 @@ impl StylePropertyMapReadOnlyMethods for StylePropertyMapReadOnly {
// TODO: avoid constructing an Atom // TODO: avoid constructing an Atom
self.entries.contains_key(&Atom::from(property)) self.entries.contains_key(&Atom::from(property))
} }
/// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-getproperties
fn GetProperties(&self) -> Vec<DOMString> {
let mut result: Vec<DOMString> = self.entries.keys()
.map(|key| DOMString::from(&**key))
.collect();
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-getproperties
// requires this sort order
result.sort_by(|key1, key2| {
if let Ok(key1) = custom_properties::parse_name(key1) {
if let Ok(key2) = custom_properties::parse_name(key2) {
key1.cmp(key2)
} else {
Ordering::Greater
}
} else {
if let Ok(_) = custom_properties::parse_name(key2) {
Ordering::Less
} else {
key1.cmp(key2)
}
}
});
result
}
} }

View file

@ -10,6 +10,7 @@ interface StylePropertyMapReadOnly {
// sequence<CSSStyleValue> getAll(DOMString property); // sequence<CSSStyleValue> getAll(DOMString property);
boolean has(DOMString property); boolean has(DOMString property);
// iterable<DOMString, (CSSStyleValue or sequence<CSSStyleValue>)>; // iterable<DOMString, (CSSStyleValue or sequence<CSSStyleValue>)>;
// sequence<DOMString> getProperties(); sequence<DOMString> getProperties();
// https://github.com/w3c/css-houdini-drafts/issues/268
// stringifier; // stringifier;
}; };

View file

@ -1,4 +1,4 @@
[style-background-image.html] [style-background-image.html]
type: reftest type: reftest
expected: FAIL expected: FAIL
bug: https://github.com/servo/servo/issues/17579 bug: https://github.com/servo/servo/issues/17378

View file

@ -1,4 +1,4 @@
[style-before-pseudo.html] [style-before-pseudo.html]
type: reftest type: reftest
expected: FAIL expected: FAIL
bug: https://github.com/servo/servo/issues/17579 bug: https://github.com/servo/servo/issues/17854

View file

@ -1,4 +1,4 @@
[style-first-letter-pseudo.html] [style-first-letter-pseudo.html]
type: reftest type: reftest
expected: FAIL expected: FAIL
bug: https://github.com/servo/servo/issues/17579 bug: https://github.com/servo/servo/issues/17854