Bug 1445929 - Make Editor(Raw)DOMPoint::IsEndOfContainer() check if mParent is container node before checking mChild r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 15 Mar 2018 22:08:19 +0900
changeset 768007 ee308fbd34442bb524ea0a75afabceb0823807b7
parent 768006 91ec54ce5356e7fd6a2731c2e2bed6f576638317
child 768008 34999abdc68add4c7f19f062b16824bf8c09a324
push id102775
push usermasayuki@d-toybox.com
push dateThu, 15 Mar 2018 15:24:05 +0000
reviewersm_kato
bugs1445929
milestone61.0a1
Bug 1445929 - Make Editor(Raw)DOMPoint::IsEndOfContainer() check if mParent is container node before checking mChild r?m_kato Editor(Raw)DOMPoint::IsEndOfContainer() checks mIsChildInitialized before referring mChild. However, it may be true even if mParent is not a container node like a text node. Therefore, if mParent is a text node and mIsChildInitialized is true, it always returns true (i.e., even if mOffset isn't same as length of mParent). This patch makes it check mParent->IsContainerNode() before checking mIsChildInitialized because after checking mIsChildInitialized, it validates the relation of the members. So, this keeps the validation simple. MozReview-Commit-ID: K2XrAZoNv2I
editor/libeditor/EditorDOMPoint.h
--- a/editor/libeditor/EditorDOMPoint.h
+++ b/editor/libeditor/EditorDOMPoint.h
@@ -588,16 +588,19 @@ public:
     //   If mParent is not a container like text node, mOffset is same as the
     //   length of the container.
     //   If mChild is initialized and it's nullptr.
     //   If mChild isn't initialized and mOffset is same as the length of the
     //   container.
     if (NS_WARN_IF(!mParent)) {
       return false;
     }
+    if (!mParent->IsContainerNode()) {
+      return mOffset.value() == mParent->Length();
+    }
     if (mIsChildInitialized) {
       if (!mChild) {
         NS_WARNING_ASSERTION(!mOffset.isSome() ||
                              mOffset.value() == mParent->Length(),
           "If mOffset was initialized, it should be length of the container");
         return true;
       }
       NS_WARNING_ASSERTION(!mOffset.isSome() ||