Bug 1399626 - Part 6: Stop asserting that RangeBoundary objects are valid as they are created, r=masayuki
MozReview-Commit-ID: 3Pf80ndRZLW
--- a/dom/base/RangeBoundary.h
+++ b/dom/base/RangeBoundary.h
@@ -51,38 +51,41 @@ class RangeBoundaryBase
public:
RangeBoundaryBase(nsINode* aContainer, nsIContent* aRef)
: mParent(aContainer)
, mRef(aRef)
{
if (!mRef) {
mOffset = mozilla::Some(0);
} else {
+ NS_WARNING_ASSERTION(mRef->GetParentNode() == mParent,
+ "Initializing RangeBoundary with invalid value");
mOffset.reset();
}
}
RangeBoundaryBase(nsINode* aContainer, int32_t aOffset)
: mParent(aContainer)
, mRef(nullptr)
, mOffset(mozilla::Some(aOffset))
{
if (mParent && mParent->IsContainerNode()) {
// Find a reference node
if (aOffset == static_cast<int32_t>(aContainer->GetChildCount())) {
mRef = aContainer->GetLastChild();
} else if (aOffset != 0) {
mRef = mParent->GetChildAt(aOffset - 1);
- MOZ_ASSERT(mRef);
}
- MOZ_ASSERT_IF(!mRef, aOffset == 0);
+ NS_WARNING_ASSERTION(mRef || aOffset == 0,
+ "Constructing RangeBoundary with invalid value");
}
- MOZ_ASSERT_IF(mRef, mRef->GetParentNode() == mParent);
+ NS_WARNING_ASSERTION(!mRef || mRef->GetParentNode() == mParent,
+ "Constructing RangeBoundary with invalid value");
}
RangeBoundaryBase()
: mParent(nullptr)
, mRef(nullptr)
{
}
@@ -109,17 +112,17 @@ public:
nsIContent*
GetChildAtOffset() const
{
if (!mParent || !mParent->IsContainerNode()) {
return nullptr;
}
if (!mRef) {
- MOZ_ASSERT(Offset() == 0);
+ MOZ_ASSERT(Offset() == 0, "invalid RangeBoundary");
return mParent->GetFirstChild();
}
MOZ_ASSERT(mParent->GetChildAt(Offset()) == mRef->GetNextSibling());
return mRef->GetNextSibling();
}
uint32_t
Offset() const
@@ -141,17 +144,18 @@ public:
void
InvalidateOffset()
{
MOZ_ASSERT(mParent);
MOZ_ASSERT(mParent->IsContainerNode(), "Range is positioned on a text node!");
if (!mRef) {
- MOZ_ASSERT(mOffset.isSome() && mOffset.value() == 0);
+ MOZ_ASSERT(mOffset.isSome() && mOffset.value() == 0,
+ "Invalidating offset of invalid RangeBoundary?");
return;
}
mOffset.reset();
}
void
Set(nsINode* aContainer, int32_t aOffset)
{
@@ -162,23 +166,26 @@ public:
mRef = aContainer->GetLastChild();
} else if (aOffset == 0) {
mRef = nullptr;
} else {
mRef = mParent->GetChildAt(aOffset - 1);
MOZ_ASSERT(mRef);
}
- MOZ_ASSERT_IF(!mRef, aOffset == 0);
+ NS_WARNING_ASSERTION(mRef || aOffset == 0,
+ "Setting RangeBoundary to invalid value");
} else {
mRef = nullptr;
}
mOffset = mozilla::Some(aOffset);
- MOZ_ASSERT_IF(mRef, mRef->GetParentNode() == mParent);
+
+ NS_WARNING_ASSERTION(!mRef || mRef->GetParentNode() == mParent,
+ "Setting RangeBoundary to invalid value");
}
void
SetAfterRef(nsINode* aParent, nsIContent* aRef)
{
mParent = aParent;
mRef = aRef;
if (!mRef) {