Bug 1460509 - part 5: Make TextEditRules::CreateTrailingBRIfNeeded() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 11 May 2018 16:31:53 +0900
changeset 798723 284b619f2e968cb81ccd55b941a5d85bd63c3f48
parent 798722 5ccf7ab97dc41b8a5df61c8af929d318aaf94046
child 798724 456816b935ea0e2bc8052cdeaba65d2186928248
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 5: Make TextEditRules::CreateTrailingBRIfNeeded() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: CNTgECam862
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1407,16 +1407,19 @@ TextEditRules::CreateTrailingBRIfNeeded(
 
   // Morph it back to a mozBR
   lastChild->AsElement()->UnsetAttr(kNameSpaceID_None,
                                     kMOZEditorBogusNodeAttrAtom,
                                     false);
   lastChild->AsElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                                   NS_LITERAL_STRING("_moz"),
                                   true);
+  if (NS_WARN_IF(!CanHandleEditAction())) {
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
   return NS_OK;
 }
 
 nsresult
 TextEditRules::CreateBogusNodeIfNeeded()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -179,17 +179,17 @@ protected:
   /**
    * Check for and replace a redundant trailing break.
    */
   nsresult RemoveRedundantTrailingBR();
 
   /**
    * Creates a trailing break in the text doc if there is not one already.
    */
-  nsresult CreateTrailingBRIfNeeded();
+  MOZ_MUST_USE nsresult CreateTrailingBRIfNeeded();
 
   /**
    * Creates a bogus <br> node if the root element has no editable content.
    */
   MOZ_MUST_USE nsresult CreateBogusNodeIfNeeded();
 
   /**
    * Returns a truncated insertion string if insertion would place us over