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
--- 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;