Bug 1442195 - Don't crash when finding an unexpected default font type. r=xidorn, a=jcristau
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 14 May 2018 15:19:34 +0200
changeset 805970 9587d5f8a452b9ea73181cb72846956c0242bf2c
parent 805969 a41872ae8adb19002a7416146299ce4c0f5d0c8a
child 805971 d6d4fa13e5c885a8cd014aeea236e7b9f85df0f8
push id112832
push userbballo@mozilla.com
push dateFri, 08 Jun 2018 21:11:22 +0000
reviewersxidorn, jcristau
bugs1442195
milestone60.0.2
Bug 1442195 - Don't crash when finding an unexpected default font type. r=xidorn, a=jcristau For now just return sans-serif, though as the FIXME comment indicates we should probably just carry around the font-name instead. MozReview-Commit-ID: CIPbV3R5Ul
servo/components/style/properties/gecko.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2328,24 +2328,35 @@ fn static_assert() {
     pub fn clone_font_family(&self) -> longhands::font_family::computed_value::T {
         use gecko_bindings::structs::FontFamilyType;
         use values::computed::font::{FontFamily, SingleFontFamily, FontFamilyList};
 
         let fontlist = &self.gecko.mFont.fontlist;
         let shared_fontlist = unsafe { fontlist.mFontlist.mBasePtr.to_safe() };
 
         if shared_fontlist.mNames.is_empty() {
-            let default = match fontlist.mDefaultFontType {
+            let default = fontlist.mDefaultFontType;
+            let default = match default {
                 FontFamilyType::eFamily_serif => {
                     SingleFontFamily::Generic(atom!("serif"))
                 }
-                FontFamilyType::eFamily_sans_serif => {
+                _ => {
+                    // This can break with some combinations of user prefs, see
+                    // bug 1442195 for example. It doesn't really matter in this
+                    // case...
+                    //
+                    // FIXME(emilio): Probably should be storing the whole
+                    // default font name instead though.
+                    debug_assert_eq!(
+                        default,
+                        FontFamilyType::eFamily_sans_serif,
+                        "Default generic should be serif or sans-serif"
+                    );
                     SingleFontFamily::Generic(atom!("sans-serif"))
                 }
-                _ => panic!("Default generic must be serif or sans-serif"),
             };
             FontFamily(FontFamilyList::new(Box::new([default])))
         } else {
             FontFamily(FontFamilyList(shared_fontlist))
         }
     }
 
     pub fn unzoom_fonts(&mut self, device: &Device) {