Bug 1525481 - part 3: Make editor not expose internal errors to the web r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 25 Feb 2019 09:07:54 +0000
changeset 518742 81adda1cb3f2d0ddcc71c389ff851396387412b0
parent 518741 b68a329b15d484a031b1a452aea3c73c546d3441
child 518743 f4c45ebf34aca62e14ca3eaf92b80070b8c22f5e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1525481
milestone67.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 1525481 - part 3: Make editor not expose internal errors to the web r=m_kato As far as I've tested, Chrome does not throw exception even when editor is destroyed or editor content is modified unexpectedly. So, we should return `NS_OK` from most public methods of editor when internal methods return `NS_ERROR_EDITOR_DESTROYED` or `NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE`. Differential Revision: https://phabricator.services.mozilla.com/D20811
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/EditorCommands.cpp
editor/libeditor/EditorEventListener.cpp
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLAnonymousNodeEditor.cpp
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLInlineTableEditor.cpp
editor/libeditor/HTMLStyleEditor.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/TextEditor.cpp
editor/libeditor/TextEditor.h
editor/libeditor/TextEditorDataTransfer.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -327,26 +327,30 @@ nsresult EditorBase::PostCreate() {
   }
 
   // Synchronize some stuff for the flags.  SetFlags() will initialize
   // something by the flag difference.  This is first time of that, so, all
   // initializations must be run.  For such reason, we need to invert mFlags
   // value first.
   mFlags = ~mFlags;
   nsresult rv = SetFlags(~mFlags);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
 
   // These operations only need to happen on the first PostCreate call
   if (!mDidPostCreate) {
     mDidPostCreate = true;
 
     // Set up listeners
     CreateEventListeners();
     rv = InstallEventListeners();
-    NS_ENSURE_SUCCESS(rv, rv);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return EditorBase::ToGenericNSResult(rv);
+    }
 
     // nuke the modification count, so the doc appears unmodified
     // do this before we notify listeners
     ResetModificationCount();
 
     // update the UI with our state
     NotifyDocumentListeners(eDocumentCreated);
     NotifyDocumentListeners(eDocumentStateChanged);
@@ -358,18 +362,19 @@ nsresult EditorBase::PostCreate() {
     InitializeSelection(focusedContent);
 
     // If the text control gets reframed during focus, Focus() would not be
     // called, so take a chance here to see if we need to spell check the text
     // control.
     mEventListener->SpellCheckIfNeeded();
 
     IMEState newState;
-    rv = GetPreferredIMEState(&newState);
-    NS_ENSURE_SUCCESS(rv, NS_OK);
+    if (NS_WARN_IF(NS_FAILED(GetPreferredIMEState(&newState)))) {
+      return NS_OK;
+    }
     // May be null in design mode
     nsCOMPtr<nsIContent> content = GetFocusedContentForIME();
     IMEStateManager::UpdateIMEState(newState, content, this);
   }
 
   // FYI: This call might cause destroying this editor.
   IMEStateManager::OnEditorInitialized(*this);
 
@@ -705,17 +710,18 @@ nsresult EditorBase::GetSelection(Select
 }
 
 NS_IMETHODIMP
 EditorBase::DoTransaction(nsITransaction* aTxn) {
   AutoEditActionDataSetter editActionData(*this, EditAction::eUnknown);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_FAILURE;
   }
-
+  // This is a low level API.  So, the caller might require raw error code.
+  // Therefore, don't need to use EditorBase::ToGenericNSResult().
   return DoTransactionInternal(aTxn);
 }
 
 nsresult EditorBase::DoTransactionInternal(nsITransaction* aTxn) {
   if (mPlaceholderBatch && !mPlaceholderTransaction) {
     mPlaceholderTransaction = PlaceholderTransaction::Create(
         *this, mPlaceholderName, std::move(mSelState));
     MOZ_ASSERT(mSelState.isNothing());
@@ -967,16 +973,18 @@ NS_IMETHODIMP
 EditorBase::SelectAll() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = SelectAllInternal();
   if (NS_WARN_IF(NS_FAILED(rv))) {
+    // This is low level API for XUL applcation.  So, we should return raw
+    // error code here.
     return rv;
   }
   return NS_OK;
 }
 
 nsresult EditorBase::SelectAllInternal() {
   MOZ_ASSERT(IsInitialized());
 
@@ -1000,17 +1008,19 @@ NS_IMETHODIMP
 EditorBase::BeginningOfDocument() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // get the root element
   dom::Element* rootElement = GetRoot();
-  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
+  if (NS_WARN_IF(!rootElement)) {
+    return NS_ERROR_NULL_POINTER;
+  }
 
   // find first editable thingy
   nsCOMPtr<nsINode> firstNode = GetFirstEditableNode(rootElement);
   if (!firstNode) {
     // just the root node, set selection to inside the root
     return SelectionRefPtr()->Collapse(rootElement, 0);
   }
 
@@ -1032,17 +1042,23 @@ EditorBase::BeginningOfDocument() {
 }
 
 NS_IMETHODIMP
 EditorBase::EndOfDocument() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
-  return CollapseSelectionToEnd();
+  nsresult rv = CollapseSelectionToEnd();
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    // This is low level API for XUL applcation.  So, we should return raw
+    // error code here.
+    return rv;
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::CollapseSelectionToEnd() {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   // XXX Why doesn't this check if the document is alive?
   if (NS_WARN_IF(!IsInitialized())) {
     return NS_ERROR_NOT_INITIALIZED;
@@ -1150,17 +1166,21 @@ EditorBase::SetAttribute(Element* aEleme
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
-  return SetAttributeWithTransaction(*aElement, *attribute, aValue);
+  nsresult rv = SetAttributeWithTransaction(*aElement, *attribute, aValue);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::SetAttributeWithTransaction(Element& aElement,
                                                  nsAtom& aAttribute,
                                                  const nsAString& aValue) {
   RefPtr<ChangeAttributeTransaction> transaction =
       ChangeAttributeTransaction::Create(aElement, aAttribute, aValue);
   return DoTransactionInternal(transaction);
@@ -1193,17 +1213,21 @@ EditorBase::RemoveAttribute(Element* aEl
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eRemoveAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
-  return RemoveAttributeWithTransaction(*aElement, *attribute);
+  nsresult rv = RemoveAttributeWithTransaction(*aElement, *attribute);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::RemoveAttributeWithTransaction(Element& aElement,
                                                     nsAtom& aAttribute) {
   // XXX If aElement doesn't have aAttribute, shouldn't we stop creating
   //     the transaction?  Otherwise, there will be added a transaction
   //     which does nothing at doing undo/redo.
   RefPtr<ChangeAttributeTransaction> transaction =
@@ -1362,18 +1386,22 @@ EditorBase::InsertNode(nsINode* aNodeToI
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   int32_t offset =
       aOffset < 0
           ? static_cast<int32_t>(aContainer->Length())
           : std::min(aOffset, static_cast<int32_t>(aContainer->Length()));
-  return InsertNodeWithTransaction(*contentToInsert,
-                                   EditorRawDOMPoint(aContainer, offset));
+  nsresult rv = InsertNodeWithTransaction(
+      *contentToInsert, EditorRawDOMPoint(aContainer, offset));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 template <typename PT, typename CT>
 nsresult EditorBase::InsertNodeWithTransaction(
     nsIContent& aContentToInsert,
     const EditorDOMPointBase<PT, CT>& aPointToInsert) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
@@ -1419,17 +1447,17 @@ EditorBase::SplitNode(nsINode* aNode, in
 
   int32_t offset =
       std::min(std::max(aOffset, 0), static_cast<int32_t>(aNode->Length()));
   ErrorResult error;
   nsCOMPtr<nsIContent> newNode =
       SplitNodeWithTransaction(EditorRawDOMPoint(aNode, offset), error);
   newNode.forget(aNewLeftNode);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   return NS_OK;
 }
 
 template <typename PT, typename CT>
 already_AddRefed<nsIContent> EditorBase::SplitNodeWithTransaction(
     const EditorDOMPointBase<PT, CT>& aStartOfRightNode, ErrorResult& aError) {
   MOZ_ASSERT(IsEditActionDataAvailable());
@@ -1492,17 +1520,21 @@ EditorBase::JoinNodes(nsINode* aLeftNode
     return NS_ERROR_INVALID_ARG;
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eJoinNodes);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return JoinNodesWithTransaction(*aLeftNode, *aRightNode);
+  nsresult rv = JoinNodesWithTransaction(*aLeftNode, *aRightNode);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::JoinNodesWithTransaction(nsINode& aLeftNode,
                                               nsINode& aRightNode) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   nsCOMPtr<nsINode> parent = aLeftNode.GetParentNode();
   MOZ_ASSERT(parent);
@@ -1564,17 +1596,21 @@ EditorBase::DeleteNode(nsINode* aNode) {
     return NS_ERROR_INVALID_ARG;
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eRemoveNode);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return DeleteNodeWithTransaction(*aNode);
+  nsresult rv = DeleteNodeWithTransaction(*aNode);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::DeleteNodeWithTransaction(nsINode& aNode) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
       *this, EditSubAction::eDeleteNode, nsIEditor::ePrevious);
 
@@ -2257,18 +2293,22 @@ EditorBase::CloneAttribute(const nsAStri
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
-  return CloneAttributeWithTransaction(*attribute, *aDestElement,
-                                       *aSourceElement);
+  nsresult rv =
+      CloneAttributeWithTransaction(*attribute, *aDestElement, *aSourceElement);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::CloneAttributeWithTransaction(nsAtom& aAttribute,
                                                    Element& aDestElement,
                                                    Element& aSourceElement) {
   nsAutoString attrValue;
   if (aSourceElement.GetAttr(kNameSpaceID_None, &aAttribute, attrValue)) {
     return SetAttributeWithTransaction(aDestElement, aAttribute, attrValue);
@@ -4229,35 +4269,44 @@ EditorBase::SetAttributeOrEquivalent(Ele
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
-  return SetAttributeOrEquivalent(aElement, attribute, aValue,
-                                  aSuppressTransaction);
+  nsresult rv = SetAttributeOrEquivalent(aElement, attribute, aValue,
+                                         aSuppressTransaction);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::RemoveAttributeOrEquivalent(Element* aElement,
                                         const nsAString& aAttribute,
                                         bool aSuppressTransaction) {
   if (NS_WARN_IF(!aElement)) {
     return NS_ERROR_NULL_POINTER;
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eRemoveAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<nsAtom> attribute = NS_Atomize(aAttribute);
-  return RemoveAttributeOrEquivalent(aElement, attribute, aSuppressTransaction);
+  nsresult rv =
+      RemoveAttributeOrEquivalent(aElement, attribute, aSuppressTransaction);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult EditorBase::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
   // NOTE: When you change this method, you should also change:
   //   * editor/libeditor/tests/test_texteditor_keyevent_handling.html
   //   * editor/libeditor/tests/test_htmleditor_keyevent_handling.html
   //
   // And also when you add new key handling, you need to change the subclass's
@@ -4427,26 +4476,30 @@ nsresult EditorBase::FinalizeSelection()
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   SelectionRefPtr()->SetAncestorLimiter(nullptr);
 
   nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-  NS_ENSURE_TRUE(presShell, NS_ERROR_NOT_INITIALIZED);
+  if (NS_WARN_IF(!presShell)) {
+    return NS_ERROR_NOT_INITIALIZED;
+  }
 
   if (RefPtr<nsCaret> caret = presShell->GetCaret()) {
     caret->SetIgnoreUserModify(true);
   }
 
   selectionController->SetCaretEnabled(false);
 
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
-  NS_ENSURE_TRUE(fm, NS_ERROR_NOT_INITIALIZED);
+  if (NS_WARN_IF(!fm)) {
+    return NS_ERROR_NOT_INITIALIZED;
+  }
   fm->UpdateCaretForCaretBrowsingMode();
 
   if (!HasIndependentSelection()) {
     // If this editor doesn't have an independent selection, i.e., it must
     // mean that it is an HTML editor, the selection controller is shared with
     // presShell.  So, even this editor loses focus, other part of the document
     // may still have focus.
     RefPtr<Document> doc = GetDocument();
@@ -4548,30 +4601,30 @@ nsresult EditorBase::ToggleTextDirection
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // XXX Oddly, Chrome does not dispatch beforeinput event in this case but
   //     dispatches input event.
 
   nsresult rv = DetermineCurrentDirection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   if (IsRightToLeft()) {
     editActionData.SetData(NS_LITERAL_STRING("ltr"));
     nsresult rv = SetTextDirectionTo(TextDirection::eLTR);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
   } else if (IsLeftToRight()) {
     editActionData.SetData(NS_LITERAL_STRING("rtl"));
     nsresult rv = SetTextDirectionTo(TextDirection::eRTL);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
   } else {
     MOZ_ASSERT_UNREACHABLE(
         "Why did DetermineCurrentDirection() not determine current direction?");
   }
 
   // XXX When we don't change the text direction, do we really need to
   //     dispatch input event?
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1834,16 +1834,39 @@ class EditorBase : public nsIEditor,
  protected:  // Shouldn't be used by friend classes
   /**
    * The default destructor. This should suffice. Should this be pure virtual
    * for someone to derive from the EditorBase later? I don't believe so.
    */
   virtual ~EditorBase();
 
   /**
+   * ToGenericNSResult() computes proper nsresult value for the editor users.
+   * This should be used only when public methods return result of internal
+   * methods.
+   */
+  static inline nsresult ToGenericNSResult(nsresult aRv) {
+    switch (aRv) {
+      // If the editor is destroyed while handling an edit action, editor needs
+      // to stop handling it.  However, editor throw exception in this case
+      // because Chrome does not throw exception even in this case.
+      case NS_ERROR_EDITOR_DESTROYED:
+        return NS_OK;
+      // If editor meets unexpected DOM tree due to modified by mutation event
+      // listener, editor needs to stop handling it.  However, editor shouldn't
+      // return error for the users because Chrome does not throw exception in
+      // this case.
+      case NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE:
+        return NS_OK;
+      default:
+        return aRv;
+    }
+  }
+
+  /**
    * GetDocumentCharsetInternal() returns charset of the document.
    */
   nsresult GetDocumentCharsetInternal(nsACString& aCharset) const;
 
   /**
    * SelectAllInternal() should be used instead of SelectAll() in editor
    * because SelectAll() creates AutoEditActionSetter but we should avoid
    * to create it as far as possible.
--- a/editor/libeditor/EditorCommands.cpp
+++ b/editor/libeditor/EditorCommands.cpp
@@ -465,21 +465,16 @@ PasteTransferableCommand::DoCommandParam
   nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
   if (NS_WARN_IF(!trans)) {
     return NS_ERROR_FAILURE;
   }
 
   TextEditor* textEditor = editor->AsTextEditor();
   MOZ_ASSERT(textEditor);
   nsresult rv = textEditor->PasteTransferable(trans);
-  if (rv == NS_ERROR_EDITOR_DESTROYED) {
-    // Return NS_OK when editor is destroyed since it's expected by the
-    // web app.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PasteTransferableCommand::GetCommandStateParams(const char* aCommandName,
@@ -1093,21 +1088,16 @@ PasteQuotationCommand::DoCommand(const c
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (NS_WARN_IF(!editor)) {
     return NS_ERROR_FAILURE;
   }
   TextEditor* textEditor = editor->AsTextEditor();
   MOZ_ASSERT(textEditor);
   nsresult rv = textEditor->PasteAsQuotationAsAction(
       nsIClipboard::kGlobalClipboard, true);
-  if (rv == NS_ERROR_EDITOR_DESTROYED) {
-    // Return NS_OK when editor is destroyed since it's expected by the
-    // web app.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PasteQuotationCommand::DoCommandParams(const char* aCommandName,
@@ -1116,21 +1106,16 @@ PasteQuotationCommand::DoCommandParams(c
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (!editor) {
     return NS_ERROR_FAILURE;
   }
   TextEditor* textEditor = editor->AsTextEditor();
   MOZ_ASSERT(textEditor);
   nsresult rv = textEditor->PasteAsQuotationAsAction(
       nsIClipboard::kGlobalClipboard, true);
-  if (rv == NS_ERROR_EDITOR_DESTROYED) {
-    // Return NS_OK when editor is destroyed since it's expected by the
-    // web app.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PasteQuotationCommand::GetCommandStateParams(const char* aCommandName,
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -800,21 +800,16 @@ nsresult EditorEventListener::Drop(DragE
     return NS_OK;
   }
 
   aDragEvent->StopPropagation();
   aDragEvent->PreventDefault();
 
   RefPtr<TextEditor> textEditor = mEditorBase->AsTextEditor();
   nsresult rv = textEditor->OnDrop(aDragEvent);
-  if (rv == NS_ERROR_EDITOR_DESTROYED) {
-    // If the editor has been destroyed, it means that this is handled as
-    // expected by the web app.  So, return NS_OK.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 bool EditorEventListener::CanDrop(DragEvent* aEvent) {
   MOZ_ASSERT(!DetachedFromEditorOrDefaultPrevented(aEvent->WidgetEventPtr()));
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -66,22 +66,22 @@ nsresult HTMLEditor::SetSelectionToAbsol
   EditSubActionInfo subActionInfo(aEnabled
                                       ? EditSubAction::eSetPositionToAbsolute
                                       : EditSubAction::eSetPositionToStatic);
   bool cancel, handled;
   // Protect the edit rules object from dying
   RefPtr<TextEditRules> rules(mRules);
   nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
   if (NS_FAILED(rv) || cancel) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   rv = rules->DidDoAction(subActionInfo, rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 already_AddRefed<Element>
 HTMLEditor::GetAbsolutelyPositionedSelectionContainer() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
@@ -162,22 +162,22 @@ nsresult HTMLEditor::AddZIndex(int32_t a
   // Find out if the selection is collapsed:
   EditSubActionInfo subActionInfo(aChange < 0 ? EditSubAction::eDecreaseZIndex
                                               : EditSubAction::eIncreaseZIndex);
   bool cancel, handled;
   // Protect the edit rules object from dying
   RefPtr<TextEditRules> rules(mRules);
   nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
   if (cancel || NS_FAILED(rv)) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   rv = rules->DidDoAction(subActionInfo, rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 int32_t HTMLEditor::GetZIndex(Element& aElement) {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return 0;
@@ -254,17 +254,17 @@ HTMLEditor::RefreshGrabber() {
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = RefreshGrabberInternal();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::RefreshGrabberInternal() {
   if (!mAbsolutelyPositionedObject) {
     return NS_OK;
   }
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -309,17 +309,17 @@ NS_IMETHODIMP
 HTMLEditor::CheckSelectionStateForAnonymousButtons() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = RefereshEditingUI();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::RefereshEditingUI() {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   // First, we need to remove unnecessary editing UI now since some of them
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -176,23 +176,18 @@ HTMLEditor::InsertHTML(const nsAString& 
   AutoEditActionDataSetter editActionData(*this, EditAction::eInsertHTML);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = DoInsertHTMLWithContext(aInString, EmptyString(), EmptyString(),
                                         EmptyString(), nullptr,
                                         EditorDOMPoint(), true, true, false);
-  if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
-    // Return NS_OK when editor is destroyed since it's expected by the
-    // web app.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::DoInsertHTMLWithContext(
     const nsAString& aInputString, const nsAString& aContextStr,
     const nsAString& aInfoStr, const nsAString& aFlavor, Document* aSourceDoc,
     const EditorDOMPoint& aPointToInsert, bool aDoDeleteSelection,
@@ -978,29 +973,25 @@ nsresult HTMLEditor::BlobReader::OnResul
 
   nsString blobType;
   mBlob->GetType(blobType);
 
   NS_ConvertUTF16toUTF8 type(blobType);
   nsAutoString stuffToPaste;
   nsresult rv = ImgFromData(type, aResult, stuffToPaste);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   AutoPlaceholderBatch treatAsOneTransaction(*mHTMLEditor);
   rv = mHTMLEditor->DoInsertHTMLWithContext(
       stuffToPaste, EmptyString(), EmptyString(), NS_LITERAL_STRING(kFileMime),
       mSourceDoc, mPointToInsert, mDoDeleteSelection, mIsSafe, false);
-  if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
-    // Return NS_OK if the editor is destroyed since the web app expects it.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::BlobReader::OnError(const nsAString& aError) {
   const nsPromiseFlatString& flat = PromiseFlatString(aError);
   const char16_t* error = flat.get();
   nsContentUtils::ReportToConsole(
@@ -1551,17 +1542,17 @@ nsresult HTMLEditor::PasteTransferable(n
   if (!FireClipboardEvent(ePaste, nsIClipboard::kGlobalClipboard)) {
     return NS_OK;
   }
 
   nsAutoString contextStr, infoStr;
   nsresult rv = InsertFromTransferable(aTransferable, nullptr, contextStr,
                                        infoStr, false, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 /**
  * HTML PasteNoFormatting. Ignore any HTML styles and formating in paste source.
  */
 NS_IMETHODIMP
@@ -1578,24 +1569,26 @@ HTMLEditor::PasteNoFormatting(int32_t aS
   }
 
   CommitComposition();
 
   // Get Clipboard Service
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(
       do_GetService("@mozilla.org/widget/clipboard;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
   // Get the nsITransferable interface for getting the data from the clipboard.
   // use TextEditor::PrepareTransferable() to force unicode plaintext data.
   nsCOMPtr<nsITransferable> trans;
   rv = TextEditor::PrepareTransferable(getter_AddRefs(trans));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (!trans) {
     return NS_OK;
   }
 
   if (!IsModifiable()) {
     return NS_OK;
   }
@@ -1603,23 +1596,18 @@ HTMLEditor::PasteNoFormatting(int32_t aS
   // Get the Data from the clipboard
   rv = clipboard->GetData(trans, aSelectionType);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   const nsString& empty = EmptyString();
   rv = InsertFromTransferable(trans, nullptr, empty, empty, false, true);
-  if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
-    // Return NS_OK when editor is destroyed since it's expected by the
-    // web app.
-    return NS_OK;
-  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 // The following arrays contain the MIME types that we can paste. The arrays
 // are used by CanPaste() and CanPasteTransferable() below.
 
 static const char* textEditorFlavors[] = {kUnicodeMime};
@@ -1712,33 +1700,37 @@ nsresult HTMLEditor::PasteAsQuotationAsA
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
   editActionData.InitializeDataTransferWithClipboard(
       SettingDataTransfer::eWithFormat, aClipboardType);
 
   if (IsPlaintextEditor()) {
     // XXX In this case, we don't dispatch ePaste event.  Why?
-    return PasteAsPlaintextQuotation(aClipboardType);
+    nsresult rv = PasteAsPlaintextQuotation(aClipboardType);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return EditorBase::ToGenericNSResult(rv);
+    }
+    return NS_OK;
   }
 
   // If it's not in plain text edit mode, paste text into new
   // <blockquote type="cite"> element after removing selection.
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
       *this, EditSubAction::eInsertQuotation, nsIEditor::eNext);
 
   // Adjust Selection and clear cached style before inserting <blockquote>.
   EditSubActionInfo subActionInfo(EditSubAction::eInsertElement);
   bool cancel, handled;
   RefPtr<TextEditRules> rules(mRules);
   nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (cancel || handled) {
     return NS_OK;
   }
 
   // Then, remove Selection and create <blockquote type="cite"> now.
   // XXX Why don't we insert the <blockquote> into the DOM tree after
   //     pasting the content in clipboard into it?
@@ -1758,17 +1750,17 @@ nsresult HTMLEditor::PasteAsQuotationAsA
 
   // XXX Why don't we call HTMLEditRules::DidDoAction() after Paste()?
   // XXX If ePaste event has not been dispatched yet but selected content
   //     has already been removed and created a <blockquote> element.
   //     So, web apps cannot prevent the default of ePaste event which
   //     will be dispatched by PasteInternal().
   rv = PasteInternal(aClipboardType, aDispatchPasteEvent);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 /**
  * Paste a plaintext quotation.
  */
 nsresult HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType) {
@@ -1824,17 +1816,17 @@ nsresult HTMLEditor::InsertTextWithQuota
 
   // The whole operation should be undoable in one transaction:
   // XXX Why isn't enough to use only AutoPlaceholderBatch here?
   AutoTransactionBatch bundleAllTransactions(*this);
   AutoPlaceholderBatch treatAsOneTransaction(*this);
 
   nsresult rv = InsertTextWithQuotationsInternal(aStringToInsert);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::InsertTextWithQuotationsInternal(
     const nsAString& aStringToInsert) {
   // We're going to loop over the string, collecting up a "hunk"
   // that's all the same type (quoted or not),
@@ -1931,33 +1923,33 @@ nsresult HTMLEditor::InsertAsQuotation(c
     if (NS_WARN_IF(!editActionData.CanHandle())) {
       return NS_ERROR_NOT_INITIALIZED;
     }
     MOZ_ASSERT(!aQuotedText.IsVoid());
     editActionData.SetData(aQuotedText);
     AutoPlaceholderBatch treatAsOneTransaction(*this);
     nsresult rv = InsertAsPlaintextQuotation(aQuotedText, true, aNodeInserted);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
     return NS_OK;
   }
 
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eInsertBlockquoteElement);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   nsAutoString citation;
   nsresult rv = InsertAsCitedQuotationInternal(aQuotedText, citation, false,
                                                aNodeInserted);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 // Insert plaintext as a quotation, with cite marks (e.g. "> ").
 // This differs from its corresponding method in TextEditor
 // in that here, quoted material is enclosed in a <pre> tag
 // in order to preserve the original line wrapping.
@@ -2073,41 +2065,41 @@ HTMLEditor::Rewrap(bool aRespectNewlines
   }
 
   nsAutoString current;
   bool isCollapsed;
   nsresult rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted |
                                        nsIDocumentEncoder::OutputLFLineBreak,
                                    &isCollapsed, current);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   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_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   if (isCollapsed) {
     DebugOnly<nsresult> rv = SelectAllInternal();
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to select all text");
   }
 
   // The whole operation in InsertTextWithQuotationsInternal() should be
   // undoable in one transaction.
   // XXX Why isn't enough to use only AutoPlaceholderBatch here?
   AutoTransactionBatch bundleAllTransactions(*this);
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   rv = InsertTextWithQuotationsInternal(wrapped);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::InsertAsCitedQuotation(const nsAString& aQuotedText,
                                    const nsAString& aCitation, bool aInsertHTML,
                                    nsINode** aNodeInserted) {
@@ -2122,32 +2114,32 @@ HTMLEditor::InsertAsCitedQuotation(const
       return NS_ERROR_NOT_INITIALIZED;
     }
     MOZ_ASSERT(!aQuotedText.IsVoid());
     editActionData.SetData(aQuotedText);
 
     AutoPlaceholderBatch treatAsOneTransaction(*this);
     nsresult rv = InsertAsPlaintextQuotation(aQuotedText, true, aNodeInserted);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
     return NS_OK;
   }
 
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eInsertBlockquoteElement);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   nsresult rv = InsertAsCitedQuotationInternal(aQuotedText, aCitation,
                                                aInsertHTML, aNodeInserted);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::InsertAsCitedQuotationInternal(
     const nsAString& aQuotedText, const nsAString& aCitation, bool aInsertHTML,
     nsINode** aNodeInserted) {
   MOZ_ASSERT(IsEditActionDataAvailable());
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -190,17 +190,17 @@ NS_IMETHODIMP
 HTMLEditor::RefreshResizers() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = RefreshResizersInternal();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::RefreshResizersInternal() {
   // Don't warn even if resizers are not visible since script cannot check
   // if they are visible and this is non-virtual method.  So, the cost of
   // calling this can be ignored.
@@ -430,17 +430,17 @@ NS_IMETHODIMP
 HTMLEditor::HideResizers() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = HideResizersInternal();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::HideResizersInternal() {
   // Don't warn even if resizers are visible since script cannot check
   // if they are visible and this is non-virtual method.  So, the cost of
   // calling this can be ignored.
@@ -617,30 +617,38 @@ nsresult HTMLEditor::OnMouseDown(int32_t
       return NS_ERROR_NOT_INITIALIZED;
     }
 
     // If we have an anonymous element and that element is a resizer,
     // let's start resizing!
     aEvent->PreventDefault();
     mOriginalX = aClientX;
     mOriginalY = aClientY;
-    return StartResizing(aTarget);
+    nsresult rv = StartResizing(aTarget);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return EditorBase::ToGenericNSResult(rv);
+    }
+    return NS_OK;
   }
 
   if (anonclass.EqualsLiteral("mozGrabber")) {
     AutoEditActionDataSetter editActionData(*this, EditAction::eMoveElement);
     if (NS_WARN_IF(!editActionData.CanHandle())) {
       return NS_ERROR_NOT_INITIALIZED;
     }
 
     // If we have an anonymous element and that element is a grabber,
     // let's start moving the element!
     mOriginalX = aClientX;
     mOriginalY = aClientY;
-    return GrabberClicked();
+    nsresult rv = GrabberClicked();
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return EditorBase::ToGenericNSResult(rv);
+    }
+    return NS_OK;
   }
 
   return NS_OK;
 }
 
 nsresult HTMLEditor::OnMouseUp(int32_t aClientX, int32_t aClientY,
                                Element* aTarget) {
   if (mIsResizing) {
--- a/editor/libeditor/HTMLInlineTableEditor.cpp
+++ b/editor/libeditor/HTMLInlineTableEditor.cpp
@@ -202,17 +202,19 @@ nsresult HTMLEditor::DoInlineTableEditin
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<Element> tableElement = GetEnclosingTable(mInlineEditedCell);
   int32_t rowCount, colCount;
   nsresult rv = GetTableSize(tableElement, &rowCount, &colCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
 
   bool hideUI = false;
   bool hideResizersWithInlineTableUI = (mResizedObject == tableElement);
 
   if (anonclass.EqualsLiteral("mozTableAddColumnBefore")) {
     AutoEditActionDataSetter editActionData(*this,
                                             EditAction::eInsertTableColumn);
     if (NS_WARN_IF(!editActionData.CanHandle())) {
@@ -310,17 +312,17 @@ NS_IMETHODIMP
 HTMLEditor::RefreshInlineTableEditingUI() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = RefreshInlineTableEditingUIInternal();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::RefreshInlineTableEditingUIInternal() {
   if (!mInlineEditedCell) {
     return NS_OK;
   }
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -82,28 +82,28 @@ nsresult HTMLEditor::SetInlinePropertyAs
   }
 
   AutoTransactionBatch treatAsOneTransaction(*this);
 
   if (&aProperty == nsGkAtoms::sup) {
     // Superscript and Subscript styles are mutually exclusive.
     nsresult rv = RemoveInlinePropertyInternal(nsGkAtoms::sub, nullptr);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
   } else if (&aProperty == nsGkAtoms::sub) {
     // Superscript and Subscript styles are mutually exclusive.
     nsresult rv = RemoveInlinePropertyInternal(nsGkAtoms::sup, nullptr);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
   }
   nsresult rv = SetInlinePropertyInternal(aProperty, aAttribute, aValue);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetInlineProperty(const nsAString& aProperty,
                               const nsAString& aAttribute,
                               const nsAString& aValue) {
@@ -126,17 +126,21 @@ HTMLEditor::SetInlineProperty(const nsAS
       break;
     case EditAction::eSetColorProperty:
     case EditAction::eSetBackgroundColorPropertyInline:
       editActionData.SetColorData(aValue);
       break;
     default:
       break;
   }
-  return SetInlinePropertyInternal(*property, attribute, aValue);
+  nsresult rv = SetInlinePropertyInternal(*property, attribute, aValue);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult HTMLEditor::SetInlinePropertyInternal(nsAtom& aProperty,
                                                nsAtom* aAttribute,
                                                const nsAString& aValue) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   if (NS_WARN_IF(!mRules)) {
@@ -1184,18 +1188,22 @@ nsresult HTMLEditor::GetInlineProperty(n
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   const nsAString* val = nullptr;
   if (!aValue.IsEmpty()) val = &aValue;
-  return GetInlinePropertyBase(*aProperty, aAttribute, val, aFirst, aAny, aAll,
-                               nullptr);
+  nsresult rv = GetInlinePropertyBase(*aProperty, aAttribute, val, aFirst, aAny,
+                                      aAll, nullptr);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetInlinePropertyWithAttrValue(const nsAString& aProperty,
                                            const nsAString& aAttribute,
                                            const nsAString& aValue,
                                            bool* aFirst, bool* aAny, bool* aAll,
                                            nsAString& outValue) {
@@ -1215,34 +1223,40 @@ nsresult HTMLEditor::GetInlinePropertyWi
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   const nsAString* val = nullptr;
   if (!aValue.IsEmpty()) val = &aValue;
-  return GetInlinePropertyBase(*aProperty, aAttribute, val, aFirst, aAny, aAll,
-                               &outValue);
+  nsresult rv = GetInlinePropertyBase(*aProperty, aAttribute, val, aFirst, aAny,
+                                      aAll, &outValue);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveAllInlineProperties() {
   AutoEditActionDataSetter editActionData(
       *this, EditAction::eRemoveAllInlineStyleProperties);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
       *this, EditSubAction::eRemoveAllTextProperties, nsIEditor::eNext);
 
   nsresult rv = RemoveInlinePropertyInternal(nullptr, nullptr);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
   return NS_OK;
 }
 
 nsresult HTMLEditor::RemoveInlinePropertyAsAction(nsAtom& aProperty,
                                                   nsAtom* aAttribute) {
   AutoEditActionDataSetter editActionData(
       *this,
       HTMLEditUtils::GetEditActionForFormatText(aProperty, aAttribute, false));
@@ -1258,17 +1272,17 @@ nsresult HTMLEditor::RemoveInlinePropert
     case EditAction::eRemoveBackgroundColorPropertyInline:
       editActionData.SetColorData(EmptyString());
       break;
     default:
       break;
   }
   nsresult rv = RemoveInlinePropertyInternal(&aProperty, aAttribute);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveInlineProperty(const nsAString& aProperty,
                                  const nsAString& aAttribute) {
   RefPtr<nsAtom> property = NS_Atomize(aProperty);
@@ -1287,17 +1301,21 @@ HTMLEditor::RemoveInlineProperty(const n
       break;
     case EditAction::eRemoveColorProperty:
     case EditAction::eRemoveBackgroundColorPropertyInline:
       editActionData.SetColorData(EmptyString());
       break;
     default:
       break;
   }
-  return RemoveInlinePropertyInternal(property, attribute);
+  nsresult rv = RemoveInlinePropertyInternal(property, attribute);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult HTMLEditor::RemoveInlinePropertyInternal(nsAtom* aProperty,
                                                   nsAtom* aAttribute) {
   MOZ_ASSERT(IsEditActionDataAvailable());
   MOZ_ASSERT(aAttribute != nsGkAtoms::_empty);
 
   if (NS_WARN_IF(!mRules)) {
@@ -1450,28 +1468,36 @@ nsresult HTMLEditor::RemoveInlinePropert
 NS_IMETHODIMP
 HTMLEditor::IncreaseFontSize() {
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eIncrementFontSize);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return RelativeFontChange(FontSize::incr);
+  nsresult rv = RelativeFontChange(FontSize::incr);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::DecreaseFontSize() {
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eDecrementFontSize);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return RelativeFontChange(FontSize::decr);
+  nsresult rv = RelativeFontChange(FontSize::decr);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult HTMLEditor::RelativeFontChange(FontSize aDir) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   CommitComposition();
 
   // If selection is collapsed, set typing state
@@ -1804,31 +1830,35 @@ HTMLEditor::GetFontFaceState(bool* aMixe
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   bool first, any, all;
 
   nsresult rv = GetInlinePropertyBase(*nsGkAtoms::font, nsGkAtoms::face,
                                       nullptr, &first, &any, &all, &outFace);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
   if (any && !all) {
     return NS_OK;  // mixed
   }
   if (all) {
     *aMixed = false;
     return NS_OK;
   }
 
   // if there is no font face, check for tt
   rv = GetInlinePropertyBase(*nsGkAtoms::tt, nullptr, nullptr, &first, &any,
                              &all, nullptr);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
   if (any && !all) {
-    return rv;  // mixed
+    return EditorBase::ToGenericNSResult(rv);  // mixed
   }
   if (all) {
     *aMixed = false;
     outFace.AssignLiteral("tt");
   }
 
   if (!any) {
     // there was no font face attrs of any kind.  We are in normal font.
@@ -1850,17 +1880,17 @@ nsresult HTMLEditor::GetFontColorState(b
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   bool first, any, all;
   nsresult rv = GetInlinePropertyBase(*nsGkAtoms::font, nsGkAtoms::color,
                                       nullptr, &first, &any, &all, &aOutColor);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   if (any && !all) {
     return NS_OK;  // mixed
   }
   if (all) {
     *aMixed = false;
     return NS_OK;
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -156,17 +156,17 @@ HTMLEditor::InsertTableCell(int32_t aNum
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = InsertTableCellsWithTransaction(
       aNumberOfCellsToInsert, aInsertAfterSelectedCell
                                   ? InsertPosition::eAfterSelectedCell
                                   : InsertPosition::eBeforeSelectedCell);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return NS_ERROR_FAILURE;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::InsertTableCellsWithTransaction(
     int32_t aNumberOfCellsToInsert, InsertPosition aInsertPosition) {
   RefPtr<Element> table;
   RefPtr<Element> curCell;
@@ -252,17 +252,17 @@ HTMLEditor::GetFirstRow(Element* aTableO
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   ErrorResult error;
   RefPtr<Element> firstRowElement =
       GetFirstTableRowElement(*aTableOrElementInTable, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   firstRowElement.forget(aFirstRowElement);
   return NS_OK;
 }
 
 Element* HTMLEditor::GetFirstTableRowElement(Element& aTableOrElementInTable,
                                              ErrorResult& aRv) const {
   MOZ_ASSERT(!aRv.Failed());
@@ -573,17 +573,17 @@ HTMLEditor::InsertTableRow(int32_t aNumb
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = InsertTableRowsWithTransaction(
       aNumberOfRowsToInsert, aInsertAfterSelectedCell
                                  ? InsertPosition::eAfterSelectedCell
                                  : InsertPosition::eBeforeSelectedCell);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::InsertTableRowsWithTransaction(
     int32_t aNumberOfRowsToInsert, InsertPosition aInsertPosition) {
   RefPtr<Element> table;
   RefPtr<Element> curCell;
@@ -832,41 +832,41 @@ HTMLEditor::DeleteTable() {
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<Element> table;
   nsresult rv = GetCellContext(getter_AddRefs(table), nullptr, nullptr, nullptr,
                                nullptr, nullptr);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (NS_WARN_IF(!table)) {
     return NS_ERROR_FAILURE;
   }
 
   AutoPlaceholderBatch treateAsOneTransaction(*this);
   rv = DeleteTableElementAndChildrenWithTransaction(*table);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::DeleteTableCell(int32_t aNumberOfCellsToDelete) {
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eRemoveTableCellElement);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = DeleteTableCellWithTransaction(aNumberOfCellsToDelete);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::DeleteTableCellWithTransaction(
     int32_t aNumberOfCellsToDelete) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
@@ -1128,17 +1128,17 @@ HTMLEditor::DeleteTableCellContents() {
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eDeleteTableCellContents);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = DeleteTableCellContentsWithTransaction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::DeleteTableCellContentsWithTransaction() {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   RefPtr<Element> table;
@@ -1207,17 +1207,17 @@ HTMLEditor::DeleteTableColumn(int32_t aN
                                           EditAction::eRemoveTableColumn);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv =
       DeleteSelectedTableColumnsWithTransaction(aNumberOfColumnsToDelete);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::DeleteSelectedTableColumnsWithTransaction(
     int32_t aNumberOfColumnsToDelete) {
   RefPtr<Element> table;
   RefPtr<Element> cell;
@@ -1429,17 +1429,17 @@ HTMLEditor::DeleteTableRow(int32_t aNumb
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eRemoveTableRowElement);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = DeleteSelectedTableRowsWithTransaction(aNumberOfRowsToDelete);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::DeleteSelectedTableRowsWithTransaction(
     int32_t aNumberOfRowsToDelete) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
@@ -1683,39 +1683,47 @@ HTMLEditor::SelectTable() {
 
   RefPtr<Element> table =
       GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
   if (NS_WARN_IF(!table)) {
     return NS_OK;  // Don't fail if we didn't find a table.
   }
 
   nsresult rv = ClearSelection();
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return AppendNodeToSelectionAsRange(table);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  rv = AppendNodeToSelectionAsRange(table);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectTableCell() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<Element> cell = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::td);
   if (NS_WARN_IF(!cell)) {
     return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
   }
 
   nsresult rv = ClearSelection();
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-  return AppendNodeToSelectionAsRange(cell);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  rv = AppendNodeToSelectionAsRange(cell);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectBlockOfCells(Element* aStartCell, Element* aEndCell) {
   if (NS_WARN_IF(!aStartCell) || NS_WARN_IF(!aEndCell)) {
     return NS_ERROR_INVALID_ARG;
   }
 
@@ -1740,21 +1748,21 @@ HTMLEditor::SelectBlockOfCells(Element* 
   // so do nothing if not within one table
   if (table != endTable) {
     return NS_OK;
   }
 
   ErrorResult error;
   CellIndexes startCellIndexes(*aStartCell, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   CellIndexes endCellIndexes(*aEndCell, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   // Suppress nsISelectionListener notification
   // until all selection changes are finished
   SelectionBatcher selectionBatcher(SelectionRefPtr());
 
   // Examine all cell nodes in current selection and
   // remove those outside the new block cell region
@@ -1762,39 +1770,39 @@ HTMLEditor::SelectBlockOfCells(Element* 
       std::min(startCellIndexes.mColumn, endCellIndexes.mColumn);
   int32_t minRow = std::min(startCellIndexes.mRow, endCellIndexes.mRow);
   int32_t maxColumn =
       std::max(startCellIndexes.mColumn, endCellIndexes.mColumn);
   int32_t maxRow = std::max(startCellIndexes.mRow, endCellIndexes.mRow);
 
   RefPtr<Element> cell = GetFirstSelectedTableCellElement(error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   if (!cell) {
     return NS_OK;
   }
   RefPtr<nsRange> range = SelectionRefPtr()->GetRangeAt(0);
   MOZ_ASSERT(range);
   while (cell) {
     CellIndexes currentCellIndexes(*cell, error);
     if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
     if (currentCellIndexes.mRow < maxRow || currentCellIndexes.mRow > maxRow ||
         currentCellIndexes.mColumn < maxColumn ||
         currentCellIndexes.mColumn > maxColumn) {
       SelectionRefPtr()->RemoveRange(*range, IgnoreErrors());
       // Since we've removed the range, decrement pointer to next range
       MOZ_ASSERT(mSelectedCellIndex > 0);
       mSelectedCellIndex--;
     }
     cell = GetNextSelectedTableCellElement(error);
     if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
     if (cell) {
       MOZ_ASSERT(mSelectedCellIndex > 0);
       range = SelectionRefPtr()->GetRangeAt(mSelectedCellIndex - 1);
     }
   }
 
   nsresult rv = NS_OK;
@@ -1816,17 +1824,19 @@ HTMLEditor::SelectBlockOfCells(Element* 
         rv = AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
         }
       }
       MOZ_ASSERT(col < cellData.NextColumnIndex());
     }
   }
-  // NS_OK, otherwise, the last failure of AppendNodeToSelectionAsRange().
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
   return rv;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectAllTableCells() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
@@ -1845,17 +1855,17 @@ HTMLEditor::SelectAllTableCells() {
       GetElementOrParentByTagNameInternal(*nsGkAtoms::table, *cell);
   if (NS_WARN_IF(!table)) {
     return NS_ERROR_FAILURE;
   }
 
   ErrorResult error;
   TableSize tableSize(*this, *table, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   // Suppress nsISelectionListener notification
   // until all selection changes are finished
   SelectionBatcher selectionBatcher(SelectionRefPtr());
 
   // It is now safe to clear the selection
   // BE SURE TO RESET IT BEFORE LEAVING!
@@ -1884,21 +1894,27 @@ HTMLEditor::SelectAllTableCells() {
         }
         cellSelected = true;
       }
       MOZ_ASSERT(col < cellData.NextColumnIndex());
     }
   }
   // Safety code to select starting cell if nothing else was selected
   if (!cellSelected) {
-    return AppendNodeToSelectionAsRange(startCell);
-  }
-  // NS_OK, otherwise, the error of ClearSelection() when there is no column or
-  // the last failure of CellData or AppendNodeToSelectionAsRange().
-  return rv;
+    rv = AppendNodeToSelectionAsRange(startCell);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return EditorBase::ToGenericNSResult(rv);
+    }
+    return NS_OK;
+  }
+
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectTableRow() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
@@ -1914,26 +1930,26 @@ HTMLEditor::SelectTableRow() {
   // Get table and location of cell:
   RefPtr<Element> table;
   int32_t startRowIndex, startColIndex;
 
   nsresult rv =
       GetCellContext(getter_AddRefs(table), getter_AddRefs(cell), nullptr,
                      nullptr, &startRowIndex, &startColIndex);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (NS_WARN_IF(!table)) {
     return NS_ERROR_FAILURE;
   }
 
   ErrorResult error;
   TableSize tableSize(*this, *table, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   // Note: At this point, we could get first and last cells in row,
   // then call SelectBlockOfCells, but that would take just
   // a little less code, so the following is more efficient
 
   // Suppress nsISelectionListener notification
   // until all selection changes are finished
@@ -1966,19 +1982,20 @@ HTMLEditor::SelectTableRow() {
       cellSelected = true;
     }
     MOZ_ASSERT(col < cellData.NextColumnIndex());
   }
   // Safety code to select starting cell if nothing else was selected
   if (!cellSelected) {
     return AppendNodeToSelectionAsRange(startCell);
   }
-  // NS_OK, otherwise, the error of ClearSelection() when there is no column or
-  // the last failure of CellData or AppendNodeToSelectionAsRange().
-  return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectTableColumn() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
@@ -1994,26 +2011,26 @@ HTMLEditor::SelectTableColumn() {
   // Get location of cell:
   RefPtr<Element> table;
   int32_t startRowIndex, startColIndex;
 
   nsresult rv =
       GetCellContext(getter_AddRefs(table), getter_AddRefs(cell), nullptr,
                      nullptr, &startRowIndex, &startColIndex);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (NS_WARN_IF(!table)) {
     return NS_ERROR_FAILURE;
   }
 
   ErrorResult error;
   TableSize tableSize(*this, *table, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   // Suppress nsISelectionListener notification
   // until all selection changes are finished
   SelectionBatcher selectionBatcher(SelectionRefPtr());
 
   // It is now safe to clear the selection
   // BE SURE TO RESET IT BEFORE LEAVING!
@@ -2042,19 +2059,20 @@ HTMLEditor::SelectTableColumn() {
       cellSelected = true;
     }
     MOZ_ASSERT(row < cellData.NextRowIndex());
   }
   // Safety code to select starting cell if nothing else was selected
   if (!cellSelected) {
     return AppendNodeToSelectionAsRange(startCell);
   }
-  // NS_OK, otherwise, the error of ClearSelection() when there is no row or
-  // the last failure of CellData or AppendNodeToSelectionAsRange().
-  return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SplitTableCell() {
   AutoEditActionDataSetter editActionData(*this,
                                           EditAction::eSplitTableCellElement);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
@@ -2062,25 +2080,29 @@ HTMLEditor::SplitTableCell() {
 
   RefPtr<Element> table;
   RefPtr<Element> cell;
   int32_t startRowIndex, startColIndex, actualRowSpan, actualColSpan;
   // Get cell, table, etc. at selection anchor node
   nsresult rv =
       GetCellContext(getter_AddRefs(table), getter_AddRefs(cell), nullptr,
                      nullptr, &startRowIndex, &startColIndex);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
   if (!table || !cell) {
     return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
   }
 
   // We need rowspan and colspan data
   rv = GetCellSpansAt(table, startRowIndex, startColIndex, actualRowSpan,
                       actualColSpan);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
 
   // Must have some span to split
   if (actualRowSpan <= 1 && actualColSpan <= 1) {
     return NS_OK;
   }
 
   AutoPlaceholderBatch treateAsOneTransaction(*this);
   // Prevent auto insertion of BR in new cell until we're done
@@ -2099,25 +2121,29 @@ HTMLEditor::SplitTableCell() {
 
   // Split up cell row-wise first into rowspan=1 above, and the rest below,
   // whittling away at the cell below until no more extra span
   for (rowSpanBelow = actualRowSpan - 1; rowSpanBelow >= 0; rowSpanBelow--) {
     // We really split row-wise only if we had rowspan > 1
     if (rowSpanBelow > 0) {
       rv = SplitCellIntoRows(table, rowIndex, startColIndex, 1, rowSpanBelow,
                              getter_AddRefs(newCell));
-      NS_ENSURE_SUCCESS(rv, rv);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return EditorBase::ToGenericNSResult(rv);
+      }
       CopyCellBackgroundColor(newCell, cell);
     }
     int32_t colIndex = startColIndex;
     // Now split the cell with rowspan = 1 into cells if it has colSpan > 1
     for (colSpanAfter = actualColSpan - 1; colSpanAfter > 0; colSpanAfter--) {
       rv = SplitCellIntoColumns(table, rowIndex, colIndex, 1, colSpanAfter,
                                 getter_AddRefs(newCell));
-      NS_ENSURE_SUCCESS(rv, rv);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return EditorBase::ToGenericNSResult(rv);
+      }
       CopyCellBackgroundColor(newCell, cell);
       colIndex++;
     }
     // Point to the new cell and repeat
     rowIndex++;
   }
   return NS_OK;
 }
@@ -2371,62 +2397,62 @@ HTMLEditor::JoinTableCells(bool aMergeNo
   RefPtr<Element> targetCell;
   int32_t startRowIndex, startColIndex;
 
   // Get cell, table, etc. at selection anchor node
   nsresult rv =
       GetCellContext(getter_AddRefs(table), getter_AddRefs(targetCell), nullptr,
                      nullptr, &startRowIndex, &startColIndex);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (!table || !targetCell) {
     return NS_OK;
   }
 
   AutoPlaceholderBatch treateAsOneTransaction(*this);
   // Don't let Rules System change the selection
   AutoTransactionsConserveSelection dontChangeSelection(*this);
 
   // Note: We dont' use AutoSelectionSetterAfterTableEdit here so the selection
   // is retained after joining. This leaves the target cell selected
   // as well as the "non-contiguous" cells, so user can see what happened.
 
   ErrorResult error;
   CellAndIndexes firstSelectedCell(*this, *SelectionRefPtr(), error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   bool joinSelectedCells = false;
   if (firstSelectedCell.mElement) {
     RefPtr<Element> secondCell = GetNextSelectedTableCellElement(error);
     if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
 
     // If only one cell is selected, join with cell to the right
     joinSelectedCells = (secondCell != nullptr);
   }
 
   if (joinSelectedCells) {
     // We have selected cells: Join just contiguous cells
     // and just merge contents if not contiguous
     TableSize tableSize(*this, *table, error);
     if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
 
     // Get spans for cell we will merge into
     int32_t firstRowSpan, firstColSpan;
     rv = GetCellSpansAt(table, firstSelectedCell.mIndexes.mRow,
                         firstSelectedCell.mIndexes.mColumn, firstRowSpan,
                         firstColSpan);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
 
     // This defines the last indexes along the "edges"
     // of the contiguous block of cells, telling us
     // that we can join adjacent cells to the block
     // Start with same as the first values,
     // then expand as we find adjacent selected cells
     int32_t lastRowIndex = firstSelectedCell.mIndexes.mRow;
@@ -2436,17 +2462,17 @@ HTMLEditor::JoinTableCells(bool aMergeNo
     // we will join into one cell, favoring adjacent cells in the same row.
     IgnoredErrorResult ignoredError;
     for (int32_t rowIndex = firstSelectedCell.mIndexes.mRow;
          rowIndex <= lastRowIndex; rowIndex++) {
       int32_t currentRowCount = tableSize.mRowCount;
       // Be sure each row doesn't have rowspan errors
       rv = FixBadRowSpan(table, rowIndex, tableSize.mRowCount);
       if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
+        return EditorBase::ToGenericNSResult(rv);
       }
       // Adjust rowcount by number of rows we removed
       lastRowIndex -= currentRowCount - tableSize.mRowCount;
 
       bool cellFoundInRow = false;
       bool lastRowIsSet = false;
       int32_t lastColInRow = 0;
       int32_t firstColInRow = firstSelectedCell.mIndexes.mColumn;
@@ -2561,25 +2587,25 @@ HTMLEditor::JoinTableCells(bool aMergeNo
                                      cellData.mEffectiveColSpan -
                                      (lastColIndex + 1);
               if (extraColSpan > 0) {
                 rv = SplitCellIntoColumns(
                     table, cellData.mFirst.mRow, cellData.mFirst.mColumn,
                     cellData.mEffectiveColSpan - extraColSpan, extraColSpan,
                     nullptr);
                 if (NS_WARN_IF(NS_FAILED(rv))) {
-                  return rv;
+                  return EditorBase::ToGenericNSResult(rv);
                 }
               }
             }
 
             rv = MergeCells(firstSelectedCell.mElement, cellData.mElement,
                             false);
             if (NS_WARN_IF(NS_FAILED(rv))) {
-              return rv;
+              return EditorBase::ToGenericNSResult(rv);
             }
 
             // Add cell to list to delete
             deleteList.AppendElement(cellData.mElement.get());
           } else if (aMergeNonContiguousContents) {
             // Cell is outside join region -- just merge the contents
             rv = MergeCells(firstSelectedCell.mElement, cellData.mElement,
                             false);
@@ -2597,17 +2623,17 @@ HTMLEditor::JoinTableCells(bool aMergeNo
     AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
         *this, EditSubAction::eDeleteNode, nsIEditor::eNext);
 
     for (uint32_t i = 0, n = deleteList.Length(); i < n; i++) {
       RefPtr<Element> nodeToBeRemoved = deleteList[i];
       if (nodeToBeRemoved) {
         rv = DeleteNodeWithTransaction(*nodeToBeRemoved);
         if (NS_WARN_IF(NS_FAILED(rv))) {
-          return rv;
+          return EditorBase::ToGenericNSResult(rv);
         }
       }
     }
     // Cleanup selection: remove ranges where cells were deleted
     uint32_t rangeCount = SelectionRefPtr()->RangeCount();
 
     RefPtr<nsRange> range;
     for (uint32_t i = 0; i < rangeCount; i++) {
@@ -2624,22 +2650,22 @@ HTMLEditor::JoinTableCells(bool aMergeNo
         i--;
       }
     }
 
     // Set spans for the cell everything merged into
     rv = SetRowSpan(firstSelectedCell.mElement,
                     lastRowIndex - firstSelectedCell.mIndexes.mRow + 1);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
     rv = SetColSpan(firstSelectedCell.mElement,
                     lastColIndex - firstSelectedCell.mIndexes.mColumn + 1);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
 
     // Fixup disturbances in table layout
     DebugOnly<nsresult> rv = NormalizeTableInternal(*table);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to normalize the table");
   } else {
     // Joining with cell to the right -- get rowspan and colspan data of target
     // cell.
@@ -2678,52 +2704,52 @@ HTMLEditor::JoinTableCells(bool aMergeNo
     if (effectiveRowSpan2 > leftCellData.mEffectiveRowSpan) {
       // Cell to the right spans into row below target
       // Split off portion below target cell's bottom-most row
       rv = SplitCellIntoRows(
           table, rightCellData.mFirst.mRow, rightCellData.mFirst.mColumn,
           spanAboveMergedCell + leftCellData.mEffectiveRowSpan,
           effectiveRowSpan2 - leftCellData.mEffectiveRowSpan, nullptr);
       if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
+        return EditorBase::ToGenericNSResult(rv);
       }
     }
 
     // Move contents from cell to the right
     // Delete the cell now only if it starts in the same row
     //   and has enough row "height"
     rv = MergeCells(leftCellData.mElement, rightCellData.mElement,
                     !rightCellData.IsSpannedFromOtherRow() &&
                         effectiveRowSpan2 >= leftCellData.mEffectiveRowSpan);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
 
     if (effectiveRowSpan2 < leftCellData.mEffectiveRowSpan) {
       // Merged cell is "shorter"
       // (there are cells(s) below it that are row-spanned by target cell)
       // We could try splitting those cells, but that's REAL messy,
       // so the safest thing to do is NOT really join the cells
       return NS_OK;
     }
 
     if (spanAboveMergedCell > 0) {
       // Cell we merged started in a row above the target cell
       // Reduce rowspan to give room where target cell will extend its colspan
       rv = SetRowSpan(rightCellData.mElement, spanAboveMergedCell);
       if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
+        return EditorBase::ToGenericNSResult(rv);
       }
     }
 
     // Reset target cell's colspan to encompass cell to the right
     rv = SetColSpan(leftCellData.mElement, leftCellData.mEffectiveColSpan +
                                                rightCellData.mEffectiveColSpan);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::MergeCells(RefPtr<Element> aTargetCell,
                                 RefPtr<Element> aCellToMerge,
                                 bool aDeleteCellToMerge) {
@@ -2945,17 +2971,17 @@ HTMLEditor::NormalizeTable(Element* aTab
     aTableOrElementInTable =
         GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
     if (!aTableOrElementInTable) {
       return NS_OK;  // Don't throw error even if the element is not in <table>.
     }
   }
   nsresult rv = NormalizeTableInternal(*aTableOrElementInTable);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult HTMLEditor::NormalizeTableInternal(Element& aTableOrElementInTable) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   RefPtr<Element> tableElement;
@@ -3062,27 +3088,27 @@ HTMLEditor::GetCellIndexes(Element* aCel
   *aColumnIndex = 0;
 
   if (!aCellElement) {
     // Use cell element which contains anchor of Selection when aCellElement is
     // nullptr.
     ErrorResult error;
     CellIndexes cellIndexes(*this, *SelectionRefPtr(), error);
     if (error.Failed()) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
     *aRowIndex = cellIndexes.mRow;
     *aColumnIndex = cellIndexes.mColumn;
     return NS_OK;
   }
 
   ErrorResult error;
   CellIndexes cellIndexes(*aCellElement, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   *aRowIndex = cellIndexes.mRow;
   *aColumnIndex = cellIndexes.mColumn;
   return NS_OK;
 }
 
 void HTMLEditor::CellIndexes::Update(HTMLEditor& aHTMLEditor,
                                      Selection& aSelection, ErrorResult& aRv) {
@@ -3182,17 +3208,17 @@ HTMLEditor::GetTableSize(Element* aTable
     if (NS_WARN_IF(!tableOrElementInTable)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   ErrorResult error;
   TableSize tableSize(*this, *tableOrElementInTable, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   *aRowCount = tableSize.mRowCount;
   *aColumnCount = tableSize.mColumnCount;
   return NS_OK;
 }
 
 void HTMLEditor::TableSize::Update(HTMLEditor& aHTMLEditor,
                                    Element& aTableOrElementInTable,
@@ -3544,17 +3570,17 @@ HTMLEditor::GetFirstSelectedCell(nsRange
   if (aFirstSelectedRange) {
     *aFirstSelectedRange = nullptr;
   }
 
   ErrorResult error;
   RefPtr<Element> firstSelectedCellElement =
       GetFirstSelectedTableCellElement(error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   if (!firstSelectedCellElement) {
     // Just not found.  Don't return error.
     return NS_OK;
   }
   firstSelectedCellElement.forget(aFirstSelectedCellElement);
 
@@ -3622,17 +3648,17 @@ HTMLEditor::GetNextSelectedCell(nsRange*
   if (aNextSelectedCellRange) {
     *aNextSelectedCellRange = nullptr;
   }
 
   ErrorResult error;
   RefPtr<Element> nextSelectedCellElement =
       GetNextSelectedTableCellElement(error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   if (!nextSelectedCellElement) {
     // not more range, or met a range which does not select <td> nor <th>.
     return NS_OK;
   }
 
   if (aNextSelectedCellRange) {
@@ -3701,17 +3727,17 @@ HTMLEditor::GetFirstSelectedCellInTable(
 
   *aRowIndex = 0;
   *aColumnIndex = 0;
   *aCellElement = nullptr;
 
   ErrorResult error;
   CellAndIndexes result(*this, *SelectionRefPtr(), error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   result.mElement.forget(aCellElement);
   *aRowIndex = std::max(result.mIndexes.mRow, 0);
   *aColumnIndex = std::max(result.mIndexes.mColumn, 0);
   return NS_OK;
 }
 
 void HTMLEditor::CellAndIndexes::Update(HTMLEditor& aHTMLEditor,
@@ -3830,17 +3856,17 @@ HTMLEditor::GetSelectedOrParentTableElem
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   bool isCellSelected = false;
   ErrorResult aRv;
   RefPtr<Element> cellOrRowOrTableElement =
       GetSelectedOrParentTableElement(aRv, &isCellSelected);
   if (NS_WARN_IF(aRv.Failed())) {
-    return aRv.StealNSResult();
+    return EditorBase::ToGenericNSResult(aRv.StealNSResult());
   }
   if (!cellOrRowOrTableElement) {
     return NS_OK;
   }
 
   if (isCellSelected) {
     aTagName.AssignLiteral("td");
     *aSelectedCount = SelectionRefPtr()->RangeCount();
@@ -3960,23 +3986,23 @@ HTMLEditor::GetSelectedCellsType(Element
     if (NS_WARN_IF(!table)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   ErrorResult error;
   TableSize tableSize(*this, *table, error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
 
   // Traverse all selected cells
   RefPtr<Element> selectedCell = GetFirstSelectedTableCellElement(error);
   if (NS_WARN_IF(error.Failed())) {
-    return error.StealNSResult();
+    return EditorBase::ToGenericNSResult(error.StealNSResult());
   }
   if (!selectedCell) {
     return NS_OK;
   }
 
   // We have at least one selected cell, so set return value
   *aSelectionType = static_cast<uint32_t>(TableSelection::Cell);
 
@@ -3984,17 +4010,17 @@ HTMLEditor::GetSelectedCellsType(Element
   nsTArray<int32_t> indexArray;
 
   bool allCellsInRowAreSelected = false;
   bool allCellsInColAreSelected = false;
   IgnoredErrorResult ignoredError;
   while (selectedCell) {
     CellIndexes selectedCellIndexes(*selectedCell, error);
     if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
     if (!indexArray.Contains(selectedCellIndexes.mColumn)) {
       indexArray.AppendElement(selectedCellIndexes.mColumn);
       allCellsInRowAreSelected = AllCellsInRowSelected(
           table, selectedCellIndexes.mRow, tableSize.mColumnCount);
       // We're done as soon as we fail for any row
       if (!allCellsInRowAreSelected) {
         break;
@@ -4014,17 +4040,17 @@ HTMLEditor::GetSelectedCellsType(Element
   // Empty the indexArray
   indexArray.Clear();
 
   // Start at first cell again
   selectedCell = GetFirstSelectedTableCellElement(ignoredError);
   while (selectedCell) {
     CellIndexes selectedCellIndexes(*selectedCell, error);
     if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
+      return EditorBase::ToGenericNSResult(error.StealNSResult());
     }
 
     if (!indexArray.Contains(selectedCellIndexes.mRow)) {
       indexArray.AppendElement(selectedCellIndexes.mColumn);
       allCellsInColAreSelected = AllCellsInColumnSelected(
           table, selectedCellIndexes.mColumn, tableSize.mRowCount);
       // We're done as soon as we fail for any column
       if (!allCellsInRowAreSelected) {
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -193,35 +193,37 @@ nsresult TextEditor::EndEditorInit() {
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = InitRules();
-  if (NS_FAILED(rv)) {
-    return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
   }
   // Throw away the old transaction manager if this is not the first time that
   // we're initializing the editor.
   ClearUndoRedo();
   EnableUndoRedo();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditor::SetDocumentCharacterSet(const nsACString& characterSet) {
   AutoEditActionDataSetter editActionData(*this, EditAction::eSetCharacterSet);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   nsresult rv = EditorBase::SetDocumentCharacterSet(characterSet);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
 
   // Update META charset element.
   RefPtr<Document> doc = GetDocument();
   if (NS_WARN_IF(!doc)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   if (UpdateMetaCharset(*doc, characterSet)) {
@@ -407,33 +409,33 @@ nsresult TextEditor::OnInputText(const n
     return NS_ERROR_NOT_INITIALIZED;
   }
   MOZ_ASSERT(!aStringToInsert.IsVoid());
   editActionData.SetData(aStringToInsert);
 
   AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName);
   nsresult rv = InsertTextAsSubAction(aStringToInsert);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult TextEditor::InsertLineBreakAsAction() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eInsertLineBreak);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // XXX This may be called by execCommand() with "insertParagraph".
   //     In such case, naming the transaction "TypingTxnName" is odd.
   AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName);
   nsresult rv = InsertLineBreakAsSubAction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 template <typename PT, typename CT>
 already_AddRefed<Element> TextEditor::InsertBrElementWithTransaction(
     const EditorDOMPointBase<PT, CT>& aPointToInsert,
     EDirection aSelect /* = eNone */) {
@@ -691,17 +693,17 @@ nsresult TextEditor::DeleteSelectionAsAc
       case eToEndOfLine: {
         if (mCaretStyle != 1) {
           aDirection = eNone;
           break;
         }
         ErrorResult error;
         SelectionRefPtr()->CollapseToStart(error);
         if (NS_WARN_IF(error.Failed())) {
-          return error.StealNSResult();
+          return EditorBase::ToGenericNSResult(error.StealNSResult());
         }
         break;
       }
       default:
         break;
     }
   }
 
@@ -727,17 +729,17 @@ nsresult TextEditor::DeleteSelectionAsAc
         break;
     }
   }
 
   // delete placeholder txns merge.
   AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::DeleteTxnName);
   nsresult rv = DeleteSelectionAsSubAction(aDirection, aStripWrappers);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult TextEditor::DeleteSelectionAsSubAction(EDirection aDirection,
                                                 EStripWrappers aStripWrappers) {
   MOZ_ASSERT(IsEditActionDataAvailable());
   MOZ_ASSERT(mPlaceholderBatch);
@@ -987,17 +989,17 @@ nsresult TextEditor::InsertTextAsAction(
   // Note that we don't need to replace native line breaks with XP line breaks
   // here because Chrome does not do it.
   MOZ_ASSERT(!aStringToInsert.IsVoid());
   editActionData.SetData(aStringToInsert);
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   nsresult rv = InsertTextAsSubAction(aStringToInsert);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult TextEditor::InsertTextAsSubAction(const nsAString& aStringToInsert) {
   MOZ_ASSERT(IsEditActionDataAvailable());
   MOZ_ASSERT(mPlaceholderBatch);
 
@@ -1052,17 +1054,17 @@ TextEditor::InsertLineBreak() {
   AutoEditActionDataSetter editActionData(*this, EditAction::eInsertLineBreak);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   nsresult rv = InsertLineBreakAsSubAction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult TextEditor::InsertLineBreakAsSubAction() {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   if (!mRules) {
@@ -1099,17 +1101,17 @@ nsresult TextEditor::SetText(const nsASt
   AutoEditActionDataSetter editActionData(*this, EditAction::eSetText);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   AutoPlaceholderBatch treatAsOneTransaction(*this);
   nsresult rv = SetTextAsSubAction(aString);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult TextEditor::ReplaceTextAsAction(
     const nsAString& aString, nsRange* aReplaceRange /* = nullptr */) {
   AutoEditActionDataSetter editActionData(*this, EditAction::eReplaceText);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
@@ -1125,17 +1127,17 @@ nsresult TextEditor::ReplaceTextAsAction
 
   // This should emulates inserting text for better undo/redo behavior.
   AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
       *this, EditSubAction::eInsertText, nsIEditor::eNext);
 
   if (!aReplaceRange) {
     nsresult rv = SetTextAsSubAction(aString);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
     return NS_OK;
   }
 
   if (NS_WARN_IF(aString.IsEmpty() && aReplaceRange->Collapsed())) {
     return NS_OK;
   }
 
@@ -1153,17 +1155,17 @@ nsresult TextEditor::ReplaceTextAsAction
   ErrorResult error;
   SelectionRefPtr()->AddRange(*aReplaceRange, error);
   if (NS_WARN_IF(error.Failed())) {
     return error.StealNSResult();
   }
 
   rv = ReplaceSelectionAsSubAction(aString);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 nsresult TextEditor::SetTextAsSubAction(const nsAString& aString) {
   MOZ_ASSERT(IsEditActionDataAvailable());
   MOZ_ASSERT(mPlaceholderBatch);
 
@@ -1362,17 +1364,20 @@ nsresult TextEditor::OnCompositionChange
   // Note that if the composition will be committed by the following
   // compositionend event, we don't need to notify editor observes of this
   // change.
   // NOTE: We must notify after the auto batch will be gone.
   if (!aCompositionChangeEvent.IsFollowedByCompositionEnd()) {
     NotifyEditorObservers(eNotifyEditorObserversOfEnd);
   }
 
-  return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 void TextEditor::OnCompositionEnd(
     WidgetCompositionEvent& aCompositionEndEvent) {
   if (NS_WARN_IF(!mComposition)) {
     return;
   }
 
@@ -1658,17 +1663,20 @@ TextEditor::Undo(uint32_t aCount) {
       }
       rv = rules->DidDoAction(subActionInfo, rv);
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                            "TextEditRules::DidDoAction() failed");
     }
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
-  return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditor::Redo(uint32_t aCount) {
   // If we don't have transaction in the redo stack, we shouldn't notify
   // anybody of trying to redo since it's not useful notification but we
   // need to pay some runtime cost.
   if (!CanRedo()) {
@@ -1717,17 +1725,20 @@ TextEditor::Redo(uint32_t aCount) {
       }
       rv = rules->DidDoAction(subActionInfo, rv);
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                            "TextEditRules::DidDoAction() failed");
     }
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
-  return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 bool TextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed) {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   if (aPasswordFieldAllowed == ePasswordFieldNotAllowed && IsPasswordEditor()) {
     return false;
   }
@@ -1912,18 +1923,24 @@ NS_IMETHODIMP
 TextEditor::OutputToString(const nsAString& aFormatType,
                            uint32_t aDocumentEncoderFlags,
                            nsAString& aOutputString) {
   AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return ComputeValueInternal(aFormatType, aDocumentEncoderFlags,
-                              aOutputString);
+  nsresult rv =
+      ComputeValueInternal(aFormatType, aDocumentEncoderFlags, aOutputString);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    // This is low level API for XUL applcation.  So, we should return raw
+    // error code here.
+    return rv;
+  }
+  return NS_OK;
 }
 
 nsresult TextEditor::ComputeValueInternal(const nsAString& aFormatType,
                                           uint32_t aDocumentEncoderFlags,
                                           nsAString& aOutputString) const {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   // Protect the edit rules object from dying
@@ -1983,49 +2000,49 @@ nsresult TextEditor::PasteAsQuotationAsA
   }
 
   // XXX Why don't we dispatch ePaste event here?
 
   // Get the nsITransferable interface for getting the data from the clipboard
   nsCOMPtr<nsITransferable> trans;
   rv = PrepareTransferable(getter_AddRefs(trans));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (!trans) {
     return NS_OK;
   }
 
   // Get the Data from the clipboard
   clipboard->GetData(trans, aClipboardType);
 
   // Now we ask the transferable for the data
   // it still owns the data, we just have a pointer to it.
   // If it can't support a "text" output of the data the call will fail
   nsCOMPtr<nsISupports> genericDataObj;
   nsAutoCString flav;
   rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj));
-  if (NS_FAILED(rv)) {
-    return rv;
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
   }
 
   if (!flav.EqualsLiteral(kUnicodeMime) &&
       !flav.EqualsLiteral(kMozTextInternal)) {
     return NS_OK;
   }
 
   if (nsCOMPtr<nsISupportsString> text = do_QueryInterface(genericDataObj)) {
     nsAutoString stuffToPaste;
     text->GetData(stuffToPaste);
     editActionData.SetData(stuffToPaste);
     if (!stuffToPaste.IsEmpty()) {
       AutoPlaceholderBatch treatAsOneTransaction(*this);
       rv = InsertWithQuotationsAsSubAction(stuffToPaste);
       if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
+        return EditorBase::ToGenericNSResult(rv);
       }
     }
   }
   return NS_OK;
 }
 
 nsresult TextEditor::InsertWithQuotationsAsSubAction(
     const nsAString& aQuotedText) {
@@ -2179,46 +2196,54 @@ nsresult TextEditor::SetAttributeOrEquiv
     return NS_ERROR_INVALID_ARG;
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return SetAttributeWithTransaction(*aElement, *aAttribute, aValue);
+  nsresult rv = SetAttributeWithTransaction(*aElement, *aAttribute, aValue);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult TextEditor::RemoveAttributeOrEquivalent(Element* aElement,
                                                  nsAtom* aAttribute,
                                                  bool aSuppressTransaction) {
   if (NS_WARN_IF(!aElement) || NS_WARN_IF(!aAttribute)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eRemoveAttribute);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
-  return RemoveAttributeWithTransaction(*aElement, *aAttribute);
+  nsresult rv = RemoveAttributeWithTransaction(*aElement, *aAttribute);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 nsresult TextEditor::HideLastPasswordInput() {
   // This method should be called only by TextEditRules::Notify().
   MOZ_ASSERT(mRules);
   MOZ_ASSERT(IsPasswordEditor());
   MOZ_ASSERT(!IsEditActionDataAvailable());
 
   AutoEditActionDataSetter editActionData(*this, EditAction::eHidePassword);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   RefPtr<TextEditRules> rules(mRules);
   nsresult rv = rules->HideLastPasswordInput();
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 }  // namespace mozilla
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -228,18 +228,22 @@ class TextEditor : public EditorBase, pu
    * @param aCharset                Encoding of the document.
    */
   nsresult ComputeTextValue(uint32_t aDocumentEncoderFlags,
                             nsAString& aOutputString) const {
     AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
     if (NS_WARN_IF(!editActionData.CanHandle())) {
       return NS_ERROR_NOT_INITIALIZED;
     }
-    return ComputeValueInternal(NS_LITERAL_STRING("text/plain"),
-                                aDocumentEncoderFlags, aOutputString);
+    nsresult rv = ComputeValueInternal(NS_LITERAL_STRING("text/plain"),
+                                       aDocumentEncoderFlags, aOutputString);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return EditorBase::ToGenericNSResult(rv);
+    }
+    return NS_OK;
   }
 
  protected:  // May be called by friends.
   /****************************************************************************
    * Some classes like TextEditRules, HTMLEditRules, WSRunObject which are
    * part of handling edit actions are allowed to call the following protected
    * methods.  However, those methods won't prepare caches of some objects
    * which are necessary for them.  So, if you want some following methods
--- a/editor/libeditor/TextEditorDataTransfer.cpp
+++ b/editor/libeditor/TextEditorDataTransfer.cpp
@@ -267,17 +267,17 @@ nsresult TextEditor::OnDrop(DragEvent* a
 
   // Remove selected contents first here because we need to fire a pair of
   // "beforeinput" and "input" for deletion and web apps can cancel only
   // this deletion.  Note that callee may handle insertion asynchronously.
   // Therefore, it is the best to remove selected content here.
   if (deleteSelection && !SelectionRefPtr()->IsCollapsed()) {
     nsresult rv = PrepareToInsertContent(droppedAt, true);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
     // Now, Selection should be collapsed at dropped point.  If somebody
     // changed Selection, we should think what should do it in such case
     // later.
     if (NS_WARN_IF(!SelectionRefPtr()->IsCollapsed()) ||
         NS_WARN_IF(!SelectionRefPtr()->RangeCount())) {
       return NS_ERROR_FAILURE;
     }
@@ -286,17 +286,17 @@ nsresult TextEditor::OnDrop(DragEvent* a
       return NS_ERROR_FAILURE;
     }
 
     // Let's fire "input" event for the deletion now.
     if (mDispatchInputEvent) {
       RefPtr<DataTransfer> dataTransfer;  // Required due to bug 1506439
       FireInputEvent(EditAction::eDeleteByDrag, VoidString(), dataTransfer);
       if (NS_WARN_IF(Destroyed())) {
-        return NS_ERROR_EDITOR_DESTROYED;
+        return NS_OK;
       }
     }
 
     // XXX Now, Selection may be changed by input event listeners.  If so,
     //     should we update |droppedAt|?
   }
 
   if (!AsHTMLEditor()) {
@@ -335,26 +335,26 @@ nsresult TextEditor::OnDrop(DragEvent* a
     editActionData.SetData(data);
 
     // Then, insert the text.  Note that we shouldn't need to walk the array
     // anymore because nobody should listen to mutation events of anonymous
     // text node in <input>/<textarea>.
     nsContentUtils::PlatformToDOMLineBreaks(data);
     InsertTextAt(data, droppedAt, false);
     if (NS_WARN_IF(Destroyed())) {
-      return NS_ERROR_EDITOR_DESTROYED;
+      return NS_OK;
     }
   } else {
     editActionData.InitializeDataTransfer(dataTransfer);
     RefPtr<HTMLEditor> htmlEditor(AsHTMLEditor());
     for (uint32_t i = 0; i < numItems; ++i) {
       htmlEditor->InsertFromDataTransfer(dataTransfer, i, srcdoc, droppedAt,
                                          false);
       if (NS_WARN_IF(Destroyed())) {
-        return NS_ERROR_EDITOR_DESTROYED;
+        return NS_OK;
       }
     }
   }
 
   ScrollSelectionIntoView(false);
 
   return NS_OK;
 }
@@ -367,17 +367,17 @@ nsresult TextEditor::PasteAsAction(int32
   }
 
   if (AsHTMLEditor()) {
     editActionData.InitializeDataTransferWithClipboard(
         SettingDataTransfer::eWithFormat, aClipboardType);
     nsresult rv =
         AsHTMLEditor()->PasteInternal(aClipboardType, aDispatchPasteEvent);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
+      return EditorBase::ToGenericNSResult(rv);
     }
     return NS_OK;
   }
 
   if (aDispatchPasteEvent && !FireClipboardEvent(ePaste, aClipboardType)) {
     return NS_OK;
   }
 
@@ -388,33 +388,33 @@ nsresult TextEditor::PasteAsAction(int32
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Get the nsITransferable interface for getting the data from the clipboard
   nsCOMPtr<nsITransferable> transferable;
   rv = PrepareTransferable(getter_AddRefs(transferable));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   if (NS_WARN_IF(!transferable)) {
     return NS_OK;  // XXX Why?
   }
   // Get the Data from the clipboard.
   rv = clipboard->GetData(transferable, aClipboardType);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return NS_OK;  // XXX Why?
   }
   // XXX Why don't we check this first?
   if (!IsModifiable()) {
     return NS_OK;
   }
   rv = InsertTextFromTransferable(transferable);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+    return EditorBase::ToGenericNSResult(rv);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditor::PasteTransferable(nsITransferable* aTransferable) {
   AutoEditActionDataSetter editActionData(*this, EditAction::ePaste);
   if (NS_WARN_IF(!editActionData.CanHandle())) {
@@ -427,17 +427,21 @@ TextEditor::PasteTransferable(nsITransfe
   if (!FireClipboardEvent(ePaste, -1)) {
     return NS_OK;
   }
 
   if (!IsModifiable()) {
     return NS_OK;
   }
 
-  return InsertTextFromTransferable(aTransferable);
+  nsresult rv = InsertTextFromTransferable(aTransferable);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return EditorBase::ToGenericNSResult(rv);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 TextEditor::CanPaste(int32_t aSelectionType, bool* aCanPaste) {
   NS_ENSURE_ARG_POINTER(aCanPaste);
   *aCanPaste = false;
 
   // Always enable the paste command when inside of a HTML or XHTML document.