Bug 1454747: Assert more tightly about StyleNewChildRange. r=bz
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 17 Apr 2018 21:17:44 +0200
changeset 468623 66e90ca48094d07306202a44fa397a53b1a63d54
parent 468622 ec5e5816593915cf9c4ce808b9006ae03457d24c
child 468624 db8d706159dfcbf2d8cf699262fcfcca71c95625
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1454747, 1303605
milestone61.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 1454747: Assert more tightly about StyleNewChildRange. r=bz After bug 1303605 we can assert this, since we make sure all children have the same flattened tree parent, and thus insertion point. MozReview-Commit-ID: 7AHuGGw2uJI
layout/base/nsCSSFrameConstructor.cpp
layout/style/ServoStyleSet.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -7009,26 +7009,40 @@ IsFlattenedTreeChild(nsIContent* aParent
 void
 nsCSSFrameConstructor::StyleNewChildRange(nsIContent* aStartChild,
                                           nsIContent* aEndChild)
 {
   ServoStyleSet* styleSet = mPresShell->StyleSet();
 
   for (nsIContent* child = aStartChild; child != aEndChild;
        child = child->GetNextSibling()) {
-    if (child->IsElement() && !child->AsElement()->HasServoData()) {
-      Element* parent = child->AsElement()->GetFlattenedTreeParentElement();
-      // NB: Parent may be null if the content is appended to a shadow root, and
-      // isn't assigned to any insertion point.
-      if (MOZ_LIKELY(parent) && parent->HasServoData()) {
-        MOZ_ASSERT(IsFlattenedTreeChild(parent, child),
-                   "GetFlattenedTreeParent and ChildIterator don't agree, fix this!");
-        styleSet->StyleNewSubtree(child->AsElement());
-      }
-    }
+    if (!child->IsElement()) {
+      continue;
+    }
+
+    Element* childElement = child->AsElement();
+
+    // We only come in here from non-lazy frame construction, so the children
+    // should be unstyled.
+    MOZ_ASSERT(!childElement->HasServoData());
+
+#ifdef DEBUG
+    {
+      // Furthermore, all of them should have the same flattened tree parent
+      // (GetRangeInsertionPoint ensures it). And that parent should be styled,
+      // otherwise we would've never found an insertion point at all.
+      Element* parent = childElement->GetFlattenedTreeParentElement();
+      MOZ_ASSERT(parent);
+      MOZ_ASSERT(parent->HasServoData());
+      MOZ_ASSERT(IsFlattenedTreeChild(parent, child),
+                 "GetFlattenedTreeParent and ChildIterator don't agree, fix this!");
+    }
+#endif
+
+    styleSet->StyleNewSubtree(childElement);
   }
 }
 
 void
 nsCSSFrameConstructor::ContentAppended(nsIContent* aFirstNewContent,
                                        InsertionKind aInsertionKind)
 {
   MOZ_ASSERT(aInsertionKind == InsertionKind::Sync ||
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1062,16 +1062,18 @@ ServoStyleSet::StyleDocument(ServoTraver
   return postTraversalRequired;
 }
 
 void
 ServoStyleSet::StyleNewSubtree(Element* aRoot)
 {
   MOZ_ASSERT(GetPresContext());
   MOZ_ASSERT(!aRoot->HasServoData());
+  MOZ_ASSERT(aRoot->GetFlattenedTreeParentNodeForStyle(),
+             "Not in the flat tree? Fishy!");
   PreTraverseSync();
   AutoPrepareTraversal guard(this);
 
   // Do the traversal. The snapshots will not be used.
   const SnapshotTable& snapshots = Snapshots();
   auto flags = ServoTraversalFlags::Empty;
   if (ShouldTraverseInParallel()) {
     flags |= ServoTraversalFlags::ParallelTraversal;