Bug 1427635: Fix DoCompareTreePosition frame tree version with null aCommonAncestor. r?xidorn
It doesn't fill the ancestors of the first frame if aCommonAncestor is null,
which means that we get garbage afterwards.
MozReview-Commit-ID: G85dv7KM1Xd
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1908,18 +1908,21 @@ nsLayoutUtils::DoCompareTreePosition(nsI
nsPresContext* presContext = aFrame1->PresContext();
if (presContext != aFrame2->PresContext()) {
NS_ERROR("no common ancestor at all, different documents");
return 0;
}
AutoTArray<nsIFrame*,20> frame1Ancestors;
- if (aCommonAncestor &&
- !FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors)) {
+ // Note that the order of the condition is important. We need to fill the
+ // ancestors even if aCommonAncestor is null, otherwise the code below makes
+ // no sense.
+ if (!FillAncestors(aFrame1, aCommonAncestor, &frame1Ancestors) &&
+ aCommonAncestor) {
// We reached the root of the frame tree ... if aCommonAncestor was set,
// it is wrong
return DoCompareTreePosition(aFrame1, aFrame2,
aIf1Ancestor, aIf2Ancestor, nullptr);
}
int32_t last1 = int32_t(frame1Ancestors.Length()) - 1;
int32_t last2 = int32_t(aFrame2Ancestors.Length()) - 1;