aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/cssstyledeclaration.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-08-29 00:55:29 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-08-30 19:07:19 +0200
commit7dfb336be8dae1e2be9b898c374b6715e2a00ac7 (patch)
tree775fbf5f78d812db39ddfab79c56731262d5aded /components/script/dom/cssstyledeclaration.rs
parent6e1523f4ae61c16578a462c2e5335cbc95a6ef04 (diff)
downloadservo-7dfb336be8dae1e2be9b898c374b6715e2a00ac7.tar.gz
servo-7dfb336be8dae1e2be9b898c374b6715e2a00ac7.zip
Use Option<T> to return from getters
This removes the cumbersome &mut bool argument and offers overall a more readable code.
Diffstat (limited to 'components/script/dom/cssstyledeclaration.rs')
-rw-r--r--components/script/dom/cssstyledeclaration.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index 076a2283b67..0335a7498c0 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -100,18 +100,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-item
fn Item(&self, index: u32) -> DOMString {
- let index = index as usize;
- let elem = self.owner.upcast::<Element>();
- let style_attribute = elem.style_attribute().borrow();
- style_attribute.as_ref().and_then(|declarations| {
- declarations.declarations.get(index)
- }).map(|&(ref declaration, importance)| {
- let mut css = declaration.to_css_string();
- if importance.important() {
- css += " !important";
- }
- DOMString::from(css)
- }).unwrap_or_else(DOMString::new)
+ self.IndexedGetter(index).unwrap_or_default()
}
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
@@ -333,10 +322,19 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
}
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
- fn IndexedGetter(&self, index: u32, found: &mut bool) -> DOMString {
- let rval = self.Item(index);
- *found = index < self.Length();
- rval
+ fn IndexedGetter(&self, index: u32) -> Option<DOMString> {
+ let index = index as usize;
+ let elem = self.owner.upcast::<Element>();
+ let style_attribute = elem.style_attribute().borrow();
+ style_attribute.as_ref().and_then(|declarations| {
+ declarations.declarations.get(index)
+ }).map(|&(ref declaration, importance)| {
+ let mut css = declaration.to_css_string();
+ if importance.important() {
+ css += " !important";
+ }
+ DOMString::from(css)
+ })
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext