Bug 1454747: Assert more tightly about StyleNewChildRange. r?bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 17 Apr 2018 21:17:44 +0200
changeset 783820 5d187428f0602a4e142e827281e15b8a6bc9e265
parent 783819 01d47fcb1151a8aa1df9d1aa9eb8b8ae25fc2c96
child 784159 55731739849e9f6ea7c40f4cf955638134ce4f3a
child 784162 b17ddee517d5072d6262ca79906b2c6c483d004d
push id106793
push userbmo:emilio@crisal.io
push dateTue, 17 Apr 2018 19:27:02 +0000
reviewersbz
bugs1454747, 1303605
milestone61.0a1
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
@@ -7007,26 +7007,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
@@ -1057,16 +1057,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;