Bug 1399626 - Part 6: Stop asserting that RangeBoundary objects are valid as they are created, r=masayuki draft
authorMichael Layzell <michael@thelayzells.com>
Thu, 28 Sep 2017 16:38:18 -0400
changeset 672785 2ee1c7211c9790b677d7504a873505ec6b3159c8
parent 672784 b4dcc64f7eb62cff9c8e358cf7a2636c3883c4ba
child 733921 1d46ca38fcc491d9fc9448221de7fc878d653271
push id82373
push userbmo:nika@thelayzells.com
push dateFri, 29 Sep 2017 19:23:28 +0000
reviewersmasayuki
bugs1399626
milestone58.0a1
Bug 1399626 - Part 6: Stop asserting that RangeBoundary objects are valid as they are created, r=masayuki MozReview-Commit-ID: 3Pf80ndRZLW
dom/base/RangeBoundary.h
--- 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) {