Bug 1436663 - EditorBase::JoinNodeDeep() should set result after actually joining the nodes r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 08 Feb 2018 16:17:24 +0900
changeset 752890 769b8480a17ece8fde9b65d7e5de9c0772667c3e
parent 752889 99740eed2adae85b4c4efd5e39ca8edc3dffb1b5
push id98415
push usermasayuki@d-toybox.com
push dateFri, 09 Feb 2018 06:17:49 +0000
reviewersm_kato
bugs1436663
milestone60.0a1
Bug 1436663 - EditorBase::JoinNodeDeep() should set result after actually joining the nodes r?m_kato EditorBase::JoinNodeDeep() returns a DOM point which was start of right node. Currently, this is set before actually joining the nodes. Therefore, we see warnings since right node which becomes joined node may have less children than left node. This patch also makes the NS_WARNING_ASSERTION to NS_ASSERTION since no tests hit this. So, we can use it to detect regressions. MozReview-Commit-ID: 3RmRP588AkF
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorDOMPoint.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4355,24 +4355,24 @@ EditorBase::JoinNodeDeep(nsIContent& aLe
   nsCOMPtr<nsIContent> rightNodeToJoin = &aRightNode;
   nsCOMPtr<nsINode> parentNode = aRightNode.GetParentNode();
 
   EditorDOMPoint ret;
   while (leftNodeToJoin && rightNodeToJoin && parentNode &&
          AreNodesSameType(leftNodeToJoin, rightNodeToJoin)) {
     uint32_t length = leftNodeToJoin->Length();
 
-    ret.Set(rightNodeToJoin, length);
-
     // Do the join
     nsresult rv = JoinNodes(*leftNodeToJoin, *rightNodeToJoin);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return EditorDOMPoint();
     }
 
+    ret.Set(rightNodeToJoin, length);
+
     if (parentNode->GetAsText()) {
       // We've joined all the way down to text nodes, we're done!
       return ret;
     }
 
     // Get new left and right nodes, and begin anew
     parentNode = rightNodeToJoin;
     rightNodeToJoin = parentNode->GetChildAt_Deprecated(length);
--- a/editor/libeditor/EditorDOMPoint.h
+++ b/editor/libeditor/EditorDOMPoint.h
@@ -364,17 +364,17 @@ public:
    */
   void
   Set(nsINode* aContainer, int32_t aOffset)
   {
     mParent = aContainer;
     mChild = nullptr;
     mOffset = mozilla::Some(aOffset);
     mIsChildInitialized = false;
-    NS_WARNING_ASSERTION(!mParent || mOffset.value() <= mParent->Length(),
+    NS_ASSERTION(!mParent || mOffset.value() <= mParent->Length(),
       "The offset is out of bounds");
   }
   void
   Set(const nsINode* aChild)
   {
     MOZ_ASSERT(aChild);
     if (NS_WARN_IF(!aChild->IsContent())) {
       Clear();