Bug 1406222 - servo: Don't assume that inputs to compute_style_with_inputs have any rules. r=heycam, a=ritu
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 06 Oct 2017 01:53:12 -0500
changeset 432322 f10c0a18896e
parent 432321 5764aced3a40
child 432323 dcc4e8d773a4
push id7930
push userryanvm@gmail.com
push dateMon, 09 Oct 2017 19:21:46 +0000
treeherdermozilla-beta@b92b69f3503e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam, ritu
bugs1406222
milestone57.0
Bug 1406222 - servo: Don't assume that inputs to compute_style_with_inputs have any rules. r=heycam, a=ritu It could be a text style, which never has any rules attached to it. Source-Repo: https://github.com/servo/servo Source-Revision: 117dbfaac20d8a388cf3cf5d2bc103b9d6249ee8
servo/components/style/stylist.rs
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -891,22 +891,22 @@ impl Stylist {
         parent_style_ignoring_first_line: &ComputedValues,
         layout_parent_style: &ComputedValues,
         font_metrics: &FontMetricsProvider,
         cascade_flags: CascadeFlags
     ) -> Arc<ComputedValues> {
         // We need to compute visited values if we have visited rules or if our
         // parent has visited values.
         let visited_values = if inputs.visited_rules.is_some() || parent_style.get_visited_style().is_some() {
-            // Slightly annoying: we know that inputs has either rules or
-            // visited rules, but we can't do inputs.rules() up front because
-            // maybe it just has visited rules, so can't unwrap_or.
+            // At this point inputs may have visited rules, or rules, or both,
+            // or neither (e.g. if it's a text style it may have neither).  So
+            // we have to be a bit careful here.
             let rule_node = match inputs.visited_rules.as_ref() {
                 Some(rules) => rules,
-                None => inputs.rules.as_ref().unwrap(),
+                None => inputs.rules.as_ref().unwrap_or(self.rule_tree().root()),
             };
             let inherited_style;
             let inherited_style_ignoring_first_line;
             let layout_parent_style_for_visited;
             if cascade_flags.contains(IS_LINK) {
                 // We just want to use our parent style as our parent.
                 inherited_style = parent_style;
                 inherited_style_ignoring_first_line = parent_style_ignoring_first_line;