Bug 1734590 - Both the static InternetCiter methods are now infallible, so no need to return/check an nsresult. r=TYLin
authorJonathan Kew <jkew@mozilla.com>
Mon, 11 Oct 2021 12:20:42 +0000
changeset 595334 c061b67eacd6214fc4c383445fd539e151fbc72f
parent 595333 4be2889972ea68736c6a48f95fdb69d384b84cbf
child 595335 aa46e06b3ba47dc196cefa0873e74df3d25fcdd1
push id38868
push usermlaza@mozilla.com
push dateMon, 11 Oct 2021 21:46:13 +0000
treeherdermozilla-central@32a3cf57dd43 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTYLin
bugs1734590
milestone95.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1734590 - Both the static InternetCiter methods are now infallible, so no need to return/check an nsresult. r=TYLin Differential Revision: https://phabricator.services.mozilla.com/D127865
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/InternetCiter.cpp
editor/libeditor/InternetCiter.h
editor/libeditor/TextEditor.cpp
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -2571,21 +2571,17 @@ nsresult HTMLEditor::InsertWithQuotation
                          "HTMLEditor::CanHandleHTMLEditSubAction() failed");
     return result.Rv();
   }
 
   UndefineCaretBidiLevel();
 
   // Let the citer quote it for us:
   nsString quotedStuff;
-  nsresult rv = InternetCiter::GetCiteString(aQuotedText, quotedStuff);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("InternetCiter::GetCiteString() failed");
-    return rv;
-  }
+  InternetCiter::GetCiteString(aQuotedText, quotedStuff);
 
   // It's best to put a blank line after the quoted text so that mails
   // written without thinking won't be so ugly.
   if (!aQuotedText.IsEmpty() &&
       (aQuotedText.Last() != HTMLEditUtils::kNewLine)) {
     quotedStuff.Append(HTMLEditUtils::kNewLine);
   }
 
@@ -2594,17 +2590,17 @@ nsresult HTMLEditor::InsertWithQuotation
       *this, EditSubAction::eInsertText, nsIEditor::eNext, ignoredError);
   if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
     return ignoredError.StealNSResult();
   }
   NS_WARNING_ASSERTION(
       !ignoredError.Failed(),
       "OnStartToHandleTopLevelEditSubAction() failed, but ignored");
 
-  rv = EnsureNoPaddingBRElementForEmptyEditor();
+  nsresult rv = EnsureNoPaddingBRElementForEmptyEditor();
   if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "EditorBase::EnsureNoPaddingBRElementForEmptyEditor() "
                        "failed, but ignored");
 
   if (NS_SUCCEEDED(rv) && SelectionRef().IsCollapsed()) {
@@ -2988,22 +2984,18 @@ NS_IMETHODIMP HTMLEditor::Rewrap(bool aR
 
   if (current.IsEmpty()) {
     return NS_OK;
   }
 
   nsString wrapped;
   uint32_t firstLineOffset = 0;  // XXX need to reset this if there is a
                                  //     selection
-  rv = InternetCiter::Rewrap(current, wrapWidth, firstLineOffset,
-                             aRespectNewlines, wrapped);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("InternetCiter::Rewrap() failed");
-    return EditorBase::ToGenericNSResult(rv);
-  }
+  InternetCiter::Rewrap(current, wrapWidth, firstLineOffset, aRespectNewlines,
+                        wrapped);
 
   if (isCollapsed) {
     DebugOnly<nsresult> rvIgnored = SelectAllInternal();
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
                          "HTMLEditor::SelectAllInternal() failed");
   }
 
   // The whole operation in InsertTextWithQuotationsInternal() should be
--- a/editor/libeditor/InternetCiter.cpp
+++ b/editor/libeditor/InternetCiter.cpp
@@ -18,18 +18,18 @@
 #include "nsStringIterator.h"
 
 namespace mozilla {
 
 /**
  * Mail citations using the Internet style: > This is a citation.
  */
 
-nsresult InternetCiter::GetCiteString(const nsAString& aInString,
-                                      nsAString& aOutString) {
+void InternetCiter::GetCiteString(const nsAString& aInString,
+                                  nsAString& aOutString) {
   aOutString.Truncate();
   char16_t uch = HTMLEditUtils::kNewLine;
 
   // Strip trailing new lines which will otherwise turn up
   // as ugly quoted empty lines.
   nsReadingIterator<char16_t> beginIter, endIter;
   aInString.BeginReading(beginIter);
   aInString.EndReading(endIter);
@@ -53,17 +53,16 @@ nsresult InternetCiter::GetCiteString(co
     ++beginIter;
 
     aOutString += uch;
   }
 
   if (uch != HTMLEditUtils::kNewLine) {
     aOutString += HTMLEditUtils::kNewLine;
   }
-  return NS_OK;
 }
 
 static void AddCite(nsAString& aOutString, int32_t citeLevel) {
   for (int32_t i = 0; i < citeLevel; ++i) {
     aOutString.Append(HTMLEditUtils::kGreaterThan);
   }
   if (citeLevel > 0) {
     aOutString.Append(HTMLEditUtils::kSpace);
@@ -81,19 +80,19 @@ static inline void BreakLine(nsAString& 
   }
 }
 
 static inline bool IsSpace(char16_t c) {
   return (nsCRT::IsAsciiSpace(c) || (c == HTMLEditUtils::kNewLine) ||
           (c == HTMLEditUtils::kCarriageReturn) || (c == HTMLEditUtils::kNBSP));
 }
 
-nsresult InternetCiter::Rewrap(const nsAString& aInString, uint32_t aWrapCol,
-                               uint32_t aFirstLineOffset, bool aRespectNewlines,
-                               nsAString& aOutString) {
+void InternetCiter::Rewrap(const nsAString& aInString, uint32_t aWrapCol,
+                           uint32_t aFirstLineOffset, bool aRespectNewlines,
+                           nsAString& aOutString) {
   // There shouldn't be returns in this string, only dom newlines.
   // Check to make sure:
 #ifdef DEBUG
   int32_t crPosition = aInString.FindChar(HTMLEditUtils::kCarriageReturn);
   NS_ASSERTION(crPosition < 0, "Rewrap: CR in string gotten from DOM!\n");
 #endif /* DEBUG */
 
   aOutString.Truncate();
@@ -277,13 +276,11 @@ nsresult InternetCiter::Rewrap(const nsA
       }
 
       // Add a newline and the quote level to the out string
       if (posInString < length) {  // not for the last line, though
         BreakLine(aOutString, outStringCol, citeLevel);
       }
     }  // end inner loop within one line of aInString
   }    // end outer loop over lines of aInString
-
-  return NS_OK;
 }
 
 }  // namespace mozilla
--- a/editor/libeditor/InternetCiter.h
+++ b/editor/libeditor/InternetCiter.h
@@ -11,19 +11,18 @@
 
 namespace mozilla {
 
 /**
  * Mail citations using standard Internet style.
  */
 class InternetCiter final {
  public:
-  static nsresult GetCiteString(const nsAString& aInString,
-                                nsAString& aOutString);
+  static void GetCiteString(const nsAString& aInString, nsAString& aOutString);
 
-  static nsresult Rewrap(const nsAString& aInString, uint32_t aWrapCol,
-                         uint32_t aFirstLineOffset, bool aRespectNewlines,
-                         nsAString& aOutString);
+  static void Rewrap(const nsAString& aInString, uint32_t aWrapCol,
+                     uint32_t aFirstLineOffset, bool aRespectNewlines,
+                     nsAString& aOutString);
 };
 
 }  // namespace mozilla
 
 #endif  // #ifndef InternetCiter_h
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -574,21 +574,17 @@ nsresult TextEditor::InsertWithQuotation
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   if (IsReadonly()) {
     return NS_OK;
   }
 
   // Let the citer quote it for us:
   nsString quotedStuff;
-  nsresult rv = InternetCiter::GetCiteString(aQuotedText, quotedStuff);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("InternetCiter::GetCiteString() failed");
-    return rv;
-  }
+  InternetCiter::GetCiteString(aQuotedText, quotedStuff);
 
   // It's best to put a blank line after the quoted text so that mails
   // written without thinking won't be so ugly.
   if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != char16_t('\n'))) {
     quotedStuff.Append(char16_t('\n'));
   }
 
   IgnoredErrorResult ignoredError;
@@ -600,17 +596,17 @@ nsresult TextEditor::InsertWithQuotation
   NS_WARNING_ASSERTION(
       !ignoredError.Failed(),
       "TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
 
   // XXX Do we need to support paste-as-quotation in password editor (and
   //     also in single line editor)?
   MaybeDoAutoPasswordMasking();
 
-  rv = InsertTextAsSubAction(quotedStuff, SelectionHandling::Delete);
+  nsresult rv = InsertTextAsSubAction(quotedStuff, SelectionHandling::Delete);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "EditorBase::InsertTextAsSubAction() failed");
   return rv;
 }
 
 nsresult TextEditor::SelectEntireDocument() {
   MOZ_ASSERT(IsEditActionDataAvailable());