servo: Merge #17799 - Don't panic when body element don't have style data (from upsuper:body-color-panic); r=heycam
authorXidorn Quan <me@upsuper.org>
Thu, 20 Jul 2017 19:23:19 -0700
changeset 418825 7cccfd368ddad5de94c828eabc1ea9919d537805
parent 418824 6ed469370daa8ca35c2d71c0792c585e7bb2daa5
child 418826 1ba89b033552bf89c9a8c47903260026d63a9e97
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1381233
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17799 - Don't panic when body element don't have style data (from upsuper:body-color-panic); r=heycam This is the Servo side change of [bug 1381233](https://bugzilla.mozilla.org/show_bug.cgi?id=1381233). Source-Repo: https://github.com/servo/servo Source-Revision: fafb8476e87af305d375a27fd0d8cf7e10c9d2d5
servo/components/style/values/specified/color.rs
--- a/servo/components/style/values/specified/color.rs
+++ b/servo/components/style/values/specified/color.rs
@@ -264,26 +264,22 @@ impl ToComputedValue for Color {
                 })
             }
             #[cfg(feature = "gecko")]
             Color::InheritFromBodyQuirk => {
                 use dom::TElement;
                 use gecko::wrapper::GeckoElement;
                 use gecko_bindings::bindings::Gecko_GetBody;
                 let pres_context = _context.device().pres_context();
-                let body = unsafe {
-                    Gecko_GetBody(pres_context)
-                };
-                if let Some(body) = body {
-                    let wrap = GeckoElement(body);
-                    let borrow = wrap.borrow_data();
-                    ComputedColor::rgba(borrow.as_ref().unwrap()
-                                              .styles.primary()
-                                              .get_color()
-                                              .clone_color())
+                let body = unsafe { Gecko_GetBody(pres_context) }.map(GeckoElement);
+                let data = body.as_ref().and_then(|wrap| wrap.borrow_data());
+                if let Some(data) = data {
+                    ComputedColor::rgba(data.styles.primary()
+                                            .get_color()
+                                            .clone_color())
                 } else {
                     convert_nscolor_to_computedcolor(pres_context.mDefaultColor)
                 }
             },
         }
     }
 
     fn from_computed_value(computed: &ComputedColor) -> Self {