servo: Merge #14920 - Correctly handle unserializable shorthand (from upsuper:shorthand-variable); r=emilio
authorXidorn Quan <me@upsuper.org>
Mon, 09 Jan 2017 20:10:32 -0800
changeset 340591 773481e1e52bb5aeaeedee059412e955e09a37c0
parent 340590 3d3a0334f73bfa77209fae12f17d716bdcb703ca
child 340592 51ab690dd564a7dd3400f368b2b576f5c5d8a4c4
push id86548
push userkwierso@gmail.com
push dateSat, 04 Feb 2017 01:35:21 +0000
treeherdermozilla-inbound@e7b96d015d03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1329533
servo: Merge #14920 - Correctly handle unserializable shorthand (from upsuper:shorthand-variable); r=emilio get_shorthand_appendable_value doesn't always return a serializable value. This change makes it handle that case correctly. This change also updates step number in property_value_to_css to reflect the latest spec. --- <!-- 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 stylo [bug 1329533](https://bugzilla.mozilla.org/show_bug.cgi?id=1329533) <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 867df7f3d7a89b48de76106601cbc5e474acb9dd
servo/components/style/properties/declaration_block.rs
--- a/servo/components/style/properties/declaration_block.rs
+++ b/servo/components/style/properties/declaration_block.rs
@@ -81,62 +81,64 @@ impl PropertyDeclarationBlock {
     }
 
     /// Find the value of the given property in this block and serialize it
     ///
     /// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
     pub fn property_value_to_css<W>(&self, property: &PropertyId, dest: &mut W) -> fmt::Result
         where W: fmt::Write,
     {
-        // Step 1: done when parsing a string to PropertyId
+        // Step 1.1: done when parsing a string to PropertyId
 
-        // Step 2
+        // Step 1.2
         match property.as_shorthand() {
             Ok(shorthand) => {
-                // Step 2.1
+                // Step 1.2.1
                 let mut list = Vec::new();
                 let mut important_count = 0;
 
-                // Step 2.2
+                // Step 1.2.2
                 for &longhand in shorthand.longhands() {
-                    // Step 2.2.1
+                    // Step 1.2.2.1
                     let declaration = self.get(PropertyDeclarationId::Longhand(longhand));
 
-                    // Step 2.2.2 & 2.2.3
+                    // Step 1.2.2.2 & 1.2.2.3
                     match declaration {
                         Some(&(ref declaration, importance)) => {
                             list.push(declaration);
                             if importance.important() {
                                 important_count += 1;
                             }
                         },
                         None => return Ok(()),
                     }
                 }
 
-                // Step 3.3.2.4
                 // If there is one or more longhand with important, and one or more
                 // without important, we don't serialize it as a shorthand.
                 if important_count > 0 && important_count != list.len() {
                     return Ok(());
                 }
 
-                // Step 2.3
+                // Step 1.2.3
                 // We don't print !important when serializing individual properties,
                 // so we treat this as a normal-importance property
                 let importance = Importance::Normal;
-                let appendable_value = shorthand.get_shorthand_appendable_value(list).unwrap();
-                append_declaration_value(dest, appendable_value, importance, false)
+                match shorthand.get_shorthand_appendable_value(list) {
+                    Some(appendable_value) =>
+                        append_declaration_value(dest, appendable_value, importance, false),
+                    None => return Ok(()),
+                }
             }
             Err(longhand_or_custom) => {
                 if let Some(&(ref value, _importance)) = self.get(longhand_or_custom) {
-                    // Step 3
+                    // Step 2
                     value.to_css(dest)
                 } else {
-                    // Step 4
+                    // Step 3
                     Ok(())
                 }
             }
         }
     }
 
     /// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority
     pub fn property_priority(&self, property: &PropertyId) -> Importance {