servo: Merge #16424 - style: relax assertions in dom::element when setting selector flags (from servo:assert-layout); r=bholley
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 13 Apr 2017 04:49:30 -0500
changeset 352888 afef2f99d59b7013e449ad485cb801439c20c298
parent 352887 b938fa409e74556ab6f364532ff5cb7f56e0bf27
child 352889 2d7ef036a01fb38bc37eed59390af4f79f149ba4
push id31652
push userkwierso@gmail.com
push dateThu, 13 Apr 2017 20:03:53 +0000
treeherdermozilla-central@3243c8fc3ce7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
milestone55.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 #16424 - style: relax assertions in dom::element when setting selector flags (from servo:assert-layout); r=bholley Source-Repo: https://github.com/servo/servo Source-Revision: 3011f7613929052acd84c0936a89cc7a8e6acd44
servo/components/script/dom/element.rs
servo/components/style/matching.rs
--- a/servo/components/script/dom/element.rs
+++ b/servo/components/script/dom/element.rs
@@ -775,17 +775,17 @@ impl LayoutElementHelpers for LayoutJS<E
         unsafe {
             (*self.unsafe_get()).state.get()
         }
     }
 
     #[inline]
     #[allow(unsafe_code)]
     fn insert_selector_flags(&self, flags: ElementSelectorFlags) {
-        debug_assert!(thread_state::get() == thread_state::LAYOUT);
+        debug_assert!(thread_state::get().is_layout());
         unsafe {
             let f = &(*self.unsafe_get()).selector_flags;
             f.set(f.get() | flags);
         }
     }
 
     #[inline]
     #[allow(unsafe_code)]
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -925,18 +925,27 @@ pub trait MatchMethods : TElement {
     fn apply_selector_flags(&self,
                             tasks: &mut Vec<SequentialTask<Self>>,
                             element: &Self,
                             flags: ElementSelectorFlags) {
         // Apply the selector flags.
         let self_flags = flags.for_self();
         if !self_flags.is_empty() {
             if element == self {
+                // If this is the element we're styling, we have exclusive
+                // access to the element, and thus it's fine inserting them,
+                // even from the worker.
                 unsafe { element.set_selector_flags(self_flags); }
             } else {
+                // Otherwise, this element is an ancestor of the current element
+                // we're styling, and thus multiple children could write to it
+                // if we did from here.
+                //
+                // Instead, we can read them, and post them if necessary as a
+                // sequential task in order for them to be processed later.
                 if !element.has_selector_flags(self_flags) {
                     let task =
                         SequentialTask::set_selector_flags(element.clone(),
                                                            self_flags);
                     tasks.push(task);
                 }
             }
         }