From bb25a09e27cffe73fcfffe2ba8c220fd9da55405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 5 Nov 2018 00:05:12 +0000 Subject: [PATCH] Bug 1502893 - Don't match document author rules if not needed for revalidation. r=heycam,firefox-style-system-reviewers When you're in a ShadowRoot and can share style with a sibling, the sharing code is smart enough to skip document author rules. But then it could get confused if you also include document rules, since revalidation selectors are matched against these. This is not a correctness issue, because we're matching more than what we need, and avoid sharing if we failed. Also fix the detection for user rules in any_applicable_rule_data. Differential Revision: https://phabricator.services.mozilla.com/D10117 --HG-- extra : moz-landing-system : lando --- layout/style/crashtests/1502893.html | 29 ++++++++++++++ layout/style/crashtests/crashtests.list | 1 + servo/components/style/stylist.rs | 53 ++++++++++++++----------- 3 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 layout/style/crashtests/1502893.html diff --git a/layout/style/crashtests/1502893.html b/layout/style/crashtests/1502893.html new file mode 100644 index 000000000000..eed2d75f5e4f --- /dev/null +++ b/layout/style/crashtests/1502893.html @@ -0,0 +1,29 @@ + + + + + diff --git a/layout/style/crashtests/crashtests.list b/layout/style/crashtests/crashtests.list index de54f9918830..3714a95a1bff 100644 --- a/layout/style/crashtests/crashtests.list +++ b/layout/style/crashtests/crashtests.list @@ -294,3 +294,4 @@ load 1475003.html load 1479681.html load 1488817.html load 1490012.html +load 1502893.html diff --git a/servo/components/style/stylist.rs b/servo/components/style/stylist.rs index fe96fd78ad84..2772891a3db1 100644 --- a/servo/components/style/stylist.rs +++ b/servo/components/style/stylist.rs @@ -605,11 +605,11 @@ impl Stylist { maybe = maybe || f(&*data); }); - if maybe || !doc_author_rules_apply { - return maybe; + if maybe || f(&self.cascade_data.user) { + return true; } - f(&self.cascade_data.author) || f(&self.cascade_data.user) + doc_author_rules_apply && f(&self.cascade_data.author) } /// Computes the style for a given "precomputed" pseudo-element, taking the @@ -1491,7 +1491,33 @@ impl Stylist { // the lookups, which means that the bitvecs are comparable. We verify // this in the caller by asserting that the bitvecs are same-length. let mut results = SmallBitVec::new(); - for (data, _) in self.cascade_data.iter_origins() { + + let matches_document_rules = + element.each_applicable_non_document_style_rule_data(|data, quirks_mode, host| { + matching_context.with_shadow_host(host, |matching_context| { + data.selectors_for_cache_revalidation.lookup( + element, + quirks_mode, + |selector_and_hashes| { + results.push(matches_selector( + &selector_and_hashes.selector, + selector_and_hashes.selector_offset, + Some(&selector_and_hashes.hashes), + &element, + matching_context, + flags_setter, + )); + true + }, + ); + }) + }); + + for (data, origin) in self.cascade_data.iter_origins() { + if origin == Origin::Author && !matches_document_rules { + continue; + } + data.selectors_for_cache_revalidation.lookup( element, self.quirks_mode, @@ -1509,25 +1535,6 @@ impl Stylist { ); } - element.each_applicable_non_document_style_rule_data(|data, quirks_mode, host| { - matching_context.with_shadow_host(host, |matching_context| { - data.selectors_for_cache_revalidation.lookup( - element, - quirks_mode, - |selector_and_hashes| { - results.push(matches_selector( - &selector_and_hashes.selector, - selector_and_hashes.selector_offset, - Some(&selector_and_hashes.hashes), - &element, - matching_context, - flags_setter, - )); - true - }, - ); - }) - }); results }