Bug 1499603 - Clear host rules from clear_cascade_data. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 17 Oct 2018 13:37:47 +0000
changeset 500130 0442e4d321bb8952807bd0f5de7b1bdb2f4217a5
parent 500129 8ec57c7e30579ee2bb53f8332968177b165c822b
child 500131 3c175c006e65b1c139a1070d3d00e18e0d034d49
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1499603
milestone64.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
Bug 1499603 - Clear host rules from clear_cascade_data. r=heycam While at it, also measure them for about:memory. Differential Revision: https://phabricator.services.mozilla.com/D8972
servo/components/style/stylist.rs
testing/web-platform/tests/css/css-scoping/shadow-host-removal-invalidation.html
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -2410,16 +2410,19 @@ impl CascadeData {
     }
 
     /// Clears the cascade data, but not the invalidation data.
     fn clear_cascade_data(&mut self) {
         self.normal_rules.clear();
         if let Some(ref mut slotted_rules) = self.slotted_rules {
             slotted_rules.clear();
         }
+        if let Some(ref mut host_rules) = self.host_rules {
+            host_rules.clear();
+        }
         self.animations.clear();
         self.extra_data.clear();
         self.rules_source_order = 0;
         self.num_selectors = 0;
         self.num_declarations = 0;
     }
 
     fn clear(&mut self) {
@@ -2435,16 +2438,19 @@ impl CascadeData {
 
     /// Measures heap usage.
     #[cfg(feature = "gecko")]
     fn add_size_of(&self, ops: &mut MallocSizeOfOps, sizes: &mut ServoStyleSetSizes) {
         self.normal_rules.add_size_of(ops, sizes);
         if let Some(ref slotted_rules) = self.slotted_rules {
             slotted_rules.add_size_of(ops, sizes);
         }
+        if let Some(ref host_rules) = self.host_rules {
+            host_rules.add_size_of(ops, sizes);
+        }
         sizes.mInvalidationMap += self.invalidation_map.size_of(ops);
         sizes.mRevalidationSelectors += self.selectors_for_cache_revalidation.size_of(ops);
         sizes.mOther += self.animations.size_of(ops);
         sizes.mOther += self.effective_media_query_results.size_of(ops);
         sizes.mOther += self.extra_data.size_of(ops);
     }
 }
 
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-scoping/shadow-host-removal-invalidation.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<title>CSS Test: Invalidation of :host selectors</title>
+<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
+<link rel="author" title="Mozilla" href="https://mozilla.org">
+<link rel="help" href="https://drafts.csswg.org/css-scoping/#host-selector">
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1499603">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="host" style="color: green"></div>
+<script>
+host.attachShadow({ mode: "open" }).innerHTML = `
+  <style>
+    :host { color: red !important }
+  </style>
+`;
+test(function() {
+  assert_equals(getComputedStyle(host).color, "rgb(255, 0, 0)");
+  host.shadowRoot.querySelector("style").remove();
+  assert_equals(getComputedStyle(host).color, "rgb(0, 128, 0)");
+}, ":host rules are properly invalidated when stylesheets are removed");
+</script>