Bug 1310618 Replace nsresult variables |res| with |rv| under editor/ r=Ehsan
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 19 Oct 2016 18:09:33 +0900
changeset 361663 ae369aab847900e5c0a10a827758323604b42c87
parent 361662 4cf392058707f29b43d8255e9886be0901c580e5
child 361664 1aec2f248ad267ecee8b829671652e179937211b
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1310618
milestone52.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 1310618 Replace nsresult variables |res| with |rv| under editor/ r=Ehsan In our coding rules, variable names of nsresult should be rv. Indeed, when you see |rv| in the code, you must assume that its type if nsresult. However, a lot of code under editor/ uses |res| for the variables of nsresult. Let's replace |res| with |rv|. And this patch improves following points: 1. When |rv| is set in both |if| and |else| block and they are check outside of them, this moves the check into each |if| and |else| block because even if the failure is notified with warning, you cannot see which case was performed and failed. This change makes it clear. 2. When |return rv;| returns non-error code because |rv| is checked with NS_ENSURE_SUCCESS() immediately before, setting replacing it with |return NS_OK;| is clearer. 3. Move declaration of |nsresult rv| into smaller scope as far as possible. This prevents setting rv to unexpected value and easier to check its value at reading the code. MozReview-Commit-ID: 9MAqj7sFey3
editor/composer/nsComposerCommands.cpp
editor/libeditor/CSSEditUtils.cpp
editor/libeditor/CompositionTransaction.cpp
editor/libeditor/DeleteRangeTransaction.cpp
editor/libeditor/DeleteTextTransaction.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorUtils.cpp
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLAnonymousNodeEditor.cpp
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLInlineTableEditor.cpp
editor/libeditor/HTMLStyleEditor.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/InsertTextTransaction.cpp
editor/libeditor/SelectionState.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditor.cpp
editor/libeditor/TextEditorDataTransfer.cpp
editor/libeditor/WSRunObject.cpp
--- a/editor/composer/nsComposerCommands.cpp
+++ b/editor/composer/nsComposerCommands.cpp
@@ -1052,18 +1052,18 @@ nsDecreaseZIndexCommand::IsCommandEnable
   if (!(*outCmdEnabled))
     return NS_OK;
 
   nsCOMPtr<nsIDOMElement> positionedElement;
   htmlEditor->GetPositionedElement(getter_AddRefs(positionedElement));
   *outCmdEnabled = false;
   if (positionedElement) {
     int32_t z;
-    nsresult res = htmlEditor->GetElementZIndex(positionedElement, &z);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = htmlEditor->GetElementZIndex(positionedElement, &z);
+    NS_ENSURE_SUCCESS(rv, rv);
     *outCmdEnabled = (z > 0);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDecreaseZIndexCommand::DoCommand(const char *aCommandName,
--- a/editor/libeditor/CSSEditUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -584,18 +584,18 @@ nsresult
 CSSEditUtils::RemoveCSSInlineStyle(nsIDOMNode* aNode,
                                    nsIAtom* aProperty,
                                    const nsAString& aPropertyValue)
 {
   nsCOMPtr<Element> element = do_QueryInterface(aNode);
   NS_ENSURE_STATE(element);
 
   // remove the property from the style attribute
-  nsresult res = RemoveCSSProperty(*element, *aProperty, aPropertyValue);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = RemoveCSSProperty(*element, *aProperty, aPropertyValue);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (!element->IsHTMLElement(nsGkAtoms::span) ||
       HTMLEditor::HasAttributes(element)) {
     return NS_OK;
   }
 
   return mHTMLEditor->RemoveContainer(element);
 }
@@ -898,22 +898,22 @@ CSSEditUtils::SetCSSEquivalentToHTMLStyl
 {
   MOZ_ASSERT(aElement && aProperty);
   MOZ_ASSERT_IF(aAttribute, aValue);
   int32_t count;
   // This can only fail if SetCSSProperty fails, which should only happen if
   // something is pretty badly wrong.  In this case we assert so that hopefully
   // someone will notice, but there's nothing more sensible to do than just
   // return the count and carry on.
-  nsresult res = SetCSSEquivalentToHTMLStyle(aElement->AsDOMNode(),
-                                             aProperty, aAttribute,
-                                             aValue, &count,
-                                             aSuppressTransaction);
-  NS_ASSERTION(NS_SUCCEEDED(res), "SetCSSEquivalentToHTMLStyle failed");
-  NS_ENSURE_SUCCESS(res, count);
+  nsresult rv = SetCSSEquivalentToHTMLStyle(aElement->AsDOMNode(),
+                                            aProperty, aAttribute,
+                                            aValue, &count,
+                                            aSuppressTransaction);
+  NS_ASSERTION(NS_SUCCEEDED(rv), "SetCSSEquivalentToHTMLStyle failed");
+  NS_ENSURE_SUCCESS(rv, count);
   return count;
 }
 
 nsresult
 CSSEditUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode* aNode,
                                           nsIAtom* aHTMLProperty,
                                           const nsAString* aAttribute,
                                           const nsAString* aValue,
@@ -934,19 +934,19 @@ CSSEditUtils::SetCSSEquivalentToHTMLStyl
   nsTArray<nsString> cssValueArray;
   GenerateCSSDeclarationsFromHTMLStyle(element, aHTMLProperty, aAttribute,
                                        aValue, cssPropertyArray, cssValueArray,
                                        false);
 
   // set the individual CSS inline styles
   *aCount = cssPropertyArray.Length();
   for (int32_t index = 0; index < *aCount; index++) {
-    nsresult res = SetCSSProperty(*element, *cssPropertyArray[index],
-                                  cssValueArray[index], aSuppressTransaction);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = SetCSSProperty(*element, *cssPropertyArray[index],
+                                 cssValueArray[index], aSuppressTransaction);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 // Remove from aNode the CSS inline style equivalent to HTMLProperty/aAttribute/aValue for the node
 nsresult
 CSSEditUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode* aNode,
                                              nsIAtom* aHTMLProperty,
@@ -982,21 +982,21 @@ CSSEditUtils::RemoveCSSEquivalentToHTMLS
   nsTArray<nsString> cssValueArray;
   GenerateCSSDeclarationsFromHTMLStyle(aElement, aHTMLProperty, aAttribute,
                                        aValue, cssPropertyArray, cssValueArray,
                                        true);
 
   // remove the individual CSS inline styles
   int32_t count = cssPropertyArray.Length();
   for (int32_t index = 0; index < count; index++) {
-    nsresult res = RemoveCSSProperty(*aElement,
-                                     *cssPropertyArray[index],
-                                     cssValueArray[index],
-                                     aSuppressTransaction);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = RemoveCSSProperty(*aElement,
+                                    *cssPropertyArray[index],
+                                    cssValueArray[index],
+                                    aSuppressTransaction);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 // returns in aValueString the list of values for the CSS equivalences to
 // the HTML style aHTMLProperty/aAttribute/aValueString for the node aNode;
 // the value of aStyleType controls the styles we retrieve : specified or
 // computed.
@@ -1021,19 +1021,19 @@ CSSEditUtils::GetCSSEquivalentToHTMLInli
   // get the CSS equivalence with last param true indicating we want only the
   // "gettable" properties
   GenerateCSSDeclarationsFromHTMLStyle(theElement, aHTMLProperty, aAttribute, nullptr,
                                        cssPropertyArray, cssValueArray, true);
   int32_t count = cssPropertyArray.Length();
   for (int32_t index = 0; index < count; index++) {
     nsAutoString valueString;
     // retrieve the specified/computed value of the property
-    nsresult res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
-                                            valueString, aStyleType);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
+                                           valueString, aStyleType);
+    NS_ENSURE_SUCCESS(rv, rv);
     // append the value to aValueString (possibly with a leading whitespace)
     if (index) {
       aValueString.Append(char16_t(' '));
     }
     aValueString.Append(valueString);
   }
   return NS_OK;
 }
@@ -1062,20 +1062,20 @@ bool
 CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
                                                   nsIAtom* aProperty,
                                                   const nsAString* aAttribute,
                                                   nsAString& aValue,
                                                   StyleType aStyleType)
 {
   MOZ_ASSERT(aNode && aProperty);
   bool isSet;
-  nsresult res = IsCSSEquivalentToHTMLInlineStyleSet(aNode->AsDOMNode(),
-                                                     aProperty, aAttribute,
-                                                     isSet, aValue, aStyleType);
-  NS_ENSURE_SUCCESS(res, false);
+  nsresult rv = IsCSSEquivalentToHTMLInlineStyleSet(aNode->AsDOMNode(),
+                                                    aProperty, aAttribute,
+                                                    isSet, aValue, aStyleType);
+  NS_ENSURE_SUCCESS(rv, false);
   return isSet;
 }
 
 nsresult
 CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
                 nsIDOMNode* aNode,
                 nsIAtom* aHTMLProperty,
                 const nsAString* aHTMLAttribute,
@@ -1086,19 +1086,20 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlin
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsAutoString htmlValueString(valueString);
   aIsSet = false;
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   do {
     valueString.Assign(htmlValueString);
     // get the value of the CSS equivalent styles
-    nsresult res = GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
-                                                        valueString, aStyleType);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
+                                           valueString, aStyleType);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // early way out if we can
     if (valueString.IsEmpty()) {
       return NS_OK;
     }
 
     if (nsGkAtoms::b == aHTMLProperty) {
       if (valueString.EqualsLiteral("bold")) {
@@ -1393,18 +1394,20 @@ CSSEditUtils::GetElementContainerOrSelf(
 
 nsresult
 CSSEditUtils::SetCSSProperty(nsIDOMElement* aElement,
                              const nsAString& aProperty,
                              const nsAString& aValue)
 {
   nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
   uint32_t length;
-  nsresult res = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
-  if (NS_FAILED(res) || !cssDecl) return res;
+  nsresult rv = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
+  if (NS_FAILED(rv) || !cssDecl) {
+    return rv;
+  }
 
   return cssDecl->SetProperty(aProperty,
                               aValue,
                               EmptyString());
 }
 
 nsresult
 CSSEditUtils::SetCSSPropertyPixels(nsIDOMElement* aElement,
--- a/editor/libeditor/CompositionTransaction.cpp
+++ b/editor/libeditor/CompositionTransaction.cpp
@@ -57,46 +57,51 @@ NS_IMETHODIMP
 CompositionTransaction::DoTransaction()
 {
   // Fail before making any changes if there's no selection controller
   nsCOMPtr<nsISelectionController> selCon;
   mEditorBase.GetSelectionController(getter_AddRefs(selCon));
   NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
 
   // Advance caret: This requires the presentation shell to get the selection.
-  nsresult res;
   if (mReplaceLength == 0) {
-    res = mTextNode->InsertData(mOffset, mStringToInsert);
+    nsresult rv = mTextNode->InsertData(mOffset, mStringToInsert);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   } else {
-    res = mTextNode->ReplaceData(mOffset, mReplaceLength, mStringToInsert);
+    nsresult rv =
+      mTextNode->ReplaceData(mOffset, mReplaceLength, mStringToInsert);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   }
-  NS_ENSURE_SUCCESS(res, res);
 
-  res = SetSelectionForRanges();
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = SetSelectionForRanges();
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CompositionTransaction::UndoTransaction()
 {
   // Get the selection first so we'll fail before making any changes if we
   // can't get it
   RefPtr<Selection> selection = mEditorBase.GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
 
-  nsresult res = mTextNode->DeleteData(mOffset, mStringToInsert.Length());
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mTextNode->DeleteData(mOffset, mStringToInsert.Length());
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // set the selection to the insertion point where the string was removed
-  res = selection->Collapse(mTextNode, mOffset);
-  NS_ASSERTION(NS_SUCCEEDED(res),
+  rv = selection->Collapse(mTextNode, mOffset);
+  NS_ASSERTION(NS_SUCCEEDED(rv),
                "Selection could not be collapsed after undo of IME insert.");
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CompositionTransaction::Merge(nsITransaction* aTransaction,
                               bool* aDidMerge)
 {
--- a/editor/libeditor/DeleteRangeTransaction.cpp
+++ b/editor/libeditor/DeleteRangeTransaction.cpp
@@ -58,54 +58,55 @@ DeleteRangeTransaction::Init(EditorBase*
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DeleteRangeTransaction::DoTransaction()
 {
   MOZ_ASSERT(mRange && mEditorBase);
-  nsresult res;
 
   // build the child transactions
   nsCOMPtr<nsINode> startParent = mRange->GetStartParent();
   int32_t startOffset = mRange->StartOffset();
   nsCOMPtr<nsINode> endParent = mRange->GetEndParent();
   int32_t endOffset = mRange->EndOffset();
   MOZ_ASSERT(startParent && endParent);
 
   if (startParent == endParent) {
     // the selection begins and ends in the same node
-    res = CreateTxnsToDeleteBetween(startParent, startOffset, endOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      CreateTxnsToDeleteBetween(startParent, startOffset, endOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     // the selection ends in a different node from where it started.  delete
     // the relevant content in the start node
-    res = CreateTxnsToDeleteContent(startParent, startOffset, nsIEditor::eNext);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      CreateTxnsToDeleteContent(startParent, startOffset, nsIEditor::eNext);
+    NS_ENSURE_SUCCESS(rv, rv);
     // delete the intervening nodes
-    res = CreateTxnsToDeleteNodesBetween();
-    NS_ENSURE_SUCCESS(res, res);
+    rv = CreateTxnsToDeleteNodesBetween();
+    NS_ENSURE_SUCCESS(rv, rv);
     // delete the relevant content in the end node
-    res = CreateTxnsToDeleteContent(endParent, endOffset, nsIEditor::ePrevious);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = CreateTxnsToDeleteContent(endParent, endOffset, nsIEditor::ePrevious);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // if we've successfully built this aggregate transaction, then do it.
-  res = EditAggregateTransaction::DoTransaction();
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = EditAggregateTransaction::DoTransaction();
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // only set selection to deletion point if editor gives permission
   bool bAdjustSelection;
   mEditorBase->ShouldTxnSetSelection(&bAdjustSelection);
   if (bAdjustSelection) {
     RefPtr<Selection> selection = mEditorBase->GetSelection();
     NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
-    res = selection->Collapse(startParent, startOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = selection->Collapse(startParent, startOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   // else do nothing - dom range gravity will adjust selection
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DeleteRangeTransaction::UndoTransaction()
@@ -147,38 +148,40 @@ DeleteRangeTransaction::CreateTxnsToDele
 
     RefPtr<nsGenericDOMDataNode> charDataNode =
       static_cast<nsGenericDOMDataNode*>(aNode);
 
     RefPtr<DeleteTextTransaction> transaction =
       new DeleteTextTransaction(*mEditorBase, *charDataNode, aStartOffset,
                                 numToDel, mRangeUpdater);
 
-    nsresult res = transaction->Init();
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = transaction->Init();
+    NS_ENSURE_SUCCESS(rv, rv);
 
     AppendChild(transaction);
     return NS_OK;
   }
 
   nsCOMPtr<nsIContent> child = aNode->GetChildAt(aStartOffset);
   NS_ENSURE_STATE(child);
 
-  nsresult res = NS_OK;
+  // XXX This looks odd.  Only when the last transaction causes error at
+  //     calling Init(), the result becomes error.  Otherwise, always NS_OK.
+  nsresult rv = NS_OK;
   for (int32_t i = aStartOffset; i < aEndOffset; ++i) {
     RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
-    res = transaction->Init(mEditorBase, child, mRangeUpdater);
-    if (NS_SUCCEEDED(res)) {
+    rv = transaction->Init(mEditorBase, child, mRangeUpdater);
+    if (NS_SUCCEEDED(rv)) {
       AppendChild(transaction);
     }
 
     child = child->GetNextSibling();
   }
 
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 nsresult
 DeleteRangeTransaction::CreateTxnsToDeleteContent(nsINode* aNode,
                                                   int32_t aOffset,
                                                   nsIEditor::EDirection aAction)
 {
@@ -196,41 +199,41 @@ DeleteRangeTransaction::CreateTxnsToDele
 
     if (numToDelete) {
       RefPtr<nsGenericDOMDataNode> dataNode =
         static_cast<nsGenericDOMDataNode*>(aNode);
       RefPtr<DeleteTextTransaction> transaction =
         new DeleteTextTransaction(*mEditorBase, *dataNode, start, numToDelete,
                                   mRangeUpdater);
 
-      nsresult res = transaction->Init();
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = transaction->Init();
+      NS_ENSURE_SUCCESS(rv, rv);
 
       AppendChild(transaction);
     }
   }
 
   return NS_OK;
 }
 
 nsresult
 DeleteRangeTransaction::CreateTxnsToDeleteNodesBetween()
 {
   nsCOMPtr<nsIContentIterator> iter = NS_NewContentSubtreeIterator();
 
-  nsresult res = iter->Init(mRange);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = iter->Init(mRange);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   while (!iter->IsDone()) {
     nsCOMPtr<nsINode> node = iter->GetCurrentNode();
     NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
-    res = transaction->Init(mEditorBase, node, mRangeUpdater);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = transaction->Init(mEditorBase, node, mRangeUpdater);
+    NS_ENSURE_SUCCESS(rv, rv);
     AppendChild(transaction);
 
     iter->Next();
   }
   return NS_OK;
 }
 
 } // namespace mozilla
--- a/editor/libeditor/DeleteTextTransaction.cpp
+++ b/editor/libeditor/DeleteTextTransaction.cpp
@@ -53,34 +53,34 @@ DeleteTextTransaction::Init()
 }
 
 NS_IMETHODIMP
 DeleteTextTransaction::DoTransaction()
 {
   MOZ_ASSERT(mCharData);
 
   // Get the text that we're about to delete
-  nsresult res = mCharData->SubstringData(mOffset, mNumCharsToDelete,
-                                          mDeletedText);
-  MOZ_ASSERT(NS_SUCCEEDED(res));
-  res = mCharData->DeleteData(mOffset, mNumCharsToDelete);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mCharData->SubstringData(mOffset, mNumCharsToDelete,
+                                         mDeletedText);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
+  rv = mCharData->DeleteData(mOffset, mNumCharsToDelete);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (mRangeUpdater) {
     mRangeUpdater->SelAdjDeleteText(mCharData, mOffset, mNumCharsToDelete);
   }
 
   // Only set selection to deletion point if editor gives permission
   if (mEditorBase.GetShouldTxnSetSelection()) {
     RefPtr<Selection> selection = mEditorBase.GetSelection();
     NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
-    res = selection->Collapse(mCharData, mOffset);
-    NS_ASSERTION(NS_SUCCEEDED(res),
+    rv = selection->Collapse(mCharData, mOffset);
+    NS_ASSERTION(NS_SUCCEEDED(rv),
                  "Selection could not be collapsed after undo of deletetext");
-    NS_ENSURE_SUCCESS(res, res);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   // Else do nothing - DOM Range gravity will adjust selection
   return NS_OK;
 }
 
 //XXX: We may want to store the selection state and restore it properly.  Was
 //     it an insertion point or an extended selection?
 NS_IMETHODIMP
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -656,18 +656,18 @@ EditorBase::GetSelection(SelectionType a
   }
   return selcon->GetSelection(ToRawSelectionType(aSelectionType), aSelection);
 }
 
 Selection*
 EditorBase::GetSelection(SelectionType aSelectionType)
 {
   nsCOMPtr<nsISelection> sel;
-  nsresult res = GetSelection(aSelectionType, getter_AddRefs(sel));
-  if (NS_WARN_IF(NS_FAILED(res)) || NS_WARN_IF(!sel)) {
+  nsresult rv = GetSelection(aSelectionType, getter_AddRefs(sel));
+  if (NS_WARN_IF(NS_FAILED(rv)) || NS_WARN_IF(!sel)) {
     return nullptr;
   }
 
   return sel->AsSelection();
 }
 
 NS_IMETHODIMP
 EditorBase::DoTransaction(nsITransaction* aTxn)
@@ -724,30 +724,30 @@ EditorBase::DoTransaction(nsITransaction
     // XXX: re-entry during initial reflow. - kin
 
     // get the selection and start a batch change
     RefPtr<Selection> selection = GetSelection();
     NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
     selection->StartBatchChanges();
 
-    nsresult res;
+    nsresult rv;
     if (mTxnMgr) {
-      res = mTxnMgr->DoTransaction(aTxn);
+      rv = mTxnMgr->DoTransaction(aTxn);
     } else {
-      res = aTxn->DoTransaction();
+      rv = aTxn->DoTransaction();
     }
-    if (NS_SUCCEEDED(res)) {
+    if (NS_SUCCEEDED(rv)) {
       DoAfterDoTransaction(aTxn);
     }
 
-    // no need to check res here, don't lose result of operation
+    // no need to check rv here, don't lose result of operation
     selection->EndBatchChanges();
 
-    NS_ENSURE_SUCCESS(res, res);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::EnableUndo(bool aEnable)
 {
@@ -1359,27 +1359,27 @@ EditorBase::CreateNode(nsIAtom* aTag,
     listener->WillCreateNode(nsDependentAtomString(aTag),
                              GetAsDOMNode(aParent), aPosition);
   }
 
   nsCOMPtr<Element> ret;
 
   RefPtr<CreateElementTransaction> transaction =
     CreateTxnForCreateElement(*aTag, *aParent, aPosition);
-  nsresult res = DoTransaction(transaction);
-  if (NS_SUCCEEDED(res)) {
+  nsresult rv = DoTransaction(transaction);
+  if (NS_SUCCEEDED(rv)) {
     ret = transaction->GetNewNode();
     MOZ_ASSERT(ret);
   }
 
   mRangeUpdater.SelAdjCreateNode(aParent, aPosition);
 
   for (auto& listener : mActionListeners) {
     listener->DidCreateNode(nsDependentAtomString(aTag), GetAsDOMNode(ret),
-                            GetAsDOMNode(aParent), aPosition, res);
+                            GetAsDOMNode(aParent), aPosition, rv);
   }
 
   return ret.forget();
 }
 
 NS_IMETHODIMP
 EditorBase::InsertNode(nsIDOMNode* aNode,
                        nsIDOMNode* aParent,
@@ -1565,50 +1565,49 @@ EditorBase::ReplaceContainer(Element* aO
 
   int32_t offset = parent->IndexOf(aOldContainer);
 
   // create new container
   nsCOMPtr<Element> ret = CreateHTMLContent(aNodeType);
   NS_ENSURE_TRUE(ret, nullptr);
 
   // set attribute if needed
-  nsresult res;
   if (aAttribute && aValue && aAttribute != nsGkAtoms::_empty) {
-    res = ret->SetAttr(kNameSpaceID_None, aAttribute, *aValue, true);
-    NS_ENSURE_SUCCESS(res, nullptr);
+    nsresult rv = ret->SetAttr(kNameSpaceID_None, aAttribute, *aValue, true);
+    NS_ENSURE_SUCCESS(rv, nullptr);
   }
   if (aCloneAttributes == eCloneAttributes) {
     CloneAttributes(ret, aOldContainer);
   }
 
   // notify our internal selection state listener
   // (Note: An AutoSelectionRestorer object must be created
   //  before calling this to initialize mRangeUpdater)
   AutoReplaceContainerSelNotify selStateNotify(mRangeUpdater, aOldContainer,
                                                ret);
   {
     AutoTransactionsConserveSelection conserveSelection(this);
     while (aOldContainer->HasChildren()) {
       nsCOMPtr<nsIContent> child = aOldContainer->GetFirstChild();
 
-      res = DeleteNode(child);
-      NS_ENSURE_SUCCESS(res, nullptr);
-
-      res = InsertNode(*child, *ret, -1);
-      NS_ENSURE_SUCCESS(res, nullptr);
+      nsresult rv = DeleteNode(child);
+      NS_ENSURE_SUCCESS(rv, nullptr);
+
+      rv = InsertNode(*child, *ret, -1);
+      NS_ENSURE_SUCCESS(rv, nullptr);
     }
   }
 
   // insert new container into tree
-  res = InsertNode(*ret, *parent, offset);
-  NS_ENSURE_SUCCESS(res, nullptr);
+  nsresult rv = InsertNode(*ret, *parent, offset);
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   // delete old container
-  res = DeleteNode(aOldContainer);
-  NS_ENSURE_SUCCESS(res, nullptr);
+  rv = DeleteNode(aOldContainer);
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   return ret.forget();
 }
 
 /**
  * RemoveContainer() removes inNode, reparenting its children (if any) into the
  * parent of inNode.
  */
@@ -1659,38 +1658,38 @@ EditorBase::InsertContainerAbove(nsICont
   NS_ENSURE_TRUE(parent, nullptr);
   int32_t offset = parent->IndexOf(aNode);
 
   // Create new container
   nsCOMPtr<Element> newContent = CreateHTMLContent(aNodeType);
   NS_ENSURE_TRUE(newContent, nullptr);
 
   // Set attribute if needed
-  nsresult res;
   if (aAttribute && aValue && aAttribute != nsGkAtoms::_empty) {
-    res = newContent->SetAttr(kNameSpaceID_None, aAttribute, *aValue, true);
-    NS_ENSURE_SUCCESS(res, nullptr);
+    nsresult rv =
+      newContent->SetAttr(kNameSpaceID_None, aAttribute, *aValue, true);
+    NS_ENSURE_SUCCESS(rv, nullptr);
   }
 
   // Notify our internal selection state listener
   AutoInsertContainerSelNotify selNotify(mRangeUpdater);
 
   // Put inNode in new parent, outNode
-  res = DeleteNode(aNode);
-  NS_ENSURE_SUCCESS(res, nullptr);
+  nsresult rv = DeleteNode(aNode);
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   {
     AutoTransactionsConserveSelection conserveSelection(this);
-    res = InsertNode(*aNode, *newContent, 0);
-    NS_ENSURE_SUCCESS(res, nullptr);
+    rv = InsertNode(*aNode, *newContent, 0);
+    NS_ENSURE_SUCCESS(rv, nullptr);
   }
 
   // Put new parent in doc
-  res = InsertNode(*newContent, *parent, offset);
-  NS_ENSURE_SUCCESS(res, nullptr);
+  rv = InsertNode(*newContent, *parent, offset);
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   return newContent.forget();
 }
 
 /**
  * MoveNode() moves aNode to {aParent,aOffset}.
  */
 nsresult
@@ -2369,52 +2368,51 @@ EditorBase::InsertTextImpl(const nsAStri
   nsCOMPtr<nsINode> node = *aInOutNode;
   int32_t offset = *aInOutOffset;
 
   // In some cases, the node may be the anonymous div elemnt or a mozBR
   // element.  Let's try to look for better insertion point in the nearest
   // text node if there is.
   FindBetterInsertionPoint(node, offset);
 
-  nsresult res;
   if (ShouldHandleIMEComposition()) {
     CheckedInt<int32_t> newOffset;
     if (!node->IsNodeOfType(nsINode::eTEXT)) {
       // create a text node
       RefPtr<nsTextNode> newNode = aDoc->CreateTextNode(EmptyString());
       // then we insert it into the dom tree
-      res = InsertNode(*newNode, *node, offset);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = InsertNode(*newNode, *node, offset);
+      NS_ENSURE_SUCCESS(rv, rv);
       node = newNode;
       offset = 0;
       newOffset = lengthToInsert;
     } else {
       newOffset = lengthToInsert + offset;
       NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
     }
-    res = InsertTextIntoTextNodeImpl(aStringToInsert, *node->GetAsText(),
-                                     offset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      InsertTextIntoTextNodeImpl(aStringToInsert, *node->GetAsText(), offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     offset = newOffset.value();
   } else {
     if (node->IsNodeOfType(nsINode::eTEXT)) {
       CheckedInt<int32_t> newOffset = lengthToInsert + offset;
       NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
       // we are inserting text into an existing text node.
-      res = InsertTextIntoTextNodeImpl(aStringToInsert, *node->GetAsText(),
-                                       offset);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        InsertTextIntoTextNodeImpl(aStringToInsert, *node->GetAsText(), offset);
+      NS_ENSURE_SUCCESS(rv, rv);
       offset = newOffset.value();
     } else {
       // we are inserting text into a non-text node.  first we have to create a
       // textnode (this also populates it with the text)
       RefPtr<nsTextNode> newNode = aDoc->CreateTextNode(aStringToInsert);
       // then we insert it into the dom tree
-      res = InsertNode(*newNode, *node, offset);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = InsertNode(*newNode, *node, offset);
+      NS_ENSURE_SUCCESS(rv, rv);
       node = newNode;
       offset = lengthToInsert.value();
     }
   }
 
   *aInOutNode = node;
   *aInOutOffset = offset;
   return NS_OK;
@@ -3898,18 +3896,18 @@ EditorBase::JoinNodeDeep(nsIContent& aLe
   while (leftNodeToJoin && rightNodeToJoin && parentNode &&
          AreNodesSameType(leftNodeToJoin, rightNodeToJoin)) {
     uint32_t length = leftNodeToJoin->Length();
 
     ret.node = rightNodeToJoin;
     ret.offset = length;
 
     // Do the join
-    nsresult res = JoinNodes(*leftNodeToJoin, *rightNodeToJoin);
-    NS_ENSURE_SUCCESS(res, EditorDOMPoint());
+    nsresult rv = JoinNodes(*leftNodeToJoin, *rightNodeToJoin);
+    NS_ENSURE_SUCCESS(rv, EditorDOMPoint());
 
     if (parentNode->GetAsText()) {
       // We've joined all the way down to text nodes, we're done!
       return ret;
     }
 
     // Get new left and right nodes, and begin anew
     parentNode = rightNodeToJoin;
@@ -4041,30 +4039,30 @@ EditorBase::DeleteSelectionImpl(EDirecti
   }
 
   return rv;
 }
 
 already_AddRefed<Element>
 EditorBase::DeleteSelectionAndCreateElement(nsIAtom& aTag)
 {
-  nsresult res = DeleteSelectionAndPrepareToCreateNode();
-  NS_ENSURE_SUCCESS(res, nullptr);
+  nsresult rv = DeleteSelectionAndPrepareToCreateNode();
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, nullptr);
 
   nsCOMPtr<nsINode> node = selection->GetAnchorNode();
   uint32_t offset = selection->AnchorOffset();
 
   nsCOMPtr<Element> newElement = CreateNode(&aTag, node, offset);
 
   // We want the selection to be just after the new node
-  res = selection->Collapse(node, offset + 1);
-  NS_ENSURE_SUCCESS(res, nullptr);
+  rv = selection->Collapse(node, offset + 1);
+  NS_ENSURE_SUCCESS(rv, nullptr);
 
   return newElement.forget();
 }
 
 TextComposition*
 EditorBase::GetComposition() const
 {
   return mComposition;
@@ -4083,24 +4081,23 @@ EditorBase::ShouldHandleIMEComposition()
   // InsertText().  In this time, the text should be inserted as not a part
   // of the composition.
   return mComposition && mDidPostCreate;
 }
 
 nsresult
 EditorBase::DeleteSelectionAndPrepareToCreateNode()
 {
-  nsresult res;
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   MOZ_ASSERT(selection->GetAnchorFocusRange());
 
   if (!selection->GetAnchorFocusRange()->Collapsed()) {
-    res = DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     MOZ_ASSERT(selection->GetAnchorFocusRange() &&
                selection->GetAnchorFocusRange()->Collapsed(),
                "Selection not collapsed after delete");
   }
 
   // If the selection is a chardata node, split it if necessary and compute
   // where to put the new node
@@ -4111,33 +4108,34 @@ EditorBase::DeleteSelectionAndPrepareToC
     NS_ASSERTION(node->GetParentNode(),
                  "It's impossible to insert into chardata with no parent -- "
                  "fix the caller");
     NS_ENSURE_STATE(node->GetParentNode());
 
     uint32_t offset = selection->AnchorOffset();
 
     if (offset == 0) {
-      res = selection->Collapse(node->GetParentNode(),
-                                node->GetParentNode()->IndexOf(node));
-      MOZ_ASSERT(NS_SUCCEEDED(res));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = selection->Collapse(node->GetParentNode(),
+                                        node->GetParentNode()->IndexOf(node));
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      NS_ENSURE_SUCCESS(rv, rv);
     } else if (offset == node->Length()) {
-      res = selection->Collapse(node->GetParentNode(),
-                                node->GetParentNode()->IndexOf(node) + 1);
-      MOZ_ASSERT(NS_SUCCEEDED(res));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        selection->Collapse(node->GetParentNode(),
+                            node->GetParentNode()->IndexOf(node) + 1);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       nsCOMPtr<nsIDOMNode> tmp;
-      res = SplitNode(node->AsDOMNode(), offset, getter_AddRefs(tmp));
-      NS_ENSURE_SUCCESS(res, res);
-      res = selection->Collapse(node->GetParentNode(),
-                                node->GetParentNode()->IndexOf(node));
-      MOZ_ASSERT(NS_SUCCEEDED(res));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = SplitNode(node->AsDOMNode(), offset, getter_AddRefs(tmp));
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = selection->Collapse(node->GetParentNode(),
+                               node->GetParentNode()->IndexOf(node));
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return NS_OK;
 }
 
 void
 EditorBase::DoAfterDoTransaction(nsITransaction* aTxn)
 {
@@ -4365,18 +4363,16 @@ EditorBase::CreateTxnForDeleteInsertionP
               EDirection aAction,
               EditAggregateTransaction* aTransaction,
               nsINode** aNode,
               int32_t* aOffset,
               int32_t* aLength)
 {
   MOZ_ASSERT(aAction != eNone);
 
-  nsresult res;
-
   // get the node and offset of the insertion point
   nsCOMPtr<nsINode> node = aRange->GetStartParent();
   NS_ENSURE_STATE(node);
 
   int32_t offset = aRange->StartOffset();
 
   // determine if the insertion point is at the beginning, middle, or end of
   // the node
@@ -4410,18 +4406,19 @@ EditorBase::CreateTxnForDeleteInsertionP
       NS_ENSURE_STATE(transaction);
 
       *aOffset = transaction->GetOffset();
       *aLength = transaction->GetNumCharsToDelete();
       aTransaction->AppendChild(transaction);
     } else {
       // priorNode is not chardata, so tell its parent to delete it
       RefPtr<DeleteNodeTransaction> transaction;
-      res = CreateTxnForDeleteNode(priorNode, getter_AddRefs(transaction));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        CreateTxnForDeleteNode(priorNode, getter_AddRefs(transaction));
+      NS_ENSURE_SUCCESS(rv, rv);
 
       aTransaction->AppendChild(transaction);
     }
 
     NS_ADDREF(*aNode = priorNode);
 
     return NS_OK;
   }
@@ -4445,18 +4442,19 @@ EditorBase::CreateTxnForDeleteInsertionP
       NS_ENSURE_STATE(transaction);
 
       *aOffset = transaction->GetOffset();
       *aLength = transaction->GetNumCharsToDelete();
       aTransaction->AppendChild(transaction);
     } else {
       // nextNode is not chardata, so tell its parent to delete it
       RefPtr<DeleteNodeTransaction> transaction;
-      res = CreateTxnForDeleteNode(nextNode, getter_AddRefs(transaction));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        CreateTxnForDeleteNode(nextNode, getter_AddRefs(transaction));
+      NS_ENSURE_SUCCESS(rv, rv);
       aTransaction->AppendChild(transaction);
     }
 
     NS_ADDREF(*aNode = nextNode);
 
     return NS_OK;
   }
 
@@ -4507,19 +4505,20 @@ EditorBase::CreateTxnForDeleteInsertionP
                                     aAction);
       NS_ENSURE_TRUE(deleteTextTransaction, NS_ERROR_NULL_POINTER);
 
       aTransaction->AppendChild(deleteTextTransaction);
       *aOffset = deleteTextTransaction->GetOffset();
       *aLength = deleteTextTransaction->GetNumCharsToDelete();
     } else {
       RefPtr<DeleteNodeTransaction> deleteNodeTransaction;
-      res = CreateTxnForDeleteNode(selectedNode,
-                                   getter_AddRefs(deleteNodeTransaction));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        CreateTxnForDeleteNode(selectedNode,
+                               getter_AddRefs(deleteNodeTransaction));
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_TRUE(deleteNodeTransaction, NS_ERROR_NULL_POINTER);
 
       aTransaction->AppendChild(deleteNodeTransaction);
     }
 
     NS_ADDREF(*aNode = selectedNode);
   }
 
@@ -4540,25 +4539,26 @@ EditorBase::CreateRange(nsIDOMNode* aSta
 nsresult
 EditorBase::AppendNodeToSelectionAsRange(nsIDOMNode* aNode)
 {
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMNode> parentNode;
-  nsresult res = aNode->GetParentNode(getter_AddRefs(parentNode));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = aNode->GetParentNode(getter_AddRefs(parentNode));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(parentNode, NS_ERROR_NULL_POINTER);
 
   int32_t offset = GetChildOffset(aNode, parentNode);
 
   RefPtr<nsRange> range;
-  res = CreateRange(parentNode, offset, parentNode, offset+1, getter_AddRefs(range));
-  NS_ENSURE_SUCCESS(res, res);
+  rv = CreateRange(parentNode, offset, parentNode, offset + 1,
+                   getter_AddRefs(range));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
 
   return selection->AddRange(range);
 }
 
 nsresult
 EditorBase::ClearSelection()
 {
--- a/editor/libeditor/EditorUtils.cpp
+++ b/editor/libeditor/EditorUtils.cpp
@@ -74,18 +74,18 @@ AutoSelectionRestorer::Abort()
 /******************************************************************************
  * some helper classes for iterating the dom tree
  *****************************************************************************/
 
 DOMIterator::DOMIterator(nsINode& aNode MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
 {
   MOZ_GUARD_OBJECT_NOTIFIER_INIT;
   mIter = NS_NewContentIterator();
-  DebugOnly<nsresult> res = mIter->Init(&aNode);
-  MOZ_ASSERT(NS_SUCCEEDED(res));
+  DebugOnly<nsresult> rv = mIter->Init(&aNode);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
 }
 
 nsresult
 DOMIterator::Init(nsRange& aRange)
 {
   mIter = NS_NewContentIterator();
   return mIter->Init(&aRange);
 }
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -66,35 +66,36 @@ HTMLEditor::AbsolutePositionSelection(bo
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(aEnabled ? EditAction::setAbsolutePosition :
                                     EditAction::removeAbsolutePosition);
   bool cancel, handled;
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
-  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (NS_FAILED(res) || cancel)
-    return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (NS_FAILED(rv) || cancel) {
+    return rv;
+  }
 
-  return rules->DidDoAction(selection, &ruleInfo, res);
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement** _retval)
 {
   nsAutoString positionStr;
   nsCOMPtr<nsINode> node = GetSelectionContainer();
   nsCOMPtr<nsIDOMNode> resultNode;
 
   while (!resultNode && node && !node->IsHTMLElement(nsGkAtoms::html)) {
-    nsresult res =
+    nsresult rv =
       mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::position,
                                          positionStr);
-    NS_ENSURE_SUCCESS(res, res);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (positionStr.EqualsLiteral("absolute"))
       resultNode = GetAsDOMNode(node);
     else {
       node = node->GetParentNode();
     }
   }
 
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(resultNode);
@@ -130,18 +131,18 @@ HTMLEditor::RelativeChangeElementZIndex(
                                           int32_t* aReturn)
 {
   NS_ENSURE_ARG_POINTER(aElement);
   NS_ENSURE_ARG_POINTER(aReturn);
   if (!aChange) // early way out, no change
     return NS_OK;
 
   int32_t zIndex;
-  nsresult res = GetElementZIndex(aElement, &zIndex);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetElementZIndex(aElement, &zIndex);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   zIndex = std::max(zIndex + aChange, 0);
   SetElementZIndex(aElement, zIndex);
   *aReturn = zIndex;
 
   return NS_OK;
 }
 
@@ -172,55 +173,56 @@ HTMLEditor::RelativeChangeZIndex(int32_t
   // Find out if the selection is collapsed:
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(aChange < 0 ? EditAction::decreaseZIndex :
                                        EditAction::increaseZIndex);
   bool cancel, handled;
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
-  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || NS_FAILED(res))
-    return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
-  return rules->DidDoAction(selection, &ruleInfo, res);
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetElementZIndex(nsIDOMElement* aElement,
                              int32_t* aZindex)
 {
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_STATE(element || !aElement);
   nsAutoString zIndexStr;
   *aZindex = 0;
 
-  nsresult res = mCSSEditUtils->GetSpecifiedProperty(*element,
-                                                     *nsGkAtoms::z_index,
-                                                     zIndexStr);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mCSSEditUtils->GetSpecifiedProperty(*element, *nsGkAtoms::z_index,
+                                        zIndexStr);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (zIndexStr.EqualsLiteral("auto")) {
     // we have to look at the positioned ancestors
     // cf. CSS 2 spec section 9.9.1
     nsCOMPtr<nsIDOMNode> parentNode;
-    res = aElement->GetParentNode(getter_AddRefs(parentNode));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = aElement->GetParentNode(getter_AddRefs(parentNode));
+    NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<nsINode> node = do_QueryInterface(parentNode);
     nsAutoString positionStr;
     while (node && zIndexStr.EqualsLiteral("auto") &&
            !node->IsHTMLElement(nsGkAtoms::body)) {
-      res = mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::position,
-                                               positionStr);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::position,
+                                              positionStr);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (positionStr.EqualsLiteral("absolute")) {
         // ah, we found one, what's its z-index ? If its z-index is auto,
         // we have to continue climbing the document's tree
-        res = mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::z_index,
-                                                 zIndexStr);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::z_index,
+                                                zIndexStr);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       node = node->GetParentNode();
     }
   }
 
   if (!zIndexStr.EqualsLiteral("auto")) {
     nsresult errorCode;
     *aZindex = zIndexStr.ToInteger(&errorCode);
@@ -249,41 +251,42 @@ HTMLEditor::CreateGrabber(nsINode* aPare
   return ret.forget();
 }
 
 NS_IMETHODIMP
 HTMLEditor::RefreshGrabber()
 {
   NS_ENSURE_TRUE(mAbsolutelyPositionedObject, NS_ERROR_NULL_POINTER);
 
-  nsresult res = GetPositionAndDimensions(static_cast<nsIDOMElement*>(GetAsDOMNode(mAbsolutelyPositionedObject)),
-                                         mPositionedObjectX,
-                                         mPositionedObjectY,
-                                         mPositionedObjectWidth,
-                                         mPositionedObjectHeight,
-                                         mPositionedObjectBorderLeft,
-                                         mPositionedObjectBorderTop,
-                                         mPositionedObjectMarginLeft,
-                                         mPositionedObjectMarginTop);
-
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    GetPositionAndDimensions(
+      static_cast<nsIDOMElement*>(GetAsDOMNode(mAbsolutelyPositionedObject)),
+      mPositionedObjectX,
+      mPositionedObjectY,
+      mPositionedObjectWidth,
+      mPositionedObjectHeight,
+      mPositionedObjectBorderLeft,
+      mPositionedObjectBorderTop,
+      mPositionedObjectMarginLeft,
+      mPositionedObjectMarginTop);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   SetAnonymousElementPosition(mPositionedObjectX+12,
                               mPositionedObjectY-14,
                               static_cast<nsIDOMElement*>(GetAsDOMNode(mGrabber)));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::HideGrabber()
 {
-  nsresult res = mAbsolutelyPositionedObject->UnsetAttr(kNameSpaceID_None,
-                                                        nsGkAtoms::_moz_abspos,
-                                                        true);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mAbsolutelyPositionedObject->UnsetAttr(kNameSpaceID_None,
+                                                       nsGkAtoms::_moz_abspos,
+                                                       true);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   mAbsolutelyPositionedObject = nullptr;
   NS_ENSURE_TRUE(mGrabber, NS_ERROR_NULL_POINTER);
 
   // get the presshell's document observer interface.
   nsCOMPtr<nsIPresShell> ps = GetPresShell();
   // We allow the pres shell to be null; when it is, we presume there
   // are no document observers to notify, but we still want to
@@ -307,22 +310,22 @@ HTMLEditor::ShowGrabberOnElement(nsIDOME
   NS_ENSURE_ARG_POINTER(element);
 
   if (mGrabber) {
     NS_ERROR("call HideGrabber first");
     return NS_ERROR_UNEXPECTED;
   }
 
   nsAutoString classValue;
-  nsresult res = CheckPositionedElementBGandFG(aElement, classValue);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = CheckPositionedElementBGandFG(aElement, classValue);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  res = element->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_abspos,
-                         classValue, true);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = element->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_abspos,
+                        classValue, true);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // first, let's keep track of that element...
   mAbsolutelyPositionedObject = element;
 
   mGrabber = CreateGrabber(element->GetParentNode());
   NS_ENSURE_TRUE(mGrabber, NS_ERROR_FAILURE);
 
   // and set its position
@@ -333,63 +336,63 @@ nsresult
 HTMLEditor::StartMoving(nsIDOMElement* aHandle)
 {
   nsCOMPtr<nsINode> parentNode = mGrabber->GetParentNode();
 
   // now, let's create the resizing shadow
   mPositioningShadow = CreateShadow(GetAsDOMNode(parentNode),
       static_cast<nsIDOMElement*>(GetAsDOMNode(mAbsolutelyPositionedObject)));
   NS_ENSURE_TRUE(mPositioningShadow, NS_ERROR_FAILURE);
-  nsresult res = SetShadowPosition(mPositioningShadow,
-                                   mAbsolutelyPositionedObject,
-                                   mPositionedObjectX, mPositionedObjectY);
-  NS_ENSURE_SUCCESS(res,res);
+  nsresult rv = SetShadowPosition(mPositioningShadow,
+                                  mAbsolutelyPositionedObject,
+                                  mPositionedObjectX, mPositionedObjectY);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // make the shadow appear
   mPositioningShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
 
   // position it
   mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::width,
                                       mPositionedObjectWidth);
   mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::height,
                                       mPositionedObjectHeight);
 
   mIsMoving = true;
-  return res;
+  return NS_OK; // XXX Looks like nobody refers this result
 }
 
 void
 HTMLEditor::SnapToGrid(int32_t& newX, int32_t& newY)
 {
   if (mSnapToGridEnabled && mGridSize) {
     newX = (int32_t) floor( ((float)newX / (float)mGridSize) + 0.5f ) * mGridSize;
     newY = (int32_t) floor( ((float)newY / (float)mGridSize) + 0.5f ) * mGridSize;
   }
 }
 
 nsresult
 HTMLEditor::GrabberClicked()
 {
   // add a mouse move listener to the editor
-  nsresult res = NS_OK;
+  nsresult rv = NS_OK;
   if (!mMouseMotionListenerP) {
     mMouseMotionListenerP = new ResizerMouseMotionListener(this);
     if (!mMouseMotionListenerP) {return NS_ERROR_NULL_POINTER;}
 
     nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
     NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
 
-    res = piTarget->AddEventListener(NS_LITERAL_STRING("mousemove"),
+    rv = piTarget->AddEventListener(NS_LITERAL_STRING("mousemove"),
                                      mMouseMotionListenerP,
                                      false, false);
-    NS_ASSERTION(NS_SUCCEEDED(res),
+    NS_ASSERTION(NS_SUCCEEDED(rv),
                  "failed to register mouse motion listener");
   }
   mGrabberClicked = true;
-  return res;
+  return rv;
 }
 
 nsresult
 HTMLEditor::EndMoving()
 {
   if (mPositioningShadow) {
     nsCOMPtr<nsIPresShell> ps = GetPresShell();
     NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
@@ -400,40 +403,38 @@ HTMLEditor::EndMoving()
     DeleteRefToAnonymousNode(static_cast<nsIDOMElement*>(GetAsDOMNode(mPositioningShadow)),
                              parentContent, ps);
 
     mPositioningShadow = nullptr;
   }
   nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
 
   if (piTarget && mMouseMotionListenerP) {
-#ifdef DEBUG
-    nsresult res =
-#endif
-    piTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
-                                  mMouseMotionListenerP,
-                                  false);
-    NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove mouse motion listener");
+    DebugOnly<nsresult> rv =
+      piTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
+                                    mMouseMotionListenerP,
+                                    false);
+    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener");
   }
   mMouseMotionListenerP = nullptr;
 
   mGrabberClicked = false;
   mIsMoving = false;
   RefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return NS_ERROR_NOT_INITIALIZED;
   }
   return CheckSelectionStateForAnonymousButtons(selection);
 }
 nsresult
 HTMLEditor::SetFinalPosition(int32_t aX,
                              int32_t aY)
 {
-  nsresult res = EndMoving();
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = EndMoving();
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // we have now to set the new width and height of the resized object
   // we don't set the x and y position because we don't control that in
   // a normal HTML layout
   int32_t newX = mPositionedObjectX + aX - mOriginalX - (mPositionedObjectBorderLeft+mPositionedObjectMarginLeft);
   int32_t newY = mPositionedObjectY + aY - mOriginalY - (mPositionedObjectBorderTop+mPositionedObjectMarginTop);
 
   SnapToGrid(newX, newY);
@@ -503,18 +504,18 @@ HTMLEditor::AbsolutelyPositionElement(ns
     // we may need to create a br if the positioned element is alone in its
     // container
     nsCOMPtr<nsINode> element = do_QueryInterface(aElement);
     NS_ENSURE_STATE(element);
 
     nsINode* parentNode = element->GetParentNode();
     if (parentNode->GetChildCount() == 1) {
       nsCOMPtr<nsIDOMNode> brNode;
-      nsresult res = CreateBR(parentNode->AsDOMNode(), 0, address_of(brNode));
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = CreateBR(parentNode->AsDOMNode(), 0, address_of(brNode));
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   else {
     mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::position,
                                      EmptyString());
     mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::top,
                                      EmptyString());
     mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::left,
@@ -530,20 +531,20 @@ HTMLEditor::AbsolutelyPositionElement(ns
     }
 
     nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
     if (element && element->IsHTMLElement(nsGkAtoms::div) &&
         !HasStyleOrIdOrClass(element)) {
       RefPtr<HTMLEditRules> htmlRules =
         static_cast<HTMLEditRules*>(mRules.get());
       NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
-      nsresult res = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement);
-      NS_ENSURE_SUCCESS(res, res);
-      res = RemoveContainer(element);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = RemoveContainer(element);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetSnapToGridEnabled(bool aEnabled)
 {
@@ -620,26 +621,26 @@ HTMLEditor::CheckPositionedElementBGandF
   //       the foreground is below #d0, use a white background
   // Otherwise don't change background/foreground
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_STATE(element || !aElement);
 
   aReturn.Truncate();
 
   nsAutoString bgImageStr;
-  nsresult res =
+  nsresult rv =
     mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::background_image,
                                        bgImageStr);
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (bgImageStr.EqualsLiteral("none")) {
     nsAutoString bgColorStr;
-    res =
+    rv =
       mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::backgroundColor,
                                          bgColorStr);
-    NS_ENSURE_SUCCESS(res, res);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (bgColorStr.EqualsLiteral("transparent")) {
       RefPtr<nsComputedDOMStyle> cssDecl =
         mCSSEditUtils->GetComputedStyle(element);
       NS_ENSURE_STATE(cssDecl);
 
       // from these declarations, get the one we want and that one only
       ErrorResult error;
       RefPtr<dom::CSSValue> cssVal = cssDecl->GetPropertyCSSValue(NS_LITERAL_STRING("color"), error);
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -53,37 +53,39 @@ using namespace dom;
 // retrieve an integer stored into a CSS computed float value
 static int32_t GetCSSFloatValue(nsIDOMCSSStyleDeclaration * aDecl,
                                 const nsAString & aProperty)
 {
   MOZ_ASSERT(aDecl);
 
   nsCOMPtr<nsIDOMCSSValue> value;
   // get the computed CSSValue of the property
-  nsresult res = aDecl->GetPropertyCSSValue(aProperty, getter_AddRefs(value));
-  if (NS_FAILED(res) || !value) return 0;
+  nsresult rv = aDecl->GetPropertyCSSValue(aProperty, getter_AddRefs(value));
+  if (NS_FAILED(rv) || !value) {
+    return 0;
+  }
 
   // check the type of the returned CSSValue; we handle here only
   // pixel and enum types
   nsCOMPtr<nsIDOMCSSPrimitiveValue> val = do_QueryInterface(value);
   uint16_t type;
   val->GetPrimitiveType(&type);
 
   float f = 0;
   switch (type) {
     case nsIDOMCSSPrimitiveValue::CSS_PX:
       // the value is in pixels, just get it
-      res = val->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_PX, &f);
-      NS_ENSURE_SUCCESS(res, 0);
+      rv = val->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_PX, &f);
+      NS_ENSURE_SUCCESS(rv, 0);
       break;
     case nsIDOMCSSPrimitiveValue::CSS_IDENT: {
       // the value is keyword, we have to map these keywords into
       // numeric values
       nsAutoString str;
-      res = val->GetStringValue(str);
+      val->GetStringValue(str);
       if (str.EqualsLiteral("thin"))
         f = 1;
       else if (str.EqualsLiteral("medium"))
         f = 3;
       else if (str.EqualsLiteral("thick"))
         f = 5;
       break;
     }
@@ -187,39 +189,39 @@ HTMLEditor::CreateAnonymousElement(const
   nsCOMPtr<nsIAtom> tagAtom = NS_Atomize(aTag);
   nsCOMPtr<Element> newContent = CreateHTMLContent(tagAtom);
   NS_ENSURE_STATE(newContent);
 
   nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newContent);
   NS_ENSURE_TRUE(newElement, NS_ERROR_FAILURE);
 
   // add the "hidden" class if needed
-  nsresult res;
   if (aIsCreatedHidden) {
-    res = newElement->SetAttribute(NS_LITERAL_STRING("class"),
-                                   NS_LITERAL_STRING("hidden"));
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = newElement->SetAttribute(NS_LITERAL_STRING("class"),
+                                           NS_LITERAL_STRING("hidden"));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // add an _moz_anonclass attribute if needed
   if (!aAnonClass.IsEmpty()) {
-    res = newElement->SetAttribute(NS_LITERAL_STRING("_moz_anonclass"),
-                                   aAnonClass);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = newElement->SetAttribute(NS_LITERAL_STRING("_moz_anonclass"),
+                                           aAnonClass);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   {
     nsAutoScriptBlocker scriptBlocker;
 
     // establish parenthood of the element
     newContent->SetIsNativeAnonymousRoot();
-    res = newContent->BindToTree(doc, parentContent, parentContent, true);
-    if (NS_FAILED(res)) {
+    nsresult rv =
+      newContent->BindToTree(doc, parentContent, parentContent, true);
+    if (NS_FAILED(rv)) {
       newContent->UnbindFromTree();
-      return res;
+      return rv;
     }
   }
 
   ElementDeletionObserver* observer =
     new ElementDeletionObserver(newContent, parentContent);
   NS_ADDREF(observer); // NodeWillBeDestroyed releases.
   parentContent->AddMutationObserver(observer);
   newContent->AddMutationObserver(observer);
@@ -314,50 +316,51 @@ HTMLEditor::CheckSelectionStateForAnonym
 
   // Don't change selection state if we're moving.
   if (mIsMoving) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMElement> focusElement;
   // let's get the containing element of the selection
-  nsresult res  = GetSelectionContainer(getter_AddRefs(focusElement));
+  nsresult rv = GetSelectionContainer(getter_AddRefs(focusElement));
   NS_ENSURE_TRUE(focusElement, NS_OK);
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // If we're not in a document, don't try to add resizers
   nsCOMPtr<dom::Element> focusElementNode = do_QueryInterface(focusElement);
   NS_ENSURE_STATE(focusElementNode);
   if (!focusElementNode->IsInUncomposedDoc()) {
     return NS_OK;
   }
 
   // what's its tag?
   nsAutoString focusTagName;
-  res = focusElement->GetTagName(focusTagName);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = focusElement->GetTagName(focusTagName);
+  NS_ENSURE_SUCCESS(rv, rv);
   ToLowerCase(focusTagName);
   nsCOMPtr<nsIAtom> focusTagAtom = NS_Atomize(focusTagName);
 
   nsCOMPtr<nsIDOMElement> absPosElement;
   if (mIsAbsolutelyPositioningEnabled) {
     // Absolute Positioning support is enabled, is the selection contained
     // in an absolutely positioned element ?
-    res = GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(absPosElement));
-    NS_ENSURE_SUCCESS(res, res);
+    rv =
+      GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(absPosElement));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMPtr<nsIDOMElement> cellElement;
   if (mIsObjectResizingEnabled || mIsInlineTableEditingEnabled) {
     // Resizing or Inline Table Editing is enabled, we need to check if the
     // selection is contained in a table cell
-    res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"),
-                                      nullptr,
-                                      getter_AddRefs(cellElement));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetElementOrParentByTagName(NS_LITERAL_STRING("td"),
+                                     nullptr,
+                                     getter_AddRefs(cellElement));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (mIsObjectResizingEnabled && cellElement) {
     // we are here because Resizing is enabled AND selection is contained in
     // a cell
 
     // get the enclosing table
     if (nsGkAtoms::img != focusTagAtom) {
@@ -380,69 +383,88 @@ HTMLEditor::CheckSelectionStateForAnonym
   //                absPosElement contains the element for Positioning
 
   // Note: All the Hide/Show methods below may change attributes on real
   // content which means a DOMAttrModified handler may cause arbitrary
   // side effects while this code runs (bug 420439).
 
   if (mIsAbsolutelyPositioningEnabled && mAbsolutelyPositionedObject &&
       absPosElement != GetAsDOMNode(mAbsolutelyPositionedObject)) {
-    res = HideGrabber();
-    NS_ENSURE_SUCCESS(res, res);
+    rv = HideGrabber();
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ASSERTION(!mAbsolutelyPositionedObject, "HideGrabber failed");
   }
 
   if (mIsObjectResizingEnabled && mResizedObject &&
       GetAsDOMNode(mResizedObject) != focusElement) {
-    res = HideResizers();
-    NS_ENSURE_SUCCESS(res, res);
+    rv = HideResizers();
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ASSERTION(!mResizedObject, "HideResizers failed");
   }
 
   if (mIsInlineTableEditingEnabled && mInlineEditedCell &&
       mInlineEditedCell != cellElement) {
-    res = HideInlineTableEditingUI();
-    NS_ENSURE_SUCCESS(res, res);
+    rv = HideInlineTableEditingUI();
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ASSERTION(!mInlineEditedCell, "HideInlineTableEditingUI failed");
   }
 
   // now, let's display all contextual UI for good
   nsIContent* hostContent = GetActiveEditingHost();
   nsCOMPtr<nsIDOMNode> hostNode = do_QueryInterface(hostContent);
 
   if (mIsObjectResizingEnabled && focusElement &&
       IsModifiableNode(focusElement) && focusElement != hostNode) {
     if (nsGkAtoms::img == focusTagAtom) {
       mResizedObjectIsAnImage = true;
     }
-    if (mResizedObject)
-      res = RefreshResizers();
-    else
-      res = ShowResizers(focusElement);
-    NS_ENSURE_SUCCESS(res, res);
+    if (mResizedObject) {
+      nsresult rv = RefreshResizers();
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    } else {
+      nsresult rv = ShowResizers(focusElement);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
   }
 
   if (mIsAbsolutelyPositioningEnabled && absPosElement &&
       IsModifiableNode(absPosElement) && absPosElement != hostNode) {
-    if (mAbsolutelyPositionedObject)
-      res = RefreshGrabber();
-    else
-      res = ShowGrabberOnElement(absPosElement);
-    NS_ENSURE_SUCCESS(res, res);
+    if (mAbsolutelyPositionedObject) {
+      nsresult rv = RefreshGrabber();
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    } else {
+      nsresult rv = ShowGrabberOnElement(absPosElement);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
   }
 
   if (mIsInlineTableEditingEnabled && cellElement &&
       IsModifiableNode(cellElement) && cellElement != hostNode) {
-    if (mInlineEditedCell)
-      res = RefreshInlineTableEditingUI();
-    else
-      res = ShowInlineTableEditingUI(cellElement);
+    if (mInlineEditedCell) {
+      nsresult rv = RefreshInlineTableEditingUI();
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    } else {
+      nsresult rv = ShowInlineTableEditingUI(cellElement);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
   }
 
-  return res;
+  return NS_OK;
 }
 
 // Resizing and Absolute Positioning need to know everything about the
 // containing box of the element: position, size, margins, borders
 nsresult
 HTMLEditor::GetPositionAndDimensions(nsIDOMElement* aElement,
                                      int32_t& aX,
                                      int32_t& aY,
@@ -453,18 +475,19 @@ HTMLEditor::GetPositionAndDimensions(nsI
                                      int32_t& aMarginLeft,
                                      int32_t& aMarginTop)
 {
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_ARG_POINTER(element);
 
   // Is the element positioned ? let's check the cheap way first...
   bool isPositioned = false;
-  nsresult res = aElement->HasAttribute(NS_LITERAL_STRING("_moz_abspos"), &isPositioned);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    aElement->HasAttribute(NS_LITERAL_STRING("_moz_abspos"), &isPositioned);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!isPositioned) {
     // hmmm... the expensive way now...
     nsAutoString positionStr;
     mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::position,
                                        positionStr);
     isPositioned = positionStr.EqualsLiteral("absolute");
   }
 
@@ -492,26 +515,27 @@ HTMLEditor::GetPositionAndDimensions(nsI
   else {
     mResizedObjectIsAbsolutelyPositioned = false;
     nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(aElement);
     if (!htmlElement) {
       return NS_ERROR_NULL_POINTER;
     }
     GetElementOrigin(aElement, aX, aY);
 
-    res = htmlElement->GetOffsetWidth(&aW);
-    NS_ENSURE_SUCCESS(res, res);
-    res = htmlElement->GetOffsetHeight(&aH);
+    if (NS_WARN_IF(NS_FAILED(htmlElement->GetOffsetWidth(&aW))) ||
+        NS_WARN_IF(NS_FAILED(htmlElement->GetOffsetHeight(&aH)))) {
+      return rv;
+    }
 
     aBorderLeft = 0;
     aBorderTop  = 0;
     aMarginLeft = 0;
     aMarginTop = 0;
   }
-  return res;
+  return NS_OK;
 }
 
 // self-explanatory
 void
 HTMLEditor::SetAnonymousElementPosition(int32_t aX,
                                         int32_t aY,
                                         nsIDOMElement* aElement)
 {
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -136,18 +136,19 @@ public:
   {}
 
   virtual bool operator()(nsINode* aNode) const
   {
     if (mHTMLEditor->IsEditable(aNode) &&
         (HTMLEditUtils::IsListItem(aNode) ||
          HTMLEditUtils::IsTableCellOrCaption(*aNode))) {
       bool bIsEmptyNode;
-      nsresult res = mHTMLEditor->IsEmptyNode(aNode, &bIsEmptyNode, false, false);
-      NS_ENSURE_SUCCESS(res, false);
+      nsresult rv =
+        mHTMLEditor->IsEmptyNode(aNode, &bIsEmptyNode, false, false);
+      NS_ENSURE_SUCCESS(rv, false);
       if (bIsEmptyNode)
         return true;
     }
     return false;
   }
 
 protected:
   HTMLEditor* mHTMLEditor;
@@ -227,21 +228,20 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLE
                                    mRangeItem)
 
 NS_IMETHODIMP
 HTMLEditRules::Init(TextEditor* aTextEditor)
 {
   InitFields();
 
   mHTMLEditor = static_cast<HTMLEditor*>(aTextEditor);
-  nsresult res;
 
   // call through to base class Init
-  res = TextEditRules::Init(aTextEditor);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = TextEditRules::Init(aTextEditor);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // cache any prefs we care about
   static const char kPrefName[] =
     "editor.html.typing.returnInEmptyListItemClosesList";
   nsAdoptingCString returnInEmptyLIKillsList =
     Preferences::GetCString(kPrefName);
 
   // only when "false", becomes FALSE.  Otherwise (including empty), TRUE.
@@ -268,19 +268,17 @@ HTMLEditRules::Init(TextEditor* aTextEdi
   if (node->IsElement()) {
     ErrorResult rv;
     mDocChangeRange->SelectNode(*node, rv);
     NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
     AdjustSpecialBreaks();
   }
 
   // add ourselves as a listener to edit actions
-  res = mHTMLEditor->AddEditActionListener(this);
-
-  return res;
+  return mHTMLEditor->AddEditActionListener(this);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::DetachEditor()
 {
   if (mHTMLEditor) {
     mHTMLEditor->RemoveEditActionListener(this);
   }
@@ -431,17 +429,16 @@ HTMLEditRules::AfterEditInner(EditAction
     mDocChangeRange->GetStartContainer(getter_AddRefs(rangeStartParent));
     mDocChangeRange->GetEndContainer(getter_AddRefs(rangeEndParent));
     mDocChangeRange->GetStartOffset(&rangeStartOffset);
     mDocChangeRange->GetEndOffset(&rangeEndOffset);
     if (rangeStartParent && rangeEndParent)
       bDamagedRange = true;
   }
 
-  nsresult res;
   if (bDamagedRange && !((action == EditAction::undo) || (action == EditAction::redo)))
   {
     // don't let any txns in here move the selection around behind our back.
     // Note that this won't prevent explicit selection setting from working.
     NS_ENSURE_STATE(mHTMLEditor);
     AutoTransactionsConserveSelection dontSpazMySelection(mHTMLEditor);
 
     // expand the "changed doc range" as needed
@@ -449,46 +446,46 @@ HTMLEditRules::AfterEditInner(EditAction
 
     // if we did a ranged deletion or handling backspace key, make sure we have
     // a place to put caret.
     // Note we only want to do this if the overall operation was deletion,
     // not if deletion was done along the way for EditAction::loadHTML, EditAction::insertText, etc.
     // That's why this is here rather than DidDeleteSelection().
     if ((action == EditAction::deleteSelection) && mDidRangedDelete)
     {
-      res = InsertBRIfNeeded(selection);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = InsertBRIfNeeded(selection);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // add in any needed <br>s, and remove any unneeded ones.
     AdjustSpecialBreaks();
 
     // merge any adjacent text nodes
     if ( (action != EditAction::insertText &&
          action != EditAction::insertIMEText) )
     {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->CollapseAdjacentTextNodes(mDocChangeRange);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = mHTMLEditor->CollapseAdjacentTextNodes(mDocChangeRange);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // clean up any empty nodes in the selection
-    res = RemoveEmptyNodes();
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = RemoveEmptyNodes();
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // attempt to transform any unneeded nbsp's into spaces after doing various operations
     if ((action == EditAction::insertText) ||
         (action == EditAction::insertIMEText) ||
         (action == EditAction::deleteSelection) ||
         (action == EditAction::insertBreak) ||
         (action == EditAction::htmlPaste ||
         (action == EditAction::loadHTML)))
     {
-      res = AdjustWhitespace(selection);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = AdjustWhitespace(selection);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       // also do this for original selection endpoints.
       NS_ENSURE_STATE(mHTMLEditor);
       NS_ENSURE_STATE(mRangeItem->startNode);
       NS_ENSURE_STATE(mRangeItem->endNode);
       WSRunObject(mHTMLEditor, mRangeItem->startNode,
                   mRangeItem->startOffset).AdjustWhitespace();
       // we only need to handle old selection endpoint if it was different from start
@@ -498,60 +495,60 @@ HTMLEditRules::AfterEditInner(EditAction
         WSRunObject(mHTMLEditor, mRangeItem->endNode,
                     mRangeItem->endOffset).AdjustWhitespace();
       }
     }
 
     // if we created a new block, make sure selection lands in it
     if (mNewBlock)
     {
-      res = PinSelectionToNewBlock(selection);
+      rv = PinSelectionToNewBlock(selection);
       mNewBlock = 0;
     }
 
     // adjust selection for insert text, html paste, and delete actions
     if ((action == EditAction::insertText) ||
         (action == EditAction::insertIMEText) ||
         (action == EditAction::deleteSelection) ||
         (action == EditAction::insertBreak) ||
         (action == EditAction::htmlPaste ||
         (action == EditAction::loadHTML)))
     {
-      res = AdjustSelection(selection, aDirection);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = AdjustSelection(selection, aDirection);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // check for any styles which were removed inappropriately
     if (action == EditAction::insertText ||
         action == EditAction::insertIMEText ||
         action == EditAction::deleteSelection ||
         IsStyleCachePreservingAction(action)) {
       NS_ENSURE_STATE(mHTMLEditor);
       mHTMLEditor->mTypeInState->UpdateSelState(selection);
-      res = ReapplyCachedStyles();
-      NS_ENSURE_SUCCESS(res, res);
+      rv = ReapplyCachedStyles();
+      NS_ENSURE_SUCCESS(rv, rv);
       ClearCachedStyles();
     }
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
 
-  res = mHTMLEditor->HandleInlineSpellCheck(action, selection,
-                                            GetAsDOMNode(mRangeItem->startNode),
-                                            mRangeItem->startOffset,
-                                            rangeStartParent, rangeStartOffset,
-                                            rangeEndParent, rangeEndOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->HandleInlineSpellCheck(action, selection,
+                                        GetAsDOMNode(mRangeItem->startNode),
+                                        mRangeItem->startOffset,
+                                        rangeStartParent, rangeStartOffset,
+                                        rangeEndParent, rangeEndOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // detect empty doc
-  res = CreateBogusNodeIfNeeded(selection);
+  rv = CreateBogusNodeIfNeeded(selection);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // adjust selection HINT if needed
-  NS_ENSURE_SUCCESS(res, res);
-
   if (!mDidExplicitlySetInterline)
   {
     CheckInterlinePosition(*selection);
   }
 
   return NS_OK;
 }
 
@@ -693,19 +690,19 @@ HTMLEditRules::GetListState(bool* aMixed
   NS_ENSURE_TRUE(aMixed && aOL && aUL && aDL, NS_ERROR_NULL_POINTER);
   *aMixed = false;
   *aOL = false;
   *aUL = false;
   *aDL = false;
   bool bNonList = false;
 
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  nsresult res = GetListActionNodes(arrayOfNodes, EntireList::no,
-                                    TouchContent::no);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetListActionNodes(arrayOfNodes, EntireList::no,
+                                   TouchContent::no);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Examine list type for nodes in selection.
   for (const auto& curNode : arrayOfNodes) {
     if (!curNode->IsElement()) {
       bNonList = true;
     } else if (curNode->IsHTMLElement(nsGkAtoms::ul)) {
       *aUL = true;
     } else if (curNode->IsHTMLElement(nsGkAtoms::ol)) {
@@ -744,19 +741,19 @@ HTMLEditRules::GetListItemState(bool* aM
   NS_ENSURE_TRUE(aMixed && aLI && aDT && aDD, NS_ERROR_NULL_POINTER);
   *aMixed = false;
   *aLI = false;
   *aDT = false;
   *aDD = false;
   bool bNonList = false;
 
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  nsresult res = GetListActionNodes(arrayOfNodes, EntireList::no,
-                                    TouchContent::no);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetListActionNodes(arrayOfNodes, EntireList::no,
+                                   TouchContent::no);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // examine list type for nodes in selection
   for (const auto& node : arrayOfNodes) {
     if (!node->IsElement()) {
       bNonList = true;
     } else if (node->IsAnyOfHTMLElements(nsGkAtoms::ul,
                                          nsGkAtoms::ol,
                                          nsGkAtoms::li)) {
@@ -918,29 +915,32 @@ static nsIAtom& MarginPropertyAtomForInd
   return direction.EqualsLiteral("rtl") ?
     *nsGkAtoms::marginRight : *nsGkAtoms::marginLeft;
 }
 
 nsresult
 HTMLEditRules::GetIndentState(bool* aCanIndent,
                               bool* aCanOutdent)
 {
+  // XXX Looks like that this is implementation of
+  //     nsIHTMLEditor::getIndentState() however nobody calls this method
+  //     even with the interface method.
   NS_ENSURE_TRUE(aCanIndent && aCanOutdent, NS_ERROR_FAILURE);
   *aCanIndent = true;
   *aCanOutdent = false;
 
   // get selection
   NS_ENSURE_STATE(mHTMLEditor && mHTMLEditor->GetSelection());
   OwningNonNull<Selection> selection = *mHTMLEditor->GetSelection();
 
   // contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  nsresult res = GetNodesFromSelection(*selection, EditAction::indent,
-                                       arrayOfNodes, TouchContent::no);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetNodesFromSelection(*selection, EditAction::indent,
+                                      arrayOfNodes, TouchContent::no);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // examine nodes in selection for blockquotes or list elements;
   // these we can outdent.  Note that we return true for canOutdent
   // if *any* of the selection is outdentable, rather than all of it.
   NS_ENSURE_STATE(mHTMLEditor);
   bool useCSS = mHTMLEditor->IsCSSEnabled();
   for (auto& curNode : Reversed(arrayOfNodes)) {
     if (HTMLEditUtils::IsNodeThatCanOutdent(GetAsDOMNode(curNode))) {
@@ -982,43 +982,45 @@ HTMLEditRules::GetIndentState(bool* aCan
     NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER);
     int32_t selOffset;
     NS_ENSURE_STATE(mHTMLEditor);
     RefPtr<Selection> selection = mHTMLEditor->GetSelection();
     NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
     // test start parent hierarchy
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &selOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent),
+                                            &selOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
     while (parent && (parent!=root))
     {
       if (HTMLEditUtils::IsNodeThatCanOutdent(parent)) {
         *aCanOutdent = true;
         break;
       }
       tmp=parent;
       tmp->GetParentNode(getter_AddRefs(parent));
     }
 
     // test end parent hierarchy
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(parent), &selOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(parent),
+                                          &selOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
     while (parent && (parent!=root))
     {
       if (HTMLEditUtils::IsNodeThatCanOutdent(parent)) {
         *aCanOutdent = true;
         break;
       }
       tmp=parent;
       tmp->GetParentNode(getter_AddRefs(parent));
     }
   }
-  return res;
+  return NS_OK;
 }
 
 
 nsresult
 HTMLEditRules::GetParagraphState(bool* aMixed,
                                  nsAString& outFormat)
 {
   // This routine is *heavily* tied to our ui choices in the paragraph
@@ -1027,44 +1029,45 @@ HTMLEditRules::GetParagraphState(bool* a
   *aMixed = true;
   outFormat.Truncate(0);
 
   bool bMixed = false;
   // using "x" as an uninitialized value, since "" is meaningful
   nsAutoString formatStr(NS_LITERAL_STRING("x"));
 
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  nsresult res = GetParagraphFormatNodes(arrayOfNodes, TouchContent::no);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetParagraphFormatNodes(arrayOfNodes, TouchContent::no);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // post process list.  We need to replace any block nodes that are not format
   // nodes with their content.  This is so we only have to look "up" the hierarchy
   // to find format nodes, instead of both up and down.
   for (int32_t i = arrayOfNodes.Length() - 1; i >= 0; i--) {
     auto& curNode = arrayOfNodes[i];
     nsAutoString format;
     // if it is a known format node we have it easy
     if (IsBlockNode(curNode) && !HTMLEditUtils::IsFormatNode(curNode)) {
       // arrayOfNodes.RemoveObject(curNode);
-      res = AppendInnerFormatNodes(arrayOfNodes, curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = AppendInnerFormatNodes(arrayOfNodes, curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // we might have an empty node list.  if so, find selection parent
   // and put that on the list
   if (!arrayOfNodes.Length()) {
     nsCOMPtr<nsINode> selNode;
     int32_t selOffset;
     NS_ENSURE_STATE(mHTMLEditor);
     RefPtr<Selection> selection = mHTMLEditor->GetSelection();
     NS_ENSURE_STATE(selection);
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode),
+                                            &selOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(selNode, NS_ERROR_NULL_POINTER);
     arrayOfNodes.AppendElement(*selNode);
   }
 
   // remember root node
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<nsIDOMElement> rootElem = do_QueryInterface(mHTMLEditor->GetRoot());
   NS_ENSURE_TRUE(rootElem, NS_ERROR_NULL_POINTER);
@@ -1109,17 +1112,17 @@ HTMLEditRules::GetParagraphState(bool* a
     {
       bMixed = true;
       break;
     }
   }
 
   *aMixed = bMixed;
   outFormat = formatStr;
-  return res;
+  return NS_OK;
 }
 
 nsresult
 HTMLEditRules::AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
                                       nsINode* aNode)
 {
   MOZ_ASSERT(aNode);
 
@@ -1197,27 +1200,27 @@ HTMLEditRules::WillInsert(Selection& aSe
     nsCOMPtr<Element> block2 = htmlEditor->GetBlockNodeParent(priorNode);
 
     if (block1 && block1 == block2) {
       // If we are here then the selection is right after a mozBR that is in
       // the same block as the selection.  We need to move the selection start
       // to be before the mozBR.
       selNode = priorNode->GetParentNode();
       selOffset = selNode->IndexOf(priorNode);
-      nsresult res = aSelection.Collapse(selNode, selOffset);
-      NS_ENSURE_SUCCESS_VOID(res);
+      nsresult rv = aSelection.Collapse(selNode, selOffset);
+      NS_ENSURE_SUCCESS_VOID(rv);
     }
   }
 
   if (mDidDeleteSelection &&
       (mTheAction == EditAction::insertText ||
        mTheAction == EditAction::insertIMEText ||
        mTheAction == EditAction::deleteSelection)) {
-    nsresult res = ReapplyCachedStyles();
-    NS_ENSURE_SUCCESS_VOID(res);
+    nsresult rv = ReapplyCachedStyles();
+    NS_ENSURE_SUCCESS_VOID(rv);
   }
   // For most actions we want to clear the cached styles, but there are
   // exceptions
   if (!IsStyleCachePreservingAction(mTheAction)) {
     ClearCachedStyles();
   }
 }
 
@@ -1241,38 +1244,38 @@ HTMLEditRules::WillInsertText(EditAction
     *aCancel = true;
     *aHandled = false;
     return NS_OK;
   }
 
   // initialize out param
   *aCancel = false;
   *aHandled = true;
-  nsresult res;
   // If the selection isn't collapsed, delete it.  Don't delete existing inline
   // tags, because we're hopefully going to insert text (bug 787432).
   if (!aSelection->Collapsed()) {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eNoStrip);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mHTMLEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eNoStrip);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   WillInsert(*aSelection, aCancel);
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
 
   // we need to get the doc
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<nsIDocument> doc = mHTMLEditor->GetDocument();
   NS_ENSURE_STATE(doc);
 
   // for every property that is set, insert a new inline style node
-  res = CreateStyleForInsertText(*aSelection, *doc);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = CreateStyleForInsertText(*aSelection, *doc);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // get the (collapsed) selection location
   NS_ENSURE_STATE(mHTMLEditor);
   NS_ENSURE_STATE(aSelection->GetRangeAt(0));
   nsCOMPtr<nsINode> selNode = aSelection->GetRangeAt(0)->GetStartParent();
   int32_t selOffset = aSelection->GetRangeAt(0)->StartOffset();
   NS_ENSURE_STATE(selNode);
 
@@ -1292,38 +1295,43 @@ HTMLEditRules::WillInsertText(EditAction
     // the insertion point.
     int32_t IMESelectionOffset =
       mHTMLEditor->GetIMESelectionStartOffsetIn(selNode);
     if (IMESelectionOffset >= 0) {
       selOffset = IMESelectionOffset;
     }
     if (inString->IsEmpty())
     {
-      res = mHTMLEditor->InsertTextImpl(*inString, address_of(selNode),
-                                        &selOffset, doc);
+      rv = mHTMLEditor->InsertTextImpl(*inString, address_of(selNode),
+                                       &selOffset, doc);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
     else
     {
       WSRunObject wsObj(mHTMLEditor, selNode, selOffset);
-      res = wsObj.InsertText(*inString, address_of(selNode), &selOffset, doc);
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      rv = wsObj.InsertText(*inString, address_of(selNode), &selOffset, doc);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
   }
   else // aAction == kInsertText
   {
     // find where we are
     nsCOMPtr<nsINode> curNode = selNode;
     int32_t curOffset = selOffset;
 
     // is our text going to be PREformatted?
     // We remember this so that we know how to handle tabs.
     bool isPRE;
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->IsPreformatted(GetAsDOMNode(selNode), &isPRE);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->IsPreformatted(GetAsDOMNode(selNode), &isPRE);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // turn off the edit listener: we know how to
     // build the "doc changed range" ourselves, and it's
     // must faster to do it once here than to track all
     // the changes one at a time.
     AutoLockListener lockit(&mListenerEnabled);
 
     // don't spaz my selection in subtransactions
@@ -1368,19 +1376,19 @@ HTMLEditRules::WillInsertText(EditAction
             mHTMLEditor->CreateBRImpl(address_of(curNode), &curOffset,
                                       nsIEditor::eNone);
           NS_ENSURE_STATE(br);
           pos++;
         }
         else
         {
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->InsertTextImpl(subStr, address_of(curNode),
-                                            &curOffset, doc);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mHTMLEditor->InsertTextImpl(subStr, address_of(curNode),
+                                           &curOffset, doc);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
       }
     }
     else
     {
       NS_NAMED_LITERAL_STRING(tabStr, "\t");
       NS_NAMED_LITERAL_STRING(spacesStr, "    ");
       char specialChars[] = {TAB, nsCRT::LF, 0};
@@ -1405,55 +1413,61 @@ HTMLEditRules::WillInsertText(EditAction
 
         nsDependentSubstring subStr(tString, oldPos, subStrLen);
         NS_ENSURE_STATE(mHTMLEditor);
         WSRunObject wsObj(mHTMLEditor, curNode, curOffset);
 
         // is it a tab?
         if (subStr.Equals(tabStr))
         {
-          res =
+          rv =
             wsObj.InsertText(spacesStr, address_of(curNode), &curOffset, doc);
-          NS_ENSURE_SUCCESS(res, res);
+          NS_ENSURE_SUCCESS(rv, rv);
           pos++;
         }
         // is it a return?
         else if (subStr.Equals(newlineStr))
         {
           nsCOMPtr<Element> br = wsObj.InsertBreak(address_of(curNode),
                                                    &curOffset,
                                                    nsIEditor::eNone);
           NS_ENSURE_TRUE(br, NS_ERROR_FAILURE);
           pos++;
         }
         else
         {
-          res = wsObj.InsertText(subStr, address_of(curNode), &curOffset, doc);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = wsObj.InsertText(subStr, address_of(curNode), &curOffset, doc);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
-        NS_ENSURE_SUCCESS(res, res);
       }
     }
     aSelection->SetInterlinePosition(false);
     if (curNode) aSelection->Collapse(curNode, curOffset);
     // manually update the doc changed range so that AfterEdit will clean up
     // the correct portion of the document.
     if (!mDocChangeRange)
     {
       mDocChangeRange = new nsRange(selNode);
     }
-    res = mDocChangeRange->SetStart(selNode, selOffset);
-    NS_ENSURE_SUCCESS(res, res);
-    if (curNode)
-      res = mDocChangeRange->SetEnd(curNode, curOffset);
-    else
-      res = mDocChangeRange->SetEnd(selNode, selOffset);
-    NS_ENSURE_SUCCESS(res, res);
-  }
-  return res;
+    rv = mDocChangeRange->SetStart(selNode, selOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (curNode) {
+      rv = mDocChangeRange->SetEnd(curNode, curOffset);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    } else {
+      rv = mDocChangeRange->SetEnd(selNode, selOffset);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
+  }
+  return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillLoadHTML(Selection* aSelection,
                             bool* aCancel)
 {
   NS_ENSURE_TRUE(aSelection && aCancel, NS_ERROR_NULL_POINTER);
 
@@ -1479,32 +1493,32 @@ HTMLEditRules::WillInsertBreak(Selection
   MOZ_ASSERT(aCancel && aHandled);
   *aCancel = false;
   *aHandled = false;
 
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // If the selection isn't collapsed, delete it.
-  nsresult res;
   if (!aSelection.Collapsed()) {
-    res = htmlEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      htmlEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   WillInsert(aSelection, aCancel);
 
   // Initialize out param.  We want to ignore result of WillInsert().
   *aCancel = false;
 
   // Split any mailcites in the way.  Should we abort this if we encounter
   // table cell boundaries?
   if (IsMailEditor()) {
-    res = SplitMailCites(&aSelection, aHandled);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = SplitMailCites(&aSelection, aHandled);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (*aHandled) {
       return NS_OK;
     }
   }
 
   // Smart splitting rules
   NS_ENSURE_TRUE(aSelection.GetRangeAt(0) &&
                  aSelection.GetRangeAt(0)->GetStartParent(),
@@ -1521,18 +1535,18 @@ HTMLEditRules::WillInsertBreak(Selection
   // Identify the block
   nsCOMPtr<Element> blockParent = htmlEditor->GetBlock(node);
   NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
 
   // If the active editing host is an inline element, or if the active editing
   // host is the block parent itself, just append a br.
   nsCOMPtr<Element> host = htmlEditor->GetActiveEditingHost();
   if (!EditorUtils::IsDescendantOf(blockParent, host)) {
-    res = StandardBreakImpl(node, offset, aSelection);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = StandardBreakImpl(node, offset, aSelection);
+    NS_ENSURE_SUCCESS(rv, rv);
     *aHandled = true;
     return NS_OK;
   }
 
   // If block is empty, populate with br.  (For example, imagine a div that
   // contains the word "text".  The user selects "text" and types return.
   // "Text" is deleted leaving an empty block.  We want to put in one br to
   // make block have a line.  Then code further below will put in a second br.)
@@ -1551,19 +1565,20 @@ HTMLEditRules::WillInsertBreak(Selection
     return NS_OK;
   } else if (HTMLEditUtils::IsHeader(*blockParent)) {
     // Headers: close (or split) header
     ReturnInHeader(aSelection, *blockParent, node, offset);
     *aHandled = true;
     return NS_OK;
   } else if (blockParent->IsHTMLElement(nsGkAtoms::p)) {
     // Paragraphs: special rules to look for <br>s
-    res = ReturnInParagraph(&aSelection, GetAsDOMNode(blockParent),
-                            GetAsDOMNode(node), offset, aCancel, aHandled);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      ReturnInParagraph(&aSelection, GetAsDOMNode(blockParent),
+                        GetAsDOMNode(node), offset, aCancel, aHandled);
+    NS_ENSURE_SUCCESS(rv, rv);
     // Fall through, we may not have handled it in ReturnInParagraph()
   }
 
   // If not already handled then do the standard thing
   if (!(*aHandled)) {
     *aHandled = true;
     return StandardBreakImpl(node, offset, aSelection);
   }
@@ -1577,17 +1592,16 @@ HTMLEditRules::StandardBreakImpl(nsINode
 {
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   nsCOMPtr<Element> brNode;
   bool bAfterBlock = false;
   bool bBeforeBlock = false;
   nsCOMPtr<nsINode> node = &aNode;
-  nsresult res;
 
   if (IsPlaintextEditor()) {
     brNode = htmlEditor->CreateBR(node, aOffset);
     NS_ENSURE_STATE(brNode);
   } else {
     WSRunObject wsObj(htmlEditor, node, aOffset);
     int32_t visOffset = 0;
     WSType wsType;
@@ -1620,18 +1634,18 @@ HTMLEditRules::StandardBreakImpl(nsINode
   node = brNode->GetParentNode();
   NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
   int32_t offset = node->IndexOf(brNode);
   if (bAfterBlock && bBeforeBlock) {
     // We just placed a br between block boundaries.  This is the one case
     // where we want the selection to be before the br we just placed, as the
     // br will be on a new line, rather than at end of prior line.
     aSelection.SetInterlinePosition(true);
-    res = aSelection.Collapse(node, offset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = aSelection.Collapse(node, offset);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     WSRunObject wsObj(htmlEditor, node, offset + 1);
     nsCOMPtr<nsINode> secondBR;
     int32_t visOffset = 0;
     WSType wsType;
     wsObj.NextVisibleNode(node, offset + 1, address_of(secondBR),
                           &visOffset, &wsType);
     if (wsType == WSType::br) {
@@ -1639,35 +1653,36 @@ HTMLEditRules::StandardBreakImpl(nsINode
       // second break to be the first break's sibling.  This will prevent them
       // from being in different inline nodes, which would break
       // SetInterlinePosition().  It will also assure that if the user clicks
       // away and then clicks back on their new blank line, they will still get
       // the style from the line above.
       nsCOMPtr<nsINode> brParent = secondBR->GetParentNode();
       int32_t brOffset = brParent ? brParent->IndexOf(secondBR) : -1;
       if (brParent != node || brOffset != offset + 1) {
-        res = htmlEditor->MoveNode(secondBR->AsContent(), node, offset + 1);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv =
+          htmlEditor->MoveNode(secondBR->AsContent(), node, offset + 1);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
     // SetInterlinePosition(true) means we want the caret to stick to the
     // content on the "right".  We want the caret to stick to whatever is past
     // the break.  This is because the break is on the same line we were on,
     // but the next content will be on the following line.
 
     // An exception to this is if the break has a next sibling that is a block
     // node.  Then we stick to the left to avoid an uber caret.
     nsCOMPtr<nsIContent> siblingNode = brNode->GetNextSibling();
     if (siblingNode && IsBlockNode(*siblingNode)) {
       aSelection.SetInterlinePosition(false);
     } else {
       aSelection.SetInterlinePosition(true);
     }
-    res = aSelection.Collapse(node, offset + 1);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = aSelection.Collapse(node, offset + 1);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::DidInsertBreak(Selection* aSelection,
                               nsresult aResult)
 {
@@ -1679,20 +1694,21 @@ HTMLEditRules::SplitMailCites(Selection*
                               bool* aHandled)
 {
   NS_ENSURE_TRUE(aSelection && aHandled, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIContent> leftCite, rightCite;
   nsCOMPtr<nsINode> selNode;
   nsCOMPtr<Element> citeNode;
   int32_t selOffset;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode),
+                                       &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   citeNode = GetTopEnclosingMailCite(*selNode);
-  NS_ENSURE_SUCCESS(res, res);
   if (citeNode)
   {
     // If our selection is just before a break, nudge it to be
     // just after it.  This does two things for us.  It saves us the trouble of having to add
     // a break here ourselves to preserve the "blockness" of the inline span mailquote
     // (in the inline case), and :
     // it means the break won't end up making an empty line that happens to be inside a
     // mailquote (in either inline or block case).
@@ -1722,18 +1738,18 @@ HTMLEditRules::SplitMailCites(Selection*
         getter_AddRefs(leftCite), getter_AddRefs(rightCite));
     NS_ENSURE_STATE(newOffset != -1);
     selNode = citeNode->GetParentNode();
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(selNode, newOffset);
     NS_ENSURE_STATE(brNode);
     // want selection before the break, and on same line
     aSelection->SetInterlinePosition(true);
-    res = aSelection->Collapse(selNode, newOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = aSelection->Collapse(selNode, newOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
     // if citeNode wasn't a block, we might also want another break before it.
     // We need to examine the content both before the br we just added and also
     // just after it.  If we don't have another br or block boundary adjacent,
     // then we will need a 2nd br added to achieve blank line that user expects.
     if (IsInlineNode(*citeNode)) {
       NS_ENSURE_STATE(mHTMLEditor);
       WSRunObject wsObj(mHTMLEditor, selNode, newOffset);
       nsCOMPtr<nsINode> visNode;
@@ -1755,32 +1771,42 @@ HTMLEditRules::SplitMailCites(Selection*
         }
       }
     }
     // delete any empty cites
     bool bEmptyCite = false;
     if (leftCite)
     {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->IsEmptyNode(leftCite, &bEmptyCite, true, false);
-      if (NS_SUCCEEDED(res) && bEmptyCite) {
+      rv = mHTMLEditor->IsEmptyNode(leftCite, &bEmptyCite, true, false);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+      if (bEmptyCite) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->DeleteNode(leftCite);
-      }
-      NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->DeleteNode(leftCite);
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return rv;
+        }
+      }
     }
     if (rightCite)
     {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->IsEmptyNode(rightCite, &bEmptyCite, true, false);
-      if (NS_SUCCEEDED(res) && bEmptyCite) {
+      rv = mHTMLEditor->IsEmptyNode(rightCite, &bEmptyCite, true, false);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+      if (bEmptyCite) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->DeleteNode(rightCite);
-      }
-      NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->DeleteNode(rightCite);
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return rv;
+        }
+      }
     }
     *aHandled = true;
   }
   return NS_OK;
 }
 
 
 nsresult
@@ -1807,22 +1833,23 @@ HTMLEditRules::WillDeleteSelection(Selec
   if (mBogusNode) {
     *aCancel = true;
     return NS_OK;
   }
 
   // First check for table selection mode.  If so, hand off to table editor.
   nsCOMPtr<nsIDOMElement> cell;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetFirstSelectedCell(nullptr, getter_AddRefs(cell));
-  if (NS_SUCCEEDED(res) && cell) {
+  nsresult rv =
+    mHTMLEditor->GetFirstSelectedCell(nullptr, getter_AddRefs(cell));
+  if (NS_SUCCEEDED(rv) && cell) {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->DeleteTableCellContents();
+    rv = mHTMLEditor->DeleteTableCellContents();
     *aHandled = true;
-    return res;
+    return rv;
   }
   cell = nullptr;
 
   // origCollapsed is used later to determine whether we should join blocks. We
   // don't really care about bCollapsed because it will be modified by
   // ExtendSelectionForDelete later. JoinBlocks should happen if the original
   // selection is collapsed and the cursor is at the end of a block element, in
   // which case ExtendSelectionForDelete would always make the selection not
@@ -1840,33 +1867,33 @@ HTMLEditRules::WillDeleteSelection(Selec
   NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
 
 
   if (bCollapsed) {
     // If we are inside an empty block, delete it.
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> host = mHTMLEditor->GetActiveEditingHost();
     NS_ENSURE_TRUE(host, NS_ERROR_FAILURE);
-    res = CheckForEmptyBlock(startNode, host, aSelection, aAction, aHandled);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = CheckForEmptyBlock(startNode, host, aSelection, aAction, aHandled);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (*aHandled) {
       return NS_OK;
     }
 
     // Test for distance between caret and text that will be deleted
-    res = CheckBidiLevelForDeletion(aSelection, GetAsDOMNode(startNode),
-                                    startOffset, aAction, aCancel);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = CheckBidiLevelForDeletion(aSelection, GetAsDOMNode(startNode),
+                                   startOffset, aAction, aCancel);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (*aCancel) {
       return NS_OK;
     }
 
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // We should delete nothing.
     if (aAction == nsIEditor::eNone) {
       return NS_OK;
     }
 
     // ExtendSelectionForDelete() may have changed the selection, update it
     NS_ENSURE_STATE(aSelection->GetRangeAt(0));
@@ -1892,30 +1919,36 @@ HTMLEditRules::WillDeleteSelection(Selec
     } else {
       wsObj.PriorVisibleNode(startNode, startOffset, address_of(visNode),
                              &visOffset, &wsType);
     }
 
     if (!visNode) {
       // Can't find anything to delete!
       *aCancel = true;
-      return res;
+      // XXX This is the result of mHTMLEditor->GetFirstSelectedCell().
+      //     The value could be both an error and NS_OK.
+      return rv;
     }
 
     if (wsType == WSType::normalWS) {
       // We found some visible ws to delete.  Let ws code handle it.
+      *aHandled = true;
       if (aAction == nsIEditor::eNext) {
-        res = wsObj.DeleteWSForward();
+        rv = wsObj.DeleteWSForward();
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return rv;
+        }
       } else {
-        res = wsObj.DeleteWSBackward();
-      }
-      *aHandled = true;
-      NS_ENSURE_SUCCESS(res, res);
-      res = InsertBRIfNeeded(aSelection);
-      return res;
+        rv = wsObj.DeleteWSBackward();
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return rv;
+        }
+      }
+      return InsertBRIfNeeded(aSelection);
     }
 
     if (wsType == WSType::text) {
       // Found normal text to delete.
       OwningNonNull<Text> nodeAsText = *visNode->GetAsText();
       int32_t so = visOffset;
       int32_t eo = visOffset + 1;
       if (aAction == nsIEditor::ePrevious) {
@@ -1940,45 +1973,45 @@ HTMLEditRules::WillDeleteSelection(Selec
                      "selection start not in visNode");
         NS_ASSERTION(range->GetEndParent() == visNode,
                      "selection end not in visNode");
 
         so = range->StartOffset();
         eo = range->EndOffset();
       }
       NS_ENSURE_STATE(mHTMLEditor);
-      res = WSRunObject::PrepareToDeleteRange(mHTMLEditor,
-          address_of(visNode), &so, address_of(visNode), &eo);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = WSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(visNode),
+                                             &so, address_of(visNode), &eo);
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo),
-                                    DeprecatedAbs(eo - so));
       *aHandled = true;
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo),
+                                   DeprecatedAbs(eo - so));
+      NS_ENSURE_SUCCESS(rv, rv);
 
       DeleteNodeIfCollapsedText(nodeAsText);
 
-      res = InsertBRIfNeeded(aSelection);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = InsertBRIfNeeded(aSelection);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       // Remember that we did a ranged delete for the benefit of
       // AfterEditInner().
       mDidRangedDelete = true;
 
       return NS_OK;
     }
 
     if (wsType == WSType::special || wsType == WSType::br ||
         visNode->IsHTMLElement(nsGkAtoms::hr)) {
       // Short circuit for invisible breaks.  delete them and recurse.
       if (visNode->IsHTMLElement(nsGkAtoms::br) &&
           (!mHTMLEditor || !mHTMLEditor->IsVisBreak(visNode))) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->DeleteNode(visNode);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->DeleteNode(visNode);
+        NS_ENSURE_SUCCESS(rv, rv);
         return WillDeleteSelection(aSelection, aAction, aStripWrappers,
                                    aCancel, aHandled);
       }
 
       // Special handling for backspace when positioned after <hr>
       if (aAction == nsIEditor::ePrevious &&
           visNode->IsHTMLElement(nsGkAtoms::hr)) {
         // Only if the caret is positioned at the end-of-hr-line position, we
@@ -1999,18 +2032,18 @@ HTMLEditRules::WillDeleteSelection(Selec
         // interlineposition to false, only moving the caret to the
         // end-of-hr-line position.
         bool moveOnly = true;
 
         selNode = visNode->GetParentNode();
         selOffset = selNode ? selNode->IndexOf(visNode) : -1;
 
         bool interLineIsRight;
-        res = aSelection->GetInterlinePosition(&interLineIsRight);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = aSelection->GetInterlinePosition(&interLineIsRight);
+        NS_ENSURE_SUCCESS(rv, rv);
 
         if (startNode == selNode && startOffset - 1 == selOffset &&
             !interLineIsRight) {
           moveOnly = false;
         }
 
         if (moveOnly) {
           // Go to the position after the <hr>, but to the end of the <hr> line
@@ -2031,60 +2064,59 @@ HTMLEditRules::WillDeleteSelection(Selec
           wsObj.NextVisibleNode(startNode, startOffset, address_of(otherNode),
                                 &otherOffset, &otherWSType);
 
           if (otherWSType == WSType::br) {
             // Delete the <br>
 
             NS_ENSURE_STATE(mHTMLEditor);
             nsCOMPtr<nsIContent> otherContent(do_QueryInterface(otherNode));
-            res = WSRunObject::PrepareToDeleteNode(mHTMLEditor, otherContent);
-            NS_ENSURE_SUCCESS(res, res);
+            rv = WSRunObject::PrepareToDeleteNode(mHTMLEditor, otherContent);
+            NS_ENSURE_SUCCESS(rv, rv);
             NS_ENSURE_STATE(mHTMLEditor);
-            res = mHTMLEditor->DeleteNode(otherNode);
-            NS_ENSURE_SUCCESS(res, res);
+            rv = mHTMLEditor->DeleteNode(otherNode);
+            NS_ENSURE_SUCCESS(rv, rv);
           }
 
           return NS_OK;
         }
         // Else continue with normal delete code
       }
 
       // Found break or image, or hr.
       NS_ENSURE_STATE(mHTMLEditor);
       NS_ENSURE_STATE(visNode->IsContent());
-      res = WSRunObject::PrepareToDeleteNode(mHTMLEditor,
-                                             visNode->AsContent());
-      NS_ENSURE_SUCCESS(res, res);
+      rv = WSRunObject::PrepareToDeleteNode(mHTMLEditor, visNode->AsContent());
+      NS_ENSURE_SUCCESS(rv, rv);
       // Remember sibling to visnode, if any
       NS_ENSURE_STATE(mHTMLEditor);
       nsCOMPtr<nsIContent> sibling = mHTMLEditor->GetPriorHTMLSibling(visNode);
       // Delete the node, and join like nodes if appropriate
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(visNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteNode(visNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       // We did something, so let's say so.
       *aHandled = true;
       // Is there a prior node and are they siblings?
       nsCOMPtr<nsINode> stepbrother;
       if (sibling) {
         NS_ENSURE_STATE(mHTMLEditor);
         stepbrother = mHTMLEditor->GetNextHTMLSibling(sibling);
       }
       // Are they both text nodes?  If so, join them!
       if (startNode == stepbrother && startNode->GetAsText() &&
           sibling->GetAsText()) {
         EditorDOMPoint pt = JoinNodesSmart(*sibling, *startNode->AsContent());
         NS_ENSURE_STATE(pt.node);
         // Fix up selection
-        res = aSelection->Collapse(pt.node, pt.offset);
-        NS_ENSURE_SUCCESS(res, res);
-      }
-      res = InsertBRIfNeeded(aSelection);
-      NS_ENSURE_SUCCESS(res, res);
+        rv = aSelection->Collapse(pt.node, pt.offset);
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
+      rv = InsertBRIfNeeded(aSelection);
+      NS_ENSURE_SUCCESS(rv, rv);
       return NS_OK;
     }
 
     if (wsType == WSType::otherBlock) {
       // Make sure it's not a table element.  If so, cancel the operation
       // (translation: users cannot backspace or delete across table cells)
       if (HTMLEditUtils::IsTableElement(visNode)) {
         *aCancel = true;
@@ -2120,18 +2152,20 @@ HTMLEditRules::WillDeleteSelection(Selec
         NS_ENSURE_STATE(mHTMLEditor);
         leafNode = mHTMLEditor->GetFirstEditableLeaf(*visNode);
         leftNode = startNode;
         rightNode = leafNode;
       }
 
       if (otherNode->IsHTMLElement(nsGkAtoms::br)) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->DeleteNode(otherNode);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->DeleteNode(otherNode);
+        NS_ENSURE_SUCCESS(rv, rv);
+        // XXX Only in this case, setting "handled" to true only when it
+        //     succeeds?
         *aHandled = true;
         bDeletedBR = true;
       }
 
       // Don't cross table boundaries
       if (leftNode && rightNode &&
           InDifferentTableElements(leftNode, rightNode)) {
         return NS_OK;
@@ -2151,20 +2185,20 @@ HTMLEditRules::WillDeleteSelection(Selec
       nsCOMPtr<nsINode> selPointNode = startNode;
       int32_t selPointOffset = startOffset;
       {
         NS_ENSURE_STATE(mHTMLEditor);
         AutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater,
                                   address_of(selPointNode), &selPointOffset);
         NS_ENSURE_STATE(leftNode && leftNode->IsContent() &&
                         rightNode && rightNode->IsContent());
-        res = JoinBlocks(*leftNode->AsContent(), *rightNode->AsContent(),
-                         aCancel);
         *aHandled = true;
-        NS_ENSURE_SUCCESS(res, res);
+        rv = JoinBlocks(*leftNode->AsContent(), *rightNode->AsContent(),
+                        aCancel);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       aSelection->Collapse(selPointNode, selPointOffset);
       return NS_OK;
     }
 
     if (wsType == WSType::thisBlock) {
       // At edge of our block.  Look beside it and see if we can join to an
       // adjacent block
@@ -2202,30 +2236,30 @@ HTMLEditRules::WillDeleteSelection(Selec
 
       nsCOMPtr<nsINode> selPointNode = startNode;
       int32_t selPointOffset = startOffset;
       {
         NS_ENSURE_STATE(mHTMLEditor);
         AutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater,
                                   address_of(selPointNode), &selPointOffset);
         NS_ENSURE_STATE(leftNode->IsContent() && rightNode->IsContent());
-        res = JoinBlocks(*leftNode->AsContent(), *rightNode->AsContent(),
-                         aCancel);
         *aHandled = true;
-        NS_ENSURE_SUCCESS(res, res);
+        rv = JoinBlocks(*leftNode->AsContent(), *rightNode->AsContent(),
+                        aCancel);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       aSelection->Collapse(selPointNode, selPointOffset);
       return NS_OK;
     }
   }
 
 
   // Else we have a non-collapsed selection.  First adjust the selection.
-  res = ExpandSelectionForDeletion(*aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = ExpandSelectionForDeletion(*aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Remember that we did a ranged delete for the benefit of AfterEditInner().
   mDidRangedDelete = true;
 
   // Refresh start and end points
   NS_ENSURE_STATE(aSelection->GetRangeAt(0));
   startNode = aSelection->GetRangeAt(0)->GetStartParent();
   startOffset = aSelection->GetRangeAt(0)->StartOffset();
@@ -2234,36 +2268,36 @@ HTMLEditRules::WillDeleteSelection(Selec
   int32_t endOffset = aSelection->GetRangeAt(0)->EndOffset();
   NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
 
   // Figure out if the endpoints are in nodes that can be merged.  Adjust
   // surrounding whitespace in preparation to delete selection.
   if (!IsPlaintextEditor()) {
     NS_ENSURE_STATE(mHTMLEditor);
     AutoTransactionsConserveSelection dontSpazMySelection(mHTMLEditor);
-    res = WSRunObject::PrepareToDeleteRange(mHTMLEditor,
-                                            address_of(startNode), &startOffset,
-                                            address_of(endNode), &endOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = WSRunObject::PrepareToDeleteRange(mHTMLEditor,
+                                           address_of(startNode), &startOffset,
+                                           address_of(endNode), &endOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   {
     // Track location of where we are deleting
     NS_ENSURE_STATE(mHTMLEditor);
     AutoTrackDOMPoint startTracker(mHTMLEditor->mRangeUpdater,
                                    address_of(startNode), &startOffset);
     AutoTrackDOMPoint endTracker(mHTMLEditor->mRangeUpdater,
                                  address_of(endNode), &endOffset);
     // We are handling all ranged deletions directly now.
     *aHandled = true;
 
     if (endNode == startNode) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       // Figure out mailcite ancestors
       nsCOMPtr<Element> startCiteNode = GetTopEnclosingMailCite(*startNode);
       nsCOMPtr<Element> endCiteNode = GetTopEnclosingMailCite(*endNode);
 
       // If we only have a mailcite at one of the two endpoints, set the
       // directionality of the deletion so that the selection will end up
       // outside the mailcite.
@@ -2276,17 +2310,17 @@ HTMLEditRules::WillDeleteSelection(Selec
       // Figure out block parents
       NS_ENSURE_STATE(mHTMLEditor);
       nsCOMPtr<Element> leftParent = mHTMLEditor->GetBlock(*startNode);
       nsCOMPtr<Element> rightParent = mHTMLEditor->GetBlock(*endNode);
 
       // Are endpoint block parents the same?  Use default deletion
       if (leftParent && leftParent == rightParent) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
+        mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
       } else {
         // Deleting across blocks.  Are the blocks of same type?
         NS_ENSURE_STATE(leftParent && rightParent);
 
         // Are the blocks siblings?
         nsCOMPtr<nsINode> leftBlockParent = leftParent->GetParentNode();
         nsCOMPtr<nsINode> rightBlockParent = rightParent->GetParentNode();
 
@@ -2296,43 +2330,43 @@ HTMLEditRules::WillDeleteSelection(Selec
             mHTMLEditor->NodesSameType(GetAsDOMNode(leftParent),
                                        GetAsDOMNode(rightParent)) &&
             // XXX What's special about these three types of block?
             (leftParent->IsHTMLElement(nsGkAtoms::p) ||
              HTMLEditUtils::IsListItem(leftParent) ||
              HTMLEditUtils::IsHeader(*leftParent))) {
             // First delete the selection
             NS_ENSURE_STATE(mHTMLEditor);
-            res = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
-            NS_ENSURE_SUCCESS(res, res);
+            rv = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
+            NS_ENSURE_SUCCESS(rv, rv);
             // Join blocks
             NS_ENSURE_STATE(mHTMLEditor);
             EditorDOMPoint pt =
               mHTMLEditor->JoinNodeDeep(*leftParent, *rightParent);
             NS_ENSURE_STATE(pt.node);
             // Fix up selection
-            res = aSelection->Collapse(pt.node, pt.offset);
-            NS_ENSURE_SUCCESS(res, res);
+            rv = aSelection->Collapse(pt.node, pt.offset);
+            NS_ENSURE_SUCCESS(rv, rv);
             return NS_OK;
         }
 
         // Else blocks not same type, or not siblings.  Delete everything
         // except table elements.
         join = true;
 
         uint32_t rangeCount = aSelection->RangeCount();
         for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
           OwningNonNull<nsRange> range = *aSelection->GetRangeAt(rangeIdx);
 
           // Build a list of nodes in the range
           nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
           TrivialFunctor functor;
           DOMSubtreeIterator iter;
-          nsresult res = iter.Init(*range);
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = iter.Init(*range);
+          NS_ENSURE_SUCCESS(rv, rv);
           iter.AppendList(functor, arrayOfNodes);
 
           // Now that we have the list, delete non-table elements
           int32_t listCount = arrayOfNodes.Length();
           for (int32_t j = 0; j < listCount; j++) {
             nsCOMPtr<nsINode> somenode = do_QueryInterface(arrayOfNodes[0]);
             NS_ENSURE_STATE(somenode);
             DeleteNonTableElements(somenode);
@@ -2362,32 +2396,32 @@ HTMLEditRules::WillDeleteSelection(Selec
         // appropriate, since the case where both sel endpoints in same text
         // node was already handled (we wouldn't be here)
         if (startNode->GetAsText() &&
             startNode->Length() > uint32_t(startOffset)) {
           // Delete to last character
           OwningNonNull<nsGenericDOMDataNode> dataNode =
             *static_cast<nsGenericDOMDataNode*>(startNode.get());
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->DeleteText(dataNode, startOffset,
-              startNode->Length() - startOffset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mHTMLEditor->DeleteText(dataNode, startOffset,
+                                       startNode->Length() - startOffset);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
         if (endNode->GetAsText() && endOffset) {
           // Delete to first character
           NS_ENSURE_STATE(mHTMLEditor);
           OwningNonNull<nsGenericDOMDataNode> dataNode =
             *static_cast<nsGenericDOMDataNode*>(endNode.get());
-          res = mHTMLEditor->DeleteText(dataNode, 0, endOffset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mHTMLEditor->DeleteText(dataNode, 0, endOffset);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
 
         if (join) {
-          res = JoinBlocks(*leftParent, *rightParent, aCancel);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = JoinBlocks(*leftParent, *rightParent, aCancel);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
       }
     }
   }
 
   // We might have left only collapsed whitespace in the start/end nodes
   {
     AutoTrackDOMPoint startTracker(mHTMLEditor->mRangeUpdater,
@@ -2403,21 +2437,26 @@ HTMLEditRules::WillDeleteSelection(Selec
   // collapsed to the end of the selection, if deleting backward the selection
   // should be collapsed to the beginning of the selection. But if we're not
   // joining then the selection should collapse to the beginning of the
   // selection if we'redeleting forward, because the end of the selection will
   // still be in the next block. And same thing for deleting backwards
   // (selection should collapse to the end, because the beginning will still be
   // in the first block). See Bug 507936
   if (aAction == (join ? nsIEditor::eNext : nsIEditor::ePrevious)) {
-    res = aSelection->Collapse(endNode, endOffset);
+    rv = aSelection->Collapse(endNode, endOffset);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   } else {
-    res = aSelection->Collapse(startNode, startOffset);
-  }
-  NS_ENSURE_SUCCESS(res, res);
+    rv = aSelection->Collapse(startNode, startOffset);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
   return NS_OK;
 }
 
 /**
  * If aNode is a text node that contains only collapsed whitespace, delete it.
  * It doesn't serve any useful purpose, and we don't want it to confuse code
  * that doesn't correctly skip over it.
  *
@@ -2426,18 +2465,18 @@ HTMLEditRules::WillDeleteSelection(Selec
  */
 void
 HTMLEditRules::DeleteNodeIfCollapsedText(nsINode& aNode)
 {
   if (!aNode.GetAsText()) {
     return;
   }
   bool empty;
-  nsresult res = mHTMLEditor->IsVisTextNode(aNode.AsContent(), &empty, false);
-  NS_ENSURE_SUCCESS_VOID(res);
+  nsresult rv = mHTMLEditor->IsVisTextNode(aNode.AsContent(), &empty, false);
+  NS_ENSURE_SUCCESS_VOID(rv);
   if (empty) {
     mHTMLEditor->DeleteNode(&aNode);
   }
 }
 
 
 /**
  * InsertBRIfNeeded() determines if a br is needed for current selection to not
@@ -2449,20 +2488,20 @@ HTMLEditRules::DeleteNodeIfCollapsedText
 nsresult
 HTMLEditRules::InsertBRIfNeeded(Selection* aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
 
   // get selection
   nsCOMPtr<nsINode> node;
   int32_t offset;
-  nsresult res = mTextEditor->GetStartNodeAndOffset(aSelection,
-                                                    getter_AddRefs(node),
-                                                    &offset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mTextEditor->GetStartNodeAndOffset(aSelection,
+                                       getter_AddRefs(node), &offset);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
   // inline elements don't need any br
   if (!IsBlockNode(*node)) {
     return NS_OK;
   }
 
   // examine selection
@@ -2593,95 +2632,94 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
       rightBlock = rightList;
       mergeLists = true;
       existingList = leftList->NodeInfo()->NameAtom();
     }
   }
 
   AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
 
-  nsresult res = NS_OK;
   int32_t rightOffset = 0;
   int32_t leftOffset = -1;
 
   // offset below is where you find yourself in rightBlock when you traverse
   // upwards from leftBlock
   if (EditorUtils::IsDescendantOf(leftBlock, rightBlock, &rightOffset)) {
     // Tricky case.  Left block is inside right block.  Do ws adjustment.  This
     // just destroys non-visible ws at boundaries we will be joining.
     rightOffset++;
-    res = WSRunObject::ScrubBlockBoundary(htmlEditor,
-                                          WSRunObject::kBlockEnd,
-                                          leftBlock);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
+                                                  WSRunObject::kBlockEnd,
+                                                  leftBlock);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     {
       // We can't just track rightBlock because it's an Element.
       nsCOMPtr<nsINode> trackingRightBlock(rightBlock);
       AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater,
                                 address_of(trackingRightBlock), &rightOffset);
-      res = WSRunObject::ScrubBlockBoundary(htmlEditor,
-                                            WSRunObject::kAfterBlock,
-                                            rightBlock, rightOffset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
+                                           WSRunObject::kAfterBlock,
+                                           rightBlock, rightOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (trackingRightBlock->IsElement()) {
         rightBlock = trackingRightBlock->AsElement();
       } else {
         NS_ENSURE_STATE(trackingRightBlock->GetParentElement());
         rightBlock = trackingRightBlock->GetParentElement();
       }
     }
     // Do br adjustment.
     nsCOMPtr<Element> brNode =
       CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
     if (mergeLists) {
       // The idea here is to take all children in rightList that are past
       // offset, and pull them into leftlist.
       for (nsCOMPtr<nsIContent> child = rightList->GetChildAt(offset);
            child; child = rightList->GetChildAt(rightOffset)) {
-        res = htmlEditor->MoveNode(child, leftList, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->MoveNode(child, leftList, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     } else {
-      res = MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
+      MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
     }
     if (brNode) {
       htmlEditor->DeleteNode(brNode);
     }
   // Offset below is where you find yourself in leftBlock when you traverse
   // upwards from rightBlock
   } else if (EditorUtils::IsDescendantOf(rightBlock, leftBlock, &leftOffset)) {
     // Tricky case.  Right block is inside left block.  Do ws adjustment.  This
     // just destroys non-visible ws at boundaries we will be joining.
-    res = WSRunObject::ScrubBlockBoundary(htmlEditor,
-                                          WSRunObject::kBlockStart,
-                                          rightBlock);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
+                                                  WSRunObject::kBlockStart,
+                                                  rightBlock);
+    NS_ENSURE_SUCCESS(rv, rv);
     {
       // We can't just track leftBlock because it's an Element, so track
       // something else.
       nsCOMPtr<nsINode> trackingLeftBlock(leftBlock);
       AutoTrackDOMPoint tracker(htmlEditor->mRangeUpdater,
                                 address_of(trackingLeftBlock), &leftOffset);
-      res = WSRunObject::ScrubBlockBoundary(htmlEditor,
-                                            WSRunObject::kBeforeBlock,
-                                            leftBlock, leftOffset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
+                                           WSRunObject::kBeforeBlock,
+                                           leftBlock, leftOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (trackingLeftBlock->IsElement()) {
         leftBlock = trackingLeftBlock->AsElement();
       } else {
         NS_ENSURE_STATE(trackingLeftBlock->GetParentElement());
         leftBlock = trackingLeftBlock->GetParentElement();
       }
     }
     // Do br adjustment.
     nsCOMPtr<Element> brNode =
       CheckForInvisibleBR(*leftBlock, BRLocation::beforeBlock, leftOffset);
     if (mergeLists) {
-      res = MoveContents(*rightList, *leftList, &leftOffset);
+      MoveContents(*rightList, *leftList, &leftOffset);
     } else {
       // Left block is a parent of right block, and the parent of the previous
       // visible content.  Right block is a child and contains the contents we
       // want to move.
 
       int32_t previousContentOffset;
       nsCOMPtr<nsINode> previousContentParent;
 
@@ -2711,67 +2749,69 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
       }
 
       // Because we don't want the moving content to receive the style of the
       // previous content, we split the previous content's style.
 
       nsCOMPtr<Element> editorRoot = htmlEditor->GetEditorRoot();
       if (!editorRoot || &aLeftNode != editorRoot) {
         nsCOMPtr<nsIContent> splittedPreviousContent;
-        res = htmlEditor->SplitStyleAbovePoint(address_of(previousContentParent),
-                                               &previousContentOffset,
-                                               nullptr, nullptr, nullptr,
-                                               getter_AddRefs(splittedPreviousContent));
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->SplitStyleAbovePoint(
+                           address_of(previousContentParent),
+                           &previousContentOffset,
+                           nullptr, nullptr, nullptr,
+                           getter_AddRefs(splittedPreviousContent));
+        NS_ENSURE_SUCCESS(rv, rv);
 
         if (splittedPreviousContent) {
           previousContentParent = splittedPreviousContent->GetParentNode();
           previousContentOffset = previousContentParent ?
             previousContentParent->IndexOf(splittedPreviousContent) : -1;
         }
       }
 
       NS_ENSURE_TRUE(previousContentParent, NS_ERROR_NULL_POINTER);
 
-      res = MoveBlock(*previousContentParent->AsElement(), *rightBlock,
-          previousContentOffset, rightOffset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = MoveBlock(*previousContentParent->AsElement(), *rightBlock,
+                     previousContentOffset, rightOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     if (brNode) {
       htmlEditor->DeleteNode(brNode);
     }
   } else {
     // Normal case.  Blocks are siblings, or at least close enough.  An example
     // of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>.  The
     // first li and the p are not true siblings, but we still want to join them
     // if you backspace from li into p.
 
     // Adjust whitespace at block boundaries
-    res = WSRunObject::PrepareToJoinBlocks(htmlEditor, leftBlock, rightBlock);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      WSRunObject::PrepareToJoinBlocks(htmlEditor, leftBlock, rightBlock);
+    NS_ENSURE_SUCCESS(rv, rv);
     // Do br adjustment.
     nsCOMPtr<Element> brNode =
       CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
     if (mergeLists || leftBlock->NodeInfo()->NameAtom() ==
                       rightBlock->NodeInfo()->NameAtom()) {
       // Nodes are same type.  merge them.
       EditorDOMPoint pt = JoinNodesSmart(*leftBlock, *rightBlock);
       if (pt.node && mergeLists) {
         nsCOMPtr<Element> newBlock;
-        res = ConvertListType(rightBlock, getter_AddRefs(newBlock),
-                              existingList, nsGkAtoms::li);
+        ConvertListType(rightBlock, getter_AddRefs(newBlock),
+                        existingList, nsGkAtoms::li);
       }
     } else {
       // Nodes are dissimilar types.
-      res = MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = MoveBlock(*leftBlock, *rightBlock, leftOffset, rightOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     if (brNode) {
-      res = htmlEditor->DeleteNode(brNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->DeleteNode(brNode);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return NS_OK;
 }
 
 
 /**
  * Moves the content from aRightBlock starting from aRightOffset into
@@ -2782,38 +2822,38 @@ HTMLEditRules::JoinBlocks(nsIContent& aL
 nsresult
 HTMLEditRules::MoveBlock(Element& aLeftBlock,
                          Element& aRightBlock,
                          int32_t aLeftOffset,
                          int32_t aRightOffset)
 {
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
   // GetNodesFromPoint is the workhorse that figures out what we wnat to move.
-  nsresult res = GetNodesFromPoint(EditorDOMPoint(&aRightBlock, aRightOffset),
-                                   EditAction::makeList, arrayOfNodes,
-                                   TouchContent::yes);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetNodesFromPoint(EditorDOMPoint(&aRightBlock, aRightOffset),
+                                  EditAction::makeList, arrayOfNodes,
+                                  TouchContent::yes);
+  NS_ENSURE_SUCCESS(rv, rv);
   for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) {
     // get the node to act on
     if (IsBlockNode(arrayOfNodes[i])) {
       // For block nodes, move their contents only, then delete block.
-      res = MoveContents(*arrayOfNodes[i]->AsElement(), aLeftBlock,
-                         &aLeftOffset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = MoveContents(*arrayOfNodes[i]->AsElement(), aLeftBlock,
+                        &aLeftOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(arrayOfNodes[i]);
+      rv = mHTMLEditor->DeleteNode(arrayOfNodes[i]);
     } else {
       // Otherwise move the content as is, checking against the DTD.
-      res = MoveNodeSmart(*arrayOfNodes[i]->AsContent(), aLeftBlock,
-                          &aLeftOffset);
+      rv = MoveNodeSmart(*arrayOfNodes[i]->AsContent(), aLeftBlock,
+                         &aLeftOffset);
     }
   }
 
   // XXX We're only checking return value of the last iteration
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 /**
  * This method is used to move node aNode to (aDestElement, aInOutDestOffset).
  * DTD containment rules are followed throughout.  aInOutDestOffset is updated
  * to point _after_ inserted content.
  */
@@ -2821,35 +2861,36 @@ nsresult
 HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
                              Element& aDestElement,
                              int32_t* aInOutDestOffset)
 {
   MOZ_ASSERT(aInOutDestOffset);
 
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
-  nsresult res;
 
   // Check if this node can go into the destination node
   if (htmlEditor->CanContain(aDestElement, aNode)) {
     // If it can, move it there
-    res = htmlEditor->MoveNode(&aNode, &aDestElement, *aInOutDestOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      htmlEditor->MoveNode(&aNode, &aDestElement, *aInOutDestOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (*aInOutDestOffset != -1) {
       (*aInOutDestOffset)++;
     }
   } else {
     // If it can't, move its children (if any), and then delete it.
     if (aNode.IsElement()) {
-      res = MoveContents(*aNode.AsElement(), aDestElement, aInOutDestOffset);
-      NS_ENSURE_SUCCESS(res, res);
-    }
-
-    res = htmlEditor->DeleteNode(&aNode);
-    NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        MoveContents(*aNode.AsElement(), aDestElement, aInOutDestOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+
+    nsresult rv = htmlEditor->DeleteNode(&aNode);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 /**
  * Moves the _contents_ of aElement to (aDestElement, aInOutDestOffset).  DTD
  * containment rules are followed throughout.  aInOutDestOffset is updated to
  * point _after_ inserted content.
@@ -2859,19 +2900,19 @@ HTMLEditRules::MoveContents(Element& aEl
                             Element& aDestElement,
                             int32_t* aInOutDestOffset)
 {
   MOZ_ASSERT(aInOutDestOffset);
 
   NS_ENSURE_TRUE(&aElement != &aDestElement, NS_ERROR_ILLEGAL_VALUE);
 
   while (aElement.GetFirstChild()) {
-    nsresult res = MoveNodeSmart(*aElement.GetFirstChild(), aDestElement,
-                                 aInOutDestOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = MoveNodeSmart(*aElement.GetFirstChild(), aDestElement,
+                                aInOutDestOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 
 nsresult
 HTMLEditRules::DeleteNonTableElements(nsINode* aNode)
 {
@@ -2893,36 +2934,36 @@ HTMLEditRules::DidDeleteSelection(Select
                                   nsIEditor::EDirection aDir,
                                   nsresult aResult)
 {
   if (!aSelection) { return NS_ERROR_NULL_POINTER; }
 
   // find where we are
   nsCOMPtr<nsINode> startNode;
   int32_t startOffset;
-  nsresult res = mTextEditor->GetStartNodeAndOffset(aSelection,
-                                                    getter_AddRefs(startNode),
-                                                    &startOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mTextEditor->GetStartNodeAndOffset(aSelection,
+                                                   getter_AddRefs(startNode),
+                                                   &startOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
 
   // find any enclosing mailcite
   nsCOMPtr<Element> citeNode = GetTopEnclosingMailCite(*startNode);
   if (citeNode) {
     bool isEmpty = true, seenBR = false;
     NS_ENSURE_STATE(mHTMLEditor);
     mHTMLEditor->IsEmptyNodeImpl(citeNode, &isEmpty, true, true, false,
                                  &seenBR);
     if (isEmpty)
     {
       int32_t offset;
       nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(citeNode, &offset);
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(citeNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteNode(citeNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (parent && seenBR)
       {
         NS_ENSURE_STATE(mHTMLEditor);
         nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(parent, offset);
         NS_ENSURE_STATE(brNode);
         aSelection->Collapse(parent, offset);
       }
     }
@@ -2966,25 +3007,25 @@ HTMLEditRules::WillMakeList(Selection* a
 
   // convert the selection ranges into "promoted" selection ranges:
   // this basically just expands the range to include the immediate
   // block parent, and then further expands to include any ancestors
   // whose children are all in the range
 
   *aHandled = true;
 
-  nsresult res = NormalizeSelection(aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(mHTMLEditor);
   AutoSelectionRestorer selectionRestorer(aSelection, mHTMLEditor);
 
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  res = GetListActionNodes(arrayOfNodes,
-                           aEntireList ? EntireList::yes : EntireList::no);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetListActionNodes(arrayOfNodes,
+                          aEntireList ? EntireList::yes : EntireList::no);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // check if all our nodes are <br>s, or empty inlines
   bool bOnlyBreaks = true;
   for (auto& curNode : arrayOfNodes) {
     // if curNode is not a Break or empty inline, we're done
     if (!TextEditUtils::IsBreak(curNode) &&
         !IsEmptyInline(curNode)) {
       bOnlyBreaks = false;
@@ -2994,53 +3035,53 @@ HTMLEditRules::WillMakeList(Selection* a
 
   // if no nodes, we make empty list.  Ditto if the user tried to make a list
   // of some # of breaks.
   if (!arrayOfNodes.Length() || bOnlyBreaks) {
     // if only breaks, delete them
     if (bOnlyBreaks) {
       for (auto& node : arrayOfNodes) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->DeleteNode(node);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->DeleteNode(node);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
 
     // get selection location
     NS_ENSURE_STATE(aSelection->RangeCount());
     nsCOMPtr<nsINode> parent = aSelection->GetRangeAt(0)->GetStartParent();
     int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
     NS_ENSURE_STATE(parent);
 
     // make sure we can put a list here
     NS_ENSURE_STATE(mHTMLEditor);
     if (!mHTMLEditor->CanContainTag(*parent, listType)) {
       *aCancel = true;
       return NS_OK;
     }
-    res = SplitAsNeeded(listType, parent, offset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = SplitAsNeeded(listType, parent, offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theList =
       mHTMLEditor->CreateNode(listType, parent, offset);
     NS_ENSURE_STATE(theList);
 
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theListItem =
       mHTMLEditor->CreateNode(itemType, theList, 0);
     NS_ENSURE_STATE(theListItem);
 
     // remember our new block for postprocessing
     mNewBlock = theListItem;
     // put selection in new list item
-    res = aSelection->Collapse(theListItem, 0);
+    *aHandled = true;
+    rv = aSelection->Collapse(theListItem, 0);
     // Don't restore the selection
     selectionRestorer.Abort();
-    *aHandled = true;
-    return res;
+    return rv;
   }
 
   // if there is only one node in the array, and it is a list, div, or
   // blockquote, then look inside of it until we find inner list or content.
 
   LookInsideDivBQandList(arrayOfNodes);
 
   // Ok, now go through all the nodes and put then in the list,
@@ -3062,49 +3103,49 @@ HTMLEditRules::WillMakeList(Selection* a
     // into the same list.  respect table cell boundaries when listifying.
     if (curList && InDifferentTableElements(curList, curNode)) {
       curList = nullptr;
     }
 
     // if curNode is a Break, delete it, and quit remembering prev list item
     if (TextEditUtils::IsBreak(curNode)) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteNode(curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       prevListItem = 0;
       continue;
     } else if (IsEmptyInline(curNode)) {
       // if curNode is an empty inline container, delete it
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteNode(curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       continue;
     }
 
     if (HTMLEditUtils::IsList(curNode)) {
       // do we have a curList already?
       if (curList && !EditorUtils::IsDescendantOf(curNode, curList)) {
         // move all of our children into curList.  cheezy way to do it: move
         // whole list and then RemoveContainer() on the list.  ConvertListType
         // first: that routine handles converting the list item types, if
         // needed
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, curList, -1);
-        NS_ENSURE_SUCCESS(res, res);
-        res = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
-                              listType, itemType);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(curNode, curList, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
+                             listType, itemType);
+        NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->RemoveBlockContainer(*newBlock);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->RemoveBlockContainer(*newBlock);
+        NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // replace list with new list type
-        res = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
-                              listType, itemType);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
+                             listType, itemType);
+        NS_ENSURE_SUCCESS(rv, rv);
         curList = newBlock;
       }
       prevListItem = 0;
       continue;
     }
 
     if (HTMLEditUtils::IsListItem(curNode)) {
       NS_ENSURE_STATE(mHTMLEditor);
@@ -3123,93 +3164,96 @@ HTMLEditRules::WillMakeList(Selection* a
           nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(curParent,
                                                                  &offset);
           NS_ENSURE_STATE(mHTMLEditor);
           curList = mHTMLEditor->CreateNode(listType, parent, offset);
           NS_ENSURE_STATE(curList);
         }
         // move list item to new list
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, curList, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(curNode, curList, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
         // convert list item type if needed
         NS_ENSURE_STATE(mHTMLEditor);
         if (!curNode->IsHTMLElement(itemType)) {
           NS_ENSURE_STATE(mHTMLEditor);
           newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
                                                    itemType);
           NS_ENSURE_STATE(newBlock);
         }
       } else {
         // item is in right type of list.  But we might still have to move it.
         // and we might need to convert list item types.
         if (!curList) {
           curList = curParent->AsElement();
         } else if (curParent != curList) {
           // move list item to new list
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->MoveNode(curNode, curList, -1);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mHTMLEditor->MoveNode(curNode, curList, -1);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
         NS_ENSURE_STATE(mHTMLEditor);
         if (!curNode->IsHTMLElement(itemType)) {
           NS_ENSURE_STATE(mHTMLEditor);
           newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
                                                    itemType);
           NS_ENSURE_STATE(newBlock);
         }
       }
+      NS_ENSURE_STATE(mHTMLEditor);
       nsCOMPtr<nsIDOMElement> curElement = do_QueryInterface(curNode);
       NS_NAMED_LITERAL_STRING(typestr, "type");
       if (aBulletType && !aBulletType->IsEmpty()) {
-        NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->SetAttribute(curElement, typestr, *aBulletType);
+        rv = mHTMLEditor->SetAttribute(curElement, typestr, *aBulletType);
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return rv;
+        }
       } else {
-        NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->RemoveAttribute(curElement, typestr);
-      }
-      NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->RemoveAttribute(curElement, typestr);
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return rv;
+        }
+      }
       continue;
     }
 
     // if we hit a div clear our prevListItem, insert divs contents
     // into our node array, and remove the div
     if (curNode->IsHTMLElement(nsGkAtoms::div)) {
       prevListItem = nullptr;
       int32_t j = i + 1;
       GetInnerContent(*curNode, arrayOfNodes, &j);
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->RemoveContainer(curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->RemoveContainer(curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       listCount = arrayOfNodes.Length();
       continue;
     }
 
     // need to make a list to put things in if we haven't already,
     if (!curList) {
-      res = SplitAsNeeded(listType, curParent, offset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = SplitAsNeeded(listType, curParent, offset);
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
       curList = mHTMLEditor->CreateNode(listType, curParent, offset);
-      NS_ENSURE_SUCCESS(res, res);
       // remember our new block for postprocessing
       mNewBlock = curList;
       // curList is now the correct thing to put curNode in
       prevListItem = 0;
     }
 
     // if curNode isn't a list item, we must wrap it in one
     nsCOMPtr<Element> listItem;
     if (!HTMLEditUtils::IsListItem(curNode)) {
       if (IsInlineNode(curNode) && prevListItem) {
         // this is a continuation of some inline nodes that belong together in
         // the same list item.  use prevListItem
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, prevListItem, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(curNode, prevListItem, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // don't wrap li around a paragraph.  instead replace paragraph with li
         if (curNode->IsHTMLElement(nsGkAtoms::p)) {
           NS_ENSURE_STATE(mHTMLEditor);
           listItem = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
                                                    itemType);
           NS_ENSURE_STATE(listItem);
         } else {
@@ -3226,48 +3270,48 @@ HTMLEditRules::WillMakeList(Selection* a
     } else {
       listItem = curNode->AsElement();
     }
 
     if (listItem) {
       // if we made a new list item, deal with it: tuck the listItem into the
       // end of the active list
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->MoveNode(listItem, curList, -1);
-      NS_ENSURE_SUCCESS(res, res);
-    }
-  }
-
-  return res;
+      rv = mHTMLEditor->MoveNode(listItem, curList, -1);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+  }
+
+  return NS_OK;
 }
 
 
 nsresult
 HTMLEditRules::WillRemoveList(Selection* aSelection,
                               bool aOrdered,
                               bool* aCancel,
                               bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   // initialize out param
   *aCancel = false;
   *aHandled = true;
 
-  nsresult res = NormalizeSelection(aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(mHTMLEditor);
   AutoSelectionRestorer selectionRestorer(aSelection, mHTMLEditor);
 
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
   GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::makeList);
 
   // use these ranges to contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  res = GetListActionNodes(arrayOfNodes, EntireList::no);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetListActionNodes(arrayOfNodes, EntireList::no);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Remove all non-editable nodes.  Leave them be.
   int32_t listCount = arrayOfNodes.Length();
   int32_t i;
   for (i=listCount-1; i>=0; i--)
   {
     OwningNonNull<nsINode> testNode = arrayOfNodes[i];
     NS_ENSURE_STATE(mHTMLEditor);
@@ -3283,26 +3327,26 @@ HTMLEditRules::WillRemoveList(Selection*
   // Only act on lists or list items in the array
   for (auto& curNode : arrayOfNodes) {
     // here's where we actually figure out what to do
     if (HTMLEditUtils::IsListItem(curNode)) {
       // unlist this listitem
       bool bOutOfList;
       do
       {
-        res = PopListItem(GetAsDOMNode(curNode), &bOutOfList);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = PopListItem(GetAsDOMNode(curNode), &bOutOfList);
+        NS_ENSURE_SUCCESS(rv, rv);
       } while (!bOutOfList); // keep popping it out until it's not in a list anymore
     } else if (HTMLEditUtils::IsList(curNode)) {
       // node is a list, move list items out
-      res = RemoveListStructure(*curNode->AsElement());
-      NS_ENSURE_SUCCESS(res, res);
-    }
-  }
-  return res;
+      rv = RemoveListStructure(*curNode->AsElement());
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+  }
+  return NS_OK;
 }
 
 
 nsresult
 HTMLEditRules::WillMakeDefListItem(Selection* aSelection,
                                    const nsAString *aItemType,
                                    bool aEntireList,
                                    bool* aCancel,
@@ -3326,27 +3370,27 @@ HTMLEditRules::WillMakeBasicBlock(Select
 
   OwningNonNull<nsIAtom> blockType = NS_Atomize(aBlockType);
 
   WillInsert(aSelection, aCancel);
   // We want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = false;
 
-  nsresult res = NormalizeSelection(&aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(&aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
   AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
   AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
   *aHandled = true;
 
   // Contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  res = GetNodesFromSelection(aSelection, EditAction::makeBasicBlock,
-                              arrayOfNodes);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetNodesFromSelection(aSelection, EditAction::makeBasicBlock,
+                             arrayOfNodes);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Remove all non-editable nodes.  Leave them be.
   for (int32_t i = arrayOfNodes.Length() - 1; i >= 0; i--) {
     if (!htmlEditor->IsEditable(arrayOfNodes[i])) {
       arrayOfNodes.RemoveElementAt(i);
     }
   }
 
@@ -3366,82 +3410,82 @@ HTMLEditRules::WillMakeBasicBlock(Select
       OwningNonNull<Element> curBlock = *htmlEditor->GetBlock(parent);
       if (HTMLEditUtils::IsFormatNode(curBlock)) {
         // If the first editable node after selection is a br, consume it.
         // Otherwise it gets pushed into a following block after the split,
         // which is visually bad.
         nsCOMPtr<nsIContent> brNode =
           htmlEditor->GetNextHTMLNode(parent, offset);
         if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
-          res = htmlEditor->DeleteNode(brNode);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = htmlEditor->DeleteNode(brNode);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
         // Do the splits!
         offset = htmlEditor->SplitNodeDeep(curBlock, *parent->AsContent(),
                                             offset,
                                             HTMLEditor::EmptyContainers::no);
         NS_ENSURE_STATE(offset != -1);
         // Put a br at the split point
         brNode = htmlEditor->CreateBR(curBlock->GetParentNode(), offset);
         NS_ENSURE_STATE(brNode);
         // Put selection at the split point
-        res = aSelection.Collapse(curBlock->GetParentNode(), offset);
+        *aHandled = true;
+        rv = aSelection.Collapse(curBlock->GetParentNode(), offset);
         // Don't restore the selection
         selectionRestorer.Abort();
-        *aHandled = true;
-        NS_ENSURE_SUCCESS(res, res);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       // Else nothing to do!
     } else {
       // We are making a block.  Consume a br, if needed.
       nsCOMPtr<nsIContent> brNode =
         htmlEditor->GetNextHTMLNode(parent, offset, true);
       if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
-        res = htmlEditor->DeleteNode(brNode);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->DeleteNode(brNode);
+        NS_ENSURE_SUCCESS(rv, rv);
         // We don't need to act on this node any more
         arrayOfNodes.RemoveElement(brNode);
       }
       // Make sure we can put a block here
-      res = SplitAsNeeded(blockType, parent, offset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = SplitAsNeeded(blockType, parent, offset);
+      NS_ENSURE_SUCCESS(rv, rv);
       nsCOMPtr<Element> block =
         htmlEditor->CreateNode(blockType, parent, offset);
       NS_ENSURE_STATE(block);
       // Remember our new block for postprocessing
       mNewBlock = block;
       // Delete anything that was in the list of nodes
       while (!arrayOfNodes.IsEmpty()) {
         OwningNonNull<nsINode> curNode = arrayOfNodes[0];
-        res = htmlEditor->DeleteNode(curNode);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->DeleteNode(curNode);
+        NS_ENSURE_SUCCESS(rv, rv);
         arrayOfNodes.RemoveElementAt(0);
       }
       // Put selection in new block
-      res = aSelection.Collapse(block, 0);
+      *aHandled = true;
+      rv = aSelection.Collapse(block, 0);
       // Don't restore the selection
       selectionRestorer.Abort();
-      *aHandled = true;
-      NS_ENSURE_SUCCESS(res, res);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     return NS_OK;
   }
   // Okay, now go through all the nodes and make the right kind of blocks, or
   // whatever is approriate.  Woohoo!  Note: blockquote is handled a little
   // differently.
   if (blockType == nsGkAtoms::blockquote) {
-    res = MakeBlockquote(arrayOfNodes);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = MakeBlockquote(arrayOfNodes);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else if (blockType == nsGkAtoms::normal ||
              blockType == nsGkAtoms::_empty) {
-    res = RemoveBlockStyle(arrayOfNodes);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = RemoveBlockStyle(arrayOfNodes);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
-    res = ApplyBlockStyle(arrayOfNodes, blockType);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = ApplyBlockStyle(arrayOfNodes, blockType);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::DidMakeBasicBlock(Selection* aSelection,
                                  RulesInfo* aInfo,
                                  nsresult aResult)
@@ -3449,122 +3493,128 @@ HTMLEditRules::DidMakeBasicBlock(Selecti
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // check for empty block.  if so, put a moz br in it.
   if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   NS_ENSURE_STATE(aSelection->GetRangeAt(0) &&
                   aSelection->GetRangeAt(0)->GetStartParent());
-  nsresult res =
+  nsresult rv =
     InsertMozBRIfNeeded(*aSelection->GetRangeAt(0)->GetStartParent());
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillIndent(Selection* aSelection,
                           bool* aCancel,
                           bool* aHandled)
 {
-  nsresult res;
   NS_ENSURE_STATE(mHTMLEditor);
   if (mHTMLEditor->IsCSSEnabled()) {
-    res = WillCSSIndent(aSelection, aCancel, aHandled);
-  }
-  else {
-    res = WillHTMLIndent(aSelection, aCancel, aHandled);
-  }
-  return res;
+    nsresult rv = WillCSSIndent(aSelection, aCancel, aHandled);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  } else {
+    nsresult rv = WillHTMLIndent(aSelection, aCancel, aHandled);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
+  return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillCSSIndent(Selection* aSelection,
                              bool* aCancel,
                              bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
 
   WillInsert(*aSelection, aCancel);
 
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
-  nsresult res = NormalizeSelection(aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(mHTMLEditor);
   AutoSelectionRestorer selectionRestorer(aSelection, mHTMLEditor);
   nsTArray<OwningNonNull<nsRange>> arrayOfRanges;
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
 
   // short circuit: detect case of collapsed selection inside an <li>.
   // just sublist that <li>.  This prevents bug 97797.
 
   nsCOMPtr<Element> liNode;
   if (aSelection->Collapsed()) {
     nsCOMPtr<nsINode> node;
     int32_t offset;
     NS_ENSURE_STATE(mHTMLEditor);
-    nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mHTMLEditor->GetStartNodeAndOffset(aSelection,
+                                         getter_AddRefs(node), &offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*node);
     if (block && HTMLEditUtils::IsListItem(block)) {
       liNode = block;
     }
   }
 
   if (liNode)
   {
     arrayOfNodes.AppendElement(*liNode);
   }
   else
   {
     // convert the selection ranges into "promoted" selection ranges:
     // this basically just expands the range to include the immediate
     // block parent, and then further expands to include any ancestors
     // whose children are all in the range
-    res = GetNodesFromSelection(*aSelection, EditAction::indent, arrayOfNodes);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetNodesFromSelection(*aSelection, EditAction::indent, arrayOfNodes);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // if nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes))
   {
     // get selection location
     NS_ENSURE_STATE(aSelection->RangeCount());
     nsCOMPtr<nsINode> parent = aSelection->GetRangeAt(0)->GetStartParent();
     int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
     NS_ENSURE_STATE(parent);
 
     // make sure we can put a block here
-    res = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theBlock = mHTMLEditor->CreateNode(nsGkAtoms::div,
                                                          parent, offset);
     NS_ENSURE_STATE(theBlock);
     // remember our new block for postprocessing
     mNewBlock = theBlock;
     ChangeIndentation(*theBlock, Change::plus);
     // delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteNode(curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       arrayOfNodes.RemoveElementAt(0);
     }
     // put selection in new block
-    res = aSelection->Collapse(theBlock,0);
+    *aHandled = true;
+    rv = aSelection->Collapse(theBlock, 0);
     // Don't restore the selection
     selectionRestorer.Abort();
-    *aHandled = true;
-    return res;
+    return rv;
   }
 
   // Ok, now go through all the nodes and put them in a blockquote,
   // or whatever is appropriate.  Wohoo!
   int32_t i;
   nsCOMPtr<nsINode> curParent;
   nsCOMPtr<Element> curList, curQuote;
   nsCOMPtr<nsIContent> sibling;
@@ -3590,164 +3640,164 @@ HTMLEditRules::WillCSSIndent(Selection* 
       // We do this if the next element is a list, and the list is of the
       // same type (li/ol) as curNode was a part it.
       NS_ENSURE_STATE(mHTMLEditor);
       sibling = mHTMLEditor->GetNextHTMLSibling(curNode);
       if (sibling && HTMLEditUtils::IsList(sibling)) {
         if (curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
             curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->MoveNode(curNode, sibling, 0);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mHTMLEditor->MoveNode(curNode, sibling, 0);
+          NS_ENSURE_SUCCESS(rv, rv);
           continue;
         }
       }
       // Check for whether we should join a list that preceeds curNode.
       // We do this if the previous element is a list, and the list is of
       // the same type (li/ol) as curNode was a part of.
       NS_ENSURE_STATE(mHTMLEditor);
       sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
       if (sibling && HTMLEditUtils::IsList(sibling)) {
         if (curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
             curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->MoveNode(curNode, sibling, -1);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mHTMLEditor->MoveNode(curNode, sibling, -1);
+          NS_ENSURE_SUCCESS(rv, rv);
           continue;
         }
       }
       sibling = nullptr;
 
       // check to see if curList is still appropriate.  Which it is if
       // curNode is still right after it in the same list.
       if (curList) {
         NS_ENSURE_STATE(mHTMLEditor);
         sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         // create a new nested list of correct type
-        res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
-                            offset);
-        NS_ENSURE_SUCCESS(res, res);
+        rv =
+          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_STATE(mHTMLEditor);
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                           curParent, offset);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in
         // remember our new block for postprocessing
         mNewBlock = curList;
       }
       // tuck the node into the end of the active list
       uint32_t listLen = curList->Length();
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->MoveNode(curNode, curList, listLen);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->MoveNode(curNode, curList, listLen);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     else // not a list item
     {
       if (curNode && IsBlockNode(*curNode)) {
         ChangeIndentation(*curNode->AsElement(), Change::plus);
         curQuote = nullptr;
       }
       else {
         if (!curQuote)
         {
           // First, check that our element can contain a div.
           if (!mTextEditor->CanContainTag(*curParent, *nsGkAtoms::div)) {
             return NS_OK; // cancelled
           }
 
-          res = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           NS_ENSURE_STATE(mHTMLEditor);
           curQuote = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent,
                                              offset);
           NS_ENSURE_STATE(curQuote);
           ChangeIndentation(*curQuote, Change::plus);
           // remember our new block for postprocessing
           mNewBlock = curQuote;
           // curQuote is now the correct thing to put curNode in
         }
 
         // tuck the node into the end of the active blockquote
         uint32_t quoteLen = curQuote->Length();
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, curQuote, quoteLen);
-        NS_ENSURE_SUCCESS(res, res);
-      }
-    }
-  }
-  return res;
+        rv = mHTMLEditor->MoveNode(curNode, curQuote, quoteLen);
+        NS_ENSURE_SUCCESS(rv, rv);
+      }
+    }
+  }
+  return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillHTMLIndent(Selection* aSelection,
                               bool* aCancel,
                               bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   WillInsert(*aSelection, aCancel);
 
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
-  nsresult res = NormalizeSelection(aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(mHTMLEditor);
   AutoSelectionRestorer selectionRestorer(aSelection, mHTMLEditor);
 
   // convert the selection ranges into "promoted" selection ranges:
   // this basically just expands the range to include the immediate
   // block parent, and then further expands to include any ancestors
   // whose children are all in the range
 
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
   GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::indent);
 
   // use these ranges to contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, EditAction::indent);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetNodesForOperation(arrayOfRanges, arrayOfNodes, EditAction::indent);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // if nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes))
   {
     // get selection location
     NS_ENSURE_STATE(aSelection->RangeCount());
     nsCOMPtr<nsINode> parent = aSelection->GetRangeAt(0)->GetStartParent();
     int32_t offset = aSelection->GetRangeAt(0)->StartOffset();
     NS_ENSURE_STATE(parent);
 
     // make sure we can put a block here
-    res = SplitAsNeeded(*nsGkAtoms::blockquote, parent, offset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = SplitAsNeeded(*nsGkAtoms::blockquote, parent, offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_STATE(mHTMLEditor);
     nsCOMPtr<Element> theBlock = mHTMLEditor->CreateNode(nsGkAtoms::blockquote,
                                                          parent, offset);
     NS_ENSURE_STATE(theBlock);
     // remember our new block for postprocessing
     mNewBlock = theBlock;
     // delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->DeleteNode(curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->DeleteNode(curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       arrayOfNodes.RemoveElementAt(0);
     }
     // put selection in new block
-    res = aSelection->Collapse(theBlock,0);
+    *aHandled = true;
+    rv = aSelection->Collapse(theBlock, 0);
     // Don't restore the selection
     selectionRestorer.Abort();
-    *aHandled = true;
-    return res;
+    return rv;
   }
 
   // Ok, now go through all the nodes and put them in a blockquote,
   // or whatever is appropriate.  Wohoo!
   int32_t i;
   nsCOMPtr<nsINode> curParent;
   nsCOMPtr<nsIContent> sibling;
   nsCOMPtr<Element> curList, curQuote, indentedLI;
@@ -3773,62 +3823,62 @@ HTMLEditRules::WillHTMLIndent(Selection*
       // We do this if the next element is a list, and the list is of the
       // same type (li/ol) as curNode was a part it.
       NS_ENSURE_STATE(mHTMLEditor);
       sibling = mHTMLEditor->GetNextHTMLSibling(curNode);
       if (sibling && HTMLEditUtils::IsList(sibling) &&
           curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
           curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, sibling, 0);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(curNode, sibling, 0);
+        NS_ENSURE_SUCCESS(rv, rv);
         continue;
       }
 
       // Check for whether we should join a list that preceeds curNode.
       // We do this if the previous element is a list, and the list is of
       // the same type (li/ol) as curNode was a part of.
       NS_ENSURE_STATE(mHTMLEditor);
       sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
       if (sibling && HTMLEditUtils::IsList(sibling) &&
           curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
           curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, sibling, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(curNode, sibling, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
         continue;
       }
 
       sibling = nullptr;
 
       // check to see if curList is still appropriate.  Which it is if
       // curNode is still right after it in the same list.
       if (curList) {
         NS_ENSURE_STATE(mHTMLEditor);
         sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList) )
       {
         // create a new nested list of correct type
-        res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
-                            offset);
-        NS_ENSURE_SUCCESS(res, res);
+        rv =
+          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_STATE(mHTMLEditor);
         curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                           curParent, offset);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in
         // remember our new block for postprocessing
         mNewBlock = curList;
       }
       // tuck the node into the end of the active list
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->MoveNode(curNode, curList, -1);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->MoveNode(curNode, curList, -1);
+      NS_ENSURE_SUCCESS(rv, rv);
       // forget curQuote, if any
       curQuote = nullptr;
     }
 
     else // not a list item, use blockquote?
     {
       // if we are inside a list item, we don't want to blockquote, we want
       // to sublist the list item.  We may have several nodes listed in the
@@ -3851,27 +3901,27 @@ HTMLEditRules::WillHTMLIndent(Selection*
           sibling = nullptr;
           NS_ENSURE_STATE(mHTMLEditor);
           sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
         }
 
         if (!curList || (sibling && sibling != curList) )
         {
           // create a new nested list of correct type
-          res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
-                              offset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
+                             offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           NS_ENSURE_STATE(mHTMLEditor);
           curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                             curParent, offset);
           NS_ENSURE_STATE(curList);
         }
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(listItem, curList, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(listItem, curList, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
         // remember we indented this li
         indentedLI = listItem;
       }
 
       else
       {
         // need to make a blockquote to put things in if we haven't already,
         // or if this node doesn't go in blockquote we used earlier.
@@ -3883,68 +3933,67 @@ HTMLEditRules::WillHTMLIndent(Selection*
 
         if (!curQuote)
         {
           // First, check that our element can contain a blockquote.
           if (!mTextEditor->CanContainTag(*curParent, *nsGkAtoms::blockquote)) {
             return NS_OK; // cancelled
           }
 
-          res = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           NS_ENSURE_STATE(mHTMLEditor);
           curQuote = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent,
                                              offset);
           NS_ENSURE_STATE(curQuote);
           // remember our new block for postprocessing
           mNewBlock = curQuote;
           // curQuote is now the correct thing to put curNode in
         }
 
         // tuck the node into the end of the active blockquote
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->MoveNode(curNode, curQuote, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->MoveNode(curNode, curQuote, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
         // forget curList, if any
         curList = nullptr;
       }
     }
   }
-  return res;
+  return NS_OK;
 }
 
 
 nsresult
 HTMLEditRules::WillOutdent(Selection& aSelection,
                            bool* aCancel,
                            bool* aHandled)
 {
   MOZ_ASSERT(aCancel && aHandled);
   *aCancel = false;
   *aHandled = true;
   nsCOMPtr<nsIContent> rememberedLeftBQ, rememberedRightBQ;
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
   bool useCSS = htmlEditor->IsCSSEnabled();
 
-  nsresult res = NormalizeSelection(&aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(&aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Some scoping for selection resetting - we may need to tweak it
   {
     AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
 
     // Convert the selection ranges into "promoted" selection ranges: this
     // basically just expands the range to include the immediate block parent,
     // and then further expands to include any ancestors whose children are all
     // in the range
     nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-    res = GetNodesFromSelection(aSelection, EditAction::outdent,
-                                arrayOfNodes);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetNodesFromSelection(aSelection, EditAction::outdent, arrayOfNodes);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // Okay, now go through all the nodes and remove a level of blockquoting,
     // or whatever is appropriate.  Wohoo!
 
     nsCOMPtr<Element> curBlockQuote;
     nsCOMPtr<nsIContent> firstBQChild, lastBQChild;
     bool curBlockQuoteIsIndentedWithCSS = false;
     for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) {
@@ -3957,28 +4006,28 @@ HTMLEditRules::WillOutdent(Selection& aS
       nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
       int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
 
       // Is it a blockquote?
       if (curNode->IsHTMLElement(nsGkAtoms::blockquote)) {
         // If it is a blockquote, remove it.  So we need to finish up dealng
         // with any curBlockQuote first.
         if (curBlockQuote) {
-          res = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
-                                   curBlockQuoteIsIndentedWithCSS,
-                                   getter_AddRefs(rememberedLeftBQ),
-                                   getter_AddRefs(rememberedRightBQ));
-          NS_ENSURE_SUCCESS(res, res);
+          rv = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
+                                  curBlockQuoteIsIndentedWithCSS,
+                                  getter_AddRefs(rememberedLeftBQ),
+                                  getter_AddRefs(rememberedRightBQ));
+          NS_ENSURE_SUCCESS(rv, rv);
           curBlockQuote = nullptr;
           firstBQChild = nullptr;
           lastBQChild = nullptr;
           curBlockQuoteIsIndentedWithCSS = false;
         }
-        res = htmlEditor->RemoveBlockContainer(curNode);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->RemoveBlockContainer(curNode);
+        NS_ENSURE_SUCCESS(rv, rv);
         continue;
       }
       // Is it a block with a 'margin' property?
       if (useCSS && IsBlockNode(curNode)) {
         nsIAtom& marginProperty =
           MarginPropertyAtomForIndent(*htmlEditor->mCSSEditUtils, curNode);
         nsAutoString value;
         htmlEditor->mCSSEditUtils->GetSpecifiedProperty(curNode,
@@ -3995,48 +4044,47 @@ HTMLEditRules::WillOutdent(Selection& aS
         }
       }
       // Is it a list item?
       if (HTMLEditUtils::IsListItem(curNode)) {
         // If it is a list item, that means we are not outdenting whole list.
         // So we need to finish up dealing with any curBlockQuote, and then pop
         // this list item.
         if (curBlockQuote) {
-          res = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
-                                   curBlockQuoteIsIndentedWithCSS,
-                                   getter_AddRefs(rememberedLeftBQ),
-                                   getter_AddRefs(rememberedRightBQ));
-          NS_ENSURE_SUCCESS(res, res);
+          rv = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
+                                  curBlockQuoteIsIndentedWithCSS,
+                                  getter_AddRefs(rememberedLeftBQ),
+                                  getter_AddRefs(rememberedRightBQ));
+          NS_ENSURE_SUCCESS(rv, rv);
           curBlockQuote = nullptr;
           firstBQChild = nullptr;
           lastBQChild = nullptr;
           curBlockQuoteIsIndentedWithCSS = false;
         }
         bool unused;
-        res = PopListItem(GetAsDOMNode(curNode), &unused);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = PopListItem(GetAsDOMNode(curNode), &unused);
+        NS_ENSURE_SUCCESS(rv, rv);
         continue;
       }
       // Do we have a blockquote that we are already committed to removing?
       if (curBlockQuote) {
         // If so, is this node a descendant?
         if (EditorUtils::IsDescendantOf(curNode, curBlockQuote)) {
           lastBQChild = curNode;
           // Then we don't need to do anything different for this node
           continue;
         } else {
           // Otherwise, we have progressed beyond end of curBlockQuote, so
           // let's handle it now.  We need to remove the portion of
           // curBlockQuote that contains [firstBQChild - lastBQChild].
-          res = OutdentPartOfBlock(*curBlockQuote, *firstBQChild,
-                                   *lastBQChild,
-                                   curBlockQuoteIsIndentedWithCSS,
-                                   getter_AddRefs(rememberedLeftBQ),
-                                   getter_AddRefs(rememberedRightBQ));
-          NS_ENSURE_SUCCESS(res, res);
+          rv = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
+                                  curBlockQuoteIsIndentedWithCSS,
+                                  getter_AddRefs(rememberedLeftBQ),
+                                  getter_AddRefs(rememberedRightBQ));
+          NS_ENSURE_SUCCESS(rv, rv);
           curBlockQuote = nullptr;
           firstBQChild = nullptr;
           lastBQChild = nullptr;
           curBlockQuoteIsIndentedWithCSS = false;
           // Fall out and handle curNode
         }
       }
 
@@ -4080,66 +4128,66 @@ HTMLEditRules::WillOutdent(Selection& aS
       }
 
       if (!curBlockQuote) {
         // Couldn't find enclosing blockquote.  Handle list cases.
         if (HTMLEditUtils::IsList(curParent)) {
           // Move node out of list
           if (HTMLEditUtils::IsList(curNode)) {
             // Just unwrap this sublist
-            res = htmlEditor->RemoveBlockContainer(curNode);
-            NS_ENSURE_SUCCESS(res, res);
+            rv = htmlEditor->RemoveBlockContainer(curNode);
+            NS_ENSURE_SUCCESS(rv, rv);
           }
           // handled list item case above
         } else if (HTMLEditUtils::IsList(curNode)) {
           // node is a list, but parent is non-list: move list items out
           nsCOMPtr<nsIContent> child = curNode->GetLastChild();
           while (child) {
             if (HTMLEditUtils::IsListItem(child)) {
               bool unused;
-              res = PopListItem(GetAsDOMNode(child), &unused);
-              NS_ENSURE_SUCCESS(res, res);
+              rv = PopListItem(GetAsDOMNode(child), &unused);
+              NS_ENSURE_SUCCESS(rv, rv);
             } else if (HTMLEditUtils::IsList(child)) {
               // We have an embedded list, so move it out from under the parent
               // list. Be sure to put it after the parent list because this
               // loop iterates backwards through the parent's list of children.
 
-              res = htmlEditor->MoveNode(child, curParent, offset + 1);
-              NS_ENSURE_SUCCESS(res, res);
+              rv = htmlEditor->MoveNode(child, curParent, offset + 1);
+              NS_ENSURE_SUCCESS(rv, rv);
             } else {
               // Delete any non-list items for now
-              res = htmlEditor->DeleteNode(child);
-              NS_ENSURE_SUCCESS(res, res);
+              rv = htmlEditor->DeleteNode(child);
+              NS_ENSURE_SUCCESS(rv, rv);
             }
             child = curNode->GetLastChild();
           }
           // Delete the now-empty list
-          res = htmlEditor->RemoveBlockContainer(curNode);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = htmlEditor->RemoveBlockContainer(curNode);
+          NS_ENSURE_SUCCESS(rv, rv);
         } else if (useCSS) {
           nsCOMPtr<Element> element;
           if (curNode->GetAsText()) {
             // We want to outdent the parent of text nodes
             element = curNode->GetParentElement();
           } else if (curNode->IsElement()) {
             element = curNode->AsElement();
           }
           if (element) {
             ChangeIndentation(*element, Change::minus);
           }
         }
       }
     }
     if (curBlockQuote) {
       // We have a blockquote we haven't finished handling
-      res = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
-                               curBlockQuoteIsIndentedWithCSS,
-                               getter_AddRefs(rememberedLeftBQ),
-                               getter_AddRefs(rememberedRightBQ));
-      NS_ENSURE_SUCCESS(res, res);
+      rv = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
+                              curBlockQuoteIsIndentedWithCSS,
+                              getter_AddRefs(rememberedLeftBQ),
+                              getter_AddRefs(rememberedRightBQ));
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   // Make sure selection didn't stick to last piece of content in old bq (only
   // a problem for collapsed selections)
   if (rememberedLeftBQ || rememberedRightBQ) {
     if (aSelection.Collapsed()) {
       // Push selection past end of rememberedLeftBQ
       NS_ENSURE_TRUE(aSelection.GetRangeAt(0), NS_OK);
@@ -4179,18 +4227,18 @@ nsresult
 HTMLEditRules::RemovePartOfBlock(Element& aBlock,
                                  nsIContent& aStartChild,
                                  nsIContent& aEndChild)
 {
   SplitBlock(aBlock, aStartChild, aEndChild);
   // Get rid of part of blockquote we are outdenting
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->RemoveBlockContainer(aBlock);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mHTMLEditor->RemoveBlockContainer(aBlock);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 void
 HTMLEditRules::SplitBlock(Element& aBlock,
                           nsIContent& aStartChild,
                           nsIContent& aEndChild,
@@ -4247,23 +4295,22 @@ HTMLEditRules::OutdentPartOfBlock(Elemen
   nsCOMPtr<nsIContent> middleNode;
   SplitBlock(aBlock, aStartChild, aEndChild, aOutLeftNode, aOutRightNode,
              getter_AddRefs(middleNode));
 
   NS_ENSURE_STATE(middleNode);
 
   if (!aIsBlockIndentedWithCSS) {
     NS_ENSURE_STATE(mHTMLEditor);
-    nsresult res =
-      mHTMLEditor->RemoveBlockContainer(*middleNode);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = mHTMLEditor->RemoveBlockContainer(*middleNode);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else if (middleNode->IsElement()) {
     // We do nothing if middleNode isn't an element
-    nsresult res = ChangeIndentation(*middleNode->AsElement(), Change::minus);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = ChangeIndentation(*middleNode->AsElement(), Change::minus);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 /**
  * ConvertListType() converts list type and list item type.
  */
@@ -4317,17 +4364,16 @@ HTMLEditRules::ConvertListType(Element* 
  * style nodes for text insertion.
  */
 nsresult
 HTMLEditRules::CreateStyleForInsertText(Selection& aSelection,
                                         nsIDocument& aDoc)
 {
   MOZ_ASSERT(mHTMLEditor->mTypeInState);
 
-  nsresult res;
   bool weDidSomething = false;
   NS_ENSURE_STATE(aSelection.GetRangeAt(0));
   nsCOMPtr<nsINode> node = aSelection.GetRangeAt(0)->GetStartParent();
   int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
   // next examine our present style and make sure default styles are either
   // present or explicitly overridden.  If neither, add the default style to
   // the TypeInState
@@ -4342,38 +4388,40 @@ HTMLEditRules::CreateStyleForInsertText(
     // assuming that's not a problem: that default styles will always be
     // multivalue styles (like font face or size) where clearing the style
     // means we want to go back to the default.  If we ever wanted a "toggle"
     // style like bold for a default, though, I'll have to add code to detect
     // the difference between unset and explicitly cleared, else user would
     // never be able to unbold, for instance.
     nsAutoString curValue;
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->GetInlinePropertyBase(*propItem->tag, &propItem->attr,
-                                             nullptr, &bFirst, &bAny, &bAll,
-                                             &curValue, false);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mHTMLEditor->GetInlinePropertyBase(*propItem->tag, &propItem->attr,
+                                         nullptr, &bFirst, &bAny, &bAll,
+                                         &curValue, false);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (!bAny) {
       // no style set for this prop/attr
       mHTMLEditor->mTypeInState->SetProp(propItem->tag, propItem->attr,
                                          propItem->value);
     }
   }
 
   nsCOMPtr<Element> rootElement = aDoc.GetRootElement();
   NS_ENSURE_STATE(rootElement);
 
   // process clearing any styles first
   nsAutoPtr<PropItem> item(mHTMLEditor->mTypeInState->TakeClearProperty());
   while (item && node != rootElement) {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->ClearStyle(address_of(node), &offset,
-                                  item->tag, &item->attr);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mHTMLEditor->ClearStyle(address_of(node), &offset,
+                              item->tag, &item->attr);
+    NS_ENSURE_SUCCESS(rv, rv);
     item = mHTMLEditor->mTypeInState->TakeClearProperty();
     weDidSomething = true;
   }
 
   // then process setting any styles
   int32_t relFontSize = mHTMLEditor->mTypeInState->TakeRelativeFontSize();
   item = mHTMLEditor->mTypeInState->TakeSetProperty();
 
@@ -4387,39 +4435,39 @@ HTMLEditRules::CreateStyleForInsertText(
       NS_ENSURE_STATE(offset != -1);
       node = node->GetParentNode();
     }
     if (!mHTMLEditor->IsContainer(node)) {
       return NS_OK;
     }
     OwningNonNull<Text> newNode = aDoc.CreateTextNode(EmptyString());
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->InsertNode(*newNode, *node, offset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = mHTMLEditor->InsertNode(*newNode, *node, offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     node = newNode;
     offset = 0;
     weDidSomething = true;
 
     if (relFontSize) {
       // dir indicated bigger versus smaller.  1 = bigger, -1 = smaller
       HTMLEditor::FontSize dir = relFontSize > 0 ?
         HTMLEditor::FontSize::incr : HTMLEditor::FontSize::decr;
       for (int32_t j = 0; j < DeprecatedAbs(relFontSize); j++) {
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->RelativeFontChangeOnTextNode(dir, newNode, 0, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->RelativeFontChangeOnTextNode(dir, newNode, 0, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
 
     while (item) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->SetInlinePropertyOnNode(*node->AsContent(),
-                                                 *item->tag, &item->attr,
-                                                 item->value);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->SetInlinePropertyOnNode(*node->AsContent(),
+                                                *item->tag, &item->attr,
+                                                item->value);
+      NS_ENSURE_SUCCESS(rv, rv);
       item = mHTMLEditor->mTypeInState->TakeSetProperty();
     }
   }
   if (weDidSomething) {
     return aSelection.Collapse(node, offset);
   }
 
   return NS_OK;
@@ -4671,34 +4719,33 @@ HTMLEditRules::AlignInnerBlocks(nsINode&
   // Gather list of table cells or list items
   nsTArray<OwningNonNull<nsINode>> nodeArray;
   TableCellAndListItemFunctor functor;
   DOMIterator iter(aNode);
   iter.AppendList(functor, nodeArray);
 
   // Now that we have the list, align their contents as requested
   for (auto& node : nodeArray) {
-    nsresult res = AlignBlockContents(GetAsDOMNode(node), alignType);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = AlignBlockContents(GetAsDOMNode(node), alignType);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 
 /**
  * AlignBlockContents() aligns contents of a block element.
  */
 nsresult
 HTMLEditRules::AlignBlockContents(nsIDOMNode* aNode,
                                   const nsAString* alignType)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   NS_ENSURE_TRUE(node && alignType, NS_ERROR_NULL_POINTER);
-  nsresult res = NS_OK;
   nsCOMPtr<nsIContent> firstChild, lastChild;
   nsCOMPtr<Element> divNode;
 
   bool useCSS = mHTMLEditor->IsCSSEnabled();
 
   NS_ENSURE_STATE(mHTMLEditor);
   firstChild = mHTMLEditor->GetFirstEditableChild(*node);
   NS_ENSURE_STATE(mHTMLEditor);
@@ -4709,52 +4756,64 @@ HTMLEditRules::AlignBlockContents(nsIDOM
     // this cell has no content, nothing to align
   } else if (firstChild == lastChild &&
              firstChild->IsHTMLElement(nsGkAtoms::div)) {
     // the cell already has a div containing all of its content: just
     // act on this div.
     nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(firstChild);
     if (useCSS) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false);
+      nsresult rv = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr,
+                                                          *alignType, false);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
     else {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->SetAttribute(divElem, attr, *alignType);
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = mHTMLEditor->SetAttribute(divElem, attr, *alignType);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
   }
   else
   {
     // else we need to put in a div, set the alignment, and toss in all the children
     NS_ENSURE_STATE(mHTMLEditor);
     divNode = mHTMLEditor->CreateNode(nsGkAtoms::div, node, 0);
     NS_ENSURE_STATE(divNode);
     // set up the alignment on the div
     nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(divNode);
     if (useCSS) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false);
+      nsresult rv =
+        mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
     else {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->SetAttribute(divElem, attr, *alignType);
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = mHTMLEditor->SetAttribute(divElem, attr, *alignType);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
     // tuck the children into the end of the active div
     while (lastChild && (lastChild != divNode))
     {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->MoveNode(lastChild, divNode, 0);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = mHTMLEditor->MoveNode(lastChild, divNode, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
       lastChild = mHTMLEditor->GetLastEditableChild(*node);
     }
   }
-  return res;
+  return NS_OK;
 }
 
 /**
  * CheckForEmptyBlock() is called by WillDeleteSelection() to detect and handle
  * case of deleting from inside an empty block.
  */
 nsresult
 HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
@@ -4770,95 +4829,94 @@ HTMLEditRules::CheckForEmptyBlock(nsINod
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // If we are inside an empty block, delete it.  Note: do NOT delete table
   // elements this way.
   nsCOMPtr<Element> block = htmlEditor->GetBlock(*aStartNode);
   bool bIsEmptyNode;
   nsCOMPtr<Element> emptyBlock;
-  nsresult res;
   if (block && block != aBodyNode) {
     // Efficiency hack, avoiding IsEmptyNode() call when in body
-    res = htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
+    NS_ENSURE_SUCCESS(rv, rv);
     while (block && bIsEmptyNode && !HTMLEditUtils::IsTableElement(block) &&
            block != aBodyNode) {
       emptyBlock = block;
       block = htmlEditor->GetBlockNodeParent(emptyBlock);
       if (block) {
-        res = htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
 
   if (emptyBlock && emptyBlock->IsEditable()) {
     nsCOMPtr<nsINode> blockParent = emptyBlock->GetParentNode();
     NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
     int32_t offset = blockParent->IndexOf(emptyBlock);
 
     if (HTMLEditUtils::IsListItem(emptyBlock)) {
       // Are we the first list item in the list?
       bool bIsFirst;
       NS_ENSURE_STATE(htmlEditor);
-      res = htmlEditor->IsFirstEditableChild(GetAsDOMNode(emptyBlock),
-                                             &bIsFirst);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        htmlEditor->IsFirstEditableChild(GetAsDOMNode(emptyBlock), &bIsFirst);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (bIsFirst) {
         nsCOMPtr<nsINode> listParent = blockParent->GetParentNode();
         NS_ENSURE_TRUE(listParent, NS_ERROR_FAILURE);
         int32_t listOffset = listParent->IndexOf(blockParent);
         // If we are a sublist, skip the br creation
         if (!HTMLEditUtils::IsList(listParent)) {
           // Create a br before list
           NS_ENSURE_STATE(htmlEditor);
           nsCOMPtr<Element> br =
             htmlEditor->CreateBR(listParent, listOffset);
           NS_ENSURE_STATE(br);
           // Adjust selection to be right before it
-          res = aSelection->Collapse(listParent, listOffset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = aSelection->Collapse(listParent, listOffset);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
         // Else just let selection percolate up.  We'll adjust it in
         // AfterEdit()
       }
     } else {
       if (aAction == nsIEditor::eNext) {
         // Move to the start of the next node, if any
         nsCOMPtr<nsIContent> nextNode = htmlEditor->GetNextNode(blockParent,
                                                                 offset + 1, true);
         if (nextNode) {
           EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
-          res = aSelection->Collapse(pt.node, pt.offset);
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = aSelection->Collapse(pt.node, pt.offset);
+          NS_ENSURE_SUCCESS(rv, rv);
         } else {
           // Adjust selection to be right after it.
-          res = aSelection->Collapse(blockParent, offset + 1);
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = aSelection->Collapse(blockParent, offset + 1);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
       } else {
         // Move to the end of the previous node
         nsCOMPtr<nsIContent> priorNode = htmlEditor->GetPriorNode(blockParent,
                                                                   offset,
                                                                   true);
         if (priorNode) {
           EditorDOMPoint pt = GetGoodSelPointForNode(*priorNode, aAction);
-          res = aSelection->Collapse(pt.node, pt.offset);
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = aSelection->Collapse(pt.node, pt.offset);
+          NS_ENSURE_SUCCESS(rv, rv);
         } else {
-          res = aSelection->Collapse(blockParent, offset + 1);
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = aSelection->Collapse(blockParent, offset + 1);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
       }
     }
     NS_ENSURE_STATE(htmlEditor);
-    res = htmlEditor->DeleteNode(emptyBlock);
     *aHandled = true;
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = htmlEditor->DeleteNode(emptyBlock);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 Element*
 HTMLEditRules::CheckForInvisibleBR(Element& aBlock,
                                    BRLocation aWhere,
                                    int32_t aOffset)
@@ -5017,47 +5075,46 @@ HTMLEditRules::ExpandSelectionForDeletio
       }
     }
   }
   // Now set the selection to the new range
   aSelection.Collapse(selStartNode, selStartOffset);
 
   // Expand selection endpoint only if we didn't pass a br, or if we really
   // needed to pass that br (i.e., its block is now totally selected)
-  nsresult res;
   bool doEndExpansion = true;
   if (firstBRParent) {
     // Find block node containing br
     nsCOMPtr<Element> brBlock = HTMLEditor::GetBlock(*firstBRParent);
     bool nodeBefore = false, nodeAfter = false;
 
     // Create a range that represents expanded selection
     RefPtr<nsRange> range = new nsRange(selStartNode);
-    res = range->SetStart(selStartNode, selStartOffset);
-    NS_ENSURE_SUCCESS(res, res);
-    res = range->SetEnd(selEndNode, selEndOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = range->SetStart(selStartNode, selStartOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = range->SetEnd(selEndNode, selEndOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // Check if block is entirely inside range
     if (brBlock) {
       nsRange::CompareNodeToRange(brBlock, range, &nodeBefore, &nodeAfter);
     }
 
     // If block isn't contained, forgo grabbing the br in expanded selection
     if (nodeBefore || nodeAfter) {
       doEndExpansion = false;
     }
   }
   if (doEndExpansion) {
-    res = aSelection.Extend(selEndNode, selEndOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = aSelection.Extend(selEndNode, selEndOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     // Only expand to just before br
-    res = aSelection.Extend(firstBRParent, firstBROffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = aSelection.Extend(firstBRParent, firstBROffset);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 /**
  * NormalizeSelection() tweaks non-collapsed selections to be more "natural".
  * Idea here is to adjust selection endpoint so that they do not cross breaks
@@ -5071,37 +5128,37 @@ HTMLEditRules::NormalizeSelection(Select
   NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
 
   // don't need to touch collapsed selections
   if (inSelection->Collapsed()) {
     return NS_OK;
   }
 
   int32_t rangeCount;
-  nsresult res = inSelection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = inSelection->GetRangeCount(&rangeCount);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // we don't need to mess with cell selections, and we assume multirange selections are those.
   if (rangeCount != 1) return NS_OK;
 
   RefPtr<nsRange> range = inSelection->GetRangeAt(0);
   NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> startNode, endNode;
   int32_t startOffset, endOffset;
   nsCOMPtr<nsIDOMNode> newStartNode, newEndNode;
   int32_t newStartOffset, newEndOffset;
 
-  res = range->GetStartContainer(getter_AddRefs(startNode));
-  NS_ENSURE_SUCCESS(res, res);
-  res = range->GetStartOffset(&startOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = range->GetEndContainer(getter_AddRefs(endNode));
-  NS_ENSURE_SUCCESS(res, res);
-  res = range->GetEndOffset(&endOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = range->GetStartContainer(getter_AddRefs(startNode));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = range->GetStartOffset(&startOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = range->GetEndContainer(getter_AddRefs(endNode));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = range->GetEndOffset(&endOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // adjusted values default to original values
   newStartNode = startNode;
   newStartOffset = startOffset;
   newEndNode = endNode;
   newEndOffset = endOffset;
 
   // some locals we need for whitespace code
@@ -5129,17 +5186,17 @@ HTMLEditRules::NormalizeSelection(Select
         newEndNode = EditorBase::GetNodeLocation(child, &newEndOffset);
         ++newEndOffset; // offset *after* child
       }
       // else block is empty - we can leave selection alone here, i think.
     } else if (wsEndObj.mStartReason == WSType::thisBlock) {
       // endpoint is just after start of this block
       nsCOMPtr<nsIDOMNode> child;
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetPriorHTMLNode(endNode, endOffset, address_of(child));
+      mHTMLEditor->GetPriorHTMLNode(endNode, endOffset, address_of(child));
       if (child)
       {
         newEndNode = EditorBase::GetNodeLocation(child, &newEndOffset);
         ++newEndOffset; // offset *after* child
       }
       // else block is empty - we can leave selection alone here, i think.
     } else if (wsEndObj.mStartReason == WSType::br) {
       // endpoint is just after break.  lets adjust it to before it.
@@ -5169,17 +5226,17 @@ HTMLEditRules::NormalizeSelection(Select
       {
         newStartNode = EditorBase::GetNodeLocation(child, &newStartOffset);
       }
       // else block is empty - we can leave selection alone here, i think.
     } else if (wsStartObj.mEndReason == WSType::thisBlock) {
       // startpoint is just before end of this block
       nsCOMPtr<nsIDOMNode> child;
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetNextHTMLNode(startNode, startOffset, address_of(child));
+      mHTMLEditor->GetNextHTMLNode(startNode, startOffset, address_of(child));
       if (child)
       {
         newStartNode = EditorBase::GetNodeLocation(child, &newStartOffset);
       }
       // else block is empty - we can leave selection alone here, i think.
     } else if (wsStartObj.mEndReason == WSType::br) {
       // startpoint is just before a break.  lets adjust it to after it.
       newStartNode =
@@ -5506,20 +5563,20 @@ HTMLEditRules::PromoteRange(nsRange& aRa
   // Make sure that the new range ends up to be in the editable section.
   if (!htmlEditor->IsDescendantOfEditorRoot(
         EditorBase::GetNodeAtRangeOffsetPoint(opStartNode, opStartOffset)) ||
       !htmlEditor->IsDescendantOfEditorRoot(
         EditorBase::GetNodeAtRangeOffsetPoint(opEndNode, opEndOffset - 1))) {
     return;
   }
 
-  DebugOnly<nsresult> res = aRange.SetStart(opStartNode, opStartOffset);
-  MOZ_ASSERT(NS_SUCCEEDED(res));
-  res = aRange.SetEnd(opEndNode, opEndOffset);
-  MOZ_ASSERT(NS_SUCCEEDED(res));
+  DebugOnly<nsresult> rv = aRange.SetStart(opStartNode, opStartOffset);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
+  rv = aRange.SetEnd(opEndNode, opEndOffset);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
 }
 
 class UniqueFunctor final : public BoolDomIterFunctor
 {
 public:
   explicit UniqueFunctor(nsTArray<OwningNonNull<nsINode>>& aArray)
     : mArray(aArray)
   {
@@ -5545,18 +5602,16 @@ HTMLEditRules::GetNodesForOperation(
                  nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
                  EditAction aOperationType,
                  TouchContent aTouchContent)
 {
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   int32_t rangeCount = aArrayOfRanges.Length();
-  nsresult res = NS_OK;
-
   if (aTouchContent == TouchContent::yes) {
     // Split text nodes. This is necessary, since GetPromotedPoint() may return a
     // range ending in a text node in case where part of a pre-formatted
     // elements needs to be moved.
     for (int32_t i = 0; i < rangeCount; i++) {
       RefPtr<nsRange> r = aArrayOfRanges[i];
       nsCOMPtr<nsIContent> endParent = do_QueryInterface(r->GetEndParent());
       if (!htmlEditor->IsTextNode(endParent)) {
@@ -5566,19 +5621,19 @@ HTMLEditRules::GetNodesForOperation(
       if (textNode) {
         int32_t offset = r->EndOffset();
         nsAutoString tempString;
         textNode->GetData(tempString);
 
         if (0 < offset && offset < (int32_t)(tempString.Length())) {
           // Split the text node.
           nsCOMPtr<nsIDOMNode> tempNode;
-          res = htmlEditor->SplitNode(endParent->AsDOMNode(), offset,
-                                      getter_AddRefs(tempNode));
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = htmlEditor->SplitNode(endParent->AsDOMNode(), offset,
+                                              getter_AddRefs(tempNode));
+          NS_ENSURE_SUCCESS(rv, rv);
 
           // Correct the range.
           // The new end parent becomes the parent node of the text.
           nsCOMPtr<nsIContent> newParent = endParent->GetParent();
           r->SetEnd(newParent, newParent->IndexOf(endParent));
         }
       }
     }
@@ -5594,34 +5649,35 @@ HTMLEditRules::GetNodesForOperation(
     // First register ranges for special editor gravity
     for (int32_t i = 0; i < rangeCount; i++) {
       rangeItemArray[i] = new RangeItem();
       rangeItemArray[i]->StoreRange(aArrayOfRanges[0]);
       htmlEditor->mRangeUpdater.RegisterRangeItem(rangeItemArray[i]);
       aArrayOfRanges.RemoveElementAt(0);
     }
     // Now bust up inlines.
+    nsresult rv = NS_OK;
     for (auto& item : Reversed(rangeItemArray)) {
-      res = BustUpInlinesAtRangeEndpoints(*item);
-      if (NS_FAILED(res)) {
+      rv = BustUpInlinesAtRangeEndpoints(*item);
+      if (NS_FAILED(rv)) {
         break;
       }
     }
     // Then unregister the ranges
     for (auto& item : rangeItemArray) {
       htmlEditor->mRangeUpdater.DropRangeItem(item);
       aArrayOfRanges.AppendElement(item->GetRange());
     }
-    NS_ENSURE_SUCCESS(res, res);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   // Gather up a list of all the nodes
   for (auto& range : aArrayOfRanges) {
     DOMSubtreeIterator iter;
-    res = iter.Init(*range);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = iter.Init(*range);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (aOutArrayOfNodes.Length() == 0) {
       iter.AppendList(TrivialFunctor(), aOutArrayOfNodes);
     } else {
       // We don't want duplicates in aOutArrayOfNodes, so we use an
       // iterator/functor that only return nodes that are not already in
       // aOutArrayOfNodes.
       nsTArray<OwningNonNull<nsINode>> nodes;
       iter.AppendList(UniqueFunctor(aOutArrayOfNodes), nodes);
@@ -5676,18 +5732,18 @@ HTMLEditRules::GetNodesForOperation(
       aOperationType == EditAction::setAbsolutePosition ||
       aOperationType == EditAction::indent ||
       aOperationType == EditAction::outdent) {
     for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
       OwningNonNull<nsINode> node = aOutArrayOfNodes[i];
       if (aTouchContent == TouchContent::yes && IsInlineNode(node) &&
           htmlEditor->IsContainer(node) && !htmlEditor->IsTextNode(node)) {
         nsTArray<OwningNonNull<nsINode>> arrayOfInlines;
-        res = BustUpInlinesAtBRs(*node->AsContent(), arrayOfInlines);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = BustUpInlinesAtBRs(*node->AsContent(), arrayOfInlines);
+        NS_ENSURE_SUCCESS(rv, rv);
 
         // Put these nodes in aOutArrayOfNodes, replacing the current node
         aOutArrayOfNodes.RemoveElementAt(i);
         aOutArrayOfNodes.InsertElementsAt(i, arrayOfInlines);
       }
     }
   }
   return NS_OK;
@@ -5737,19 +5793,19 @@ HTMLEditRules::GetListActionNodes(
     }
   }
 
   {
     // We don't like other people messing with our selection!
     AutoTransactionsConserveSelection dontSpazMySelection(htmlEditor);
 
     // contruct a list of nodes to act on.
-    nsresult res = GetNodesFromSelection(*selection, EditAction::makeList,
-                                         aOutArrayOfNodes, aTouchContent);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = GetNodesFromSelection(*selection, EditAction::makeList,
+                                        aOutArrayOfNodes, aTouchContent);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Pre-process our list of nodes
   for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
     OwningNonNull<nsINode> testNode = aOutArrayOfNodes[i];
 
     // Remove all non-editable nodes.  Leave them be.
     if (!htmlEditor->IsEditable(testNode)) {
@@ -5852,19 +5908,19 @@ HTMLEditRules::GetParagraphFormatNodes(
 {
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   RefPtr<Selection> selection = htmlEditor->GetSelection();
   NS_ENSURE_STATE(selection);
 
   // Contruct a list of nodes to act on.
-  nsresult res = GetNodesFromSelection(*selection, EditAction::makeBasicBlock,
-                                       outArrayOfNodes, aTouchContent);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetNodesFromSelection(*selection, EditAction::makeBasicBlock,
+                                      outArrayOfNodes, aTouchContent);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Pre-process our list of nodes
   for (int32_t i = outArrayOfNodes.Length() - 1; i >= 0; i--) {
     OwningNonNull<nsINode> testNode = outArrayOfNodes[i];
 
     // Remove all non-editable nodes.  Leave them be.
     if (!htmlEditor->IsEditable(testNode)) {
       outArrayOfNodes.RemoveElementAt(i);
@@ -5969,19 +6025,19 @@ HTMLEditRules::BustUpInlinesAtBRs(
     // Put left node in node list
     if (leftNode) {
       // Might not be a left node.  A break might have been at the very
       // beginning of inline container, in which case SplitNodeDeep would not
       // actually split anything
       aOutArrayOfNodes.AppendElement(*leftNode);
     }
     // Move break outside of container and also put in node list
-    nsresult res = htmlEditor->MoveNode(breakNode, inlineParentNode,
-                                        resultOffset);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      htmlEditor->MoveNode(breakNode, inlineParentNode, resultOffset);
+    NS_ENSURE_SUCCESS(rv, rv);
     aOutArrayOfNodes.AppendElement(*breakNode);
 
     // Now rightNode becomes the new node to split
     splitDeepNode = rightNode;
   }
   // Now tack on remaining rightNode, if any, to the list
   if (rightNode) {
     aOutArrayOfNodes.AppendElement(*rightNode);
@@ -6011,32 +6067,32 @@ nsresult
 HTMLEditRules::GetNodesFromPoint(
                  EditorDOMPoint aPoint,
                  EditAction aOperation,
                  nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
                  TouchContent aTouchContent)
 {
   NS_ENSURE_STATE(aPoint.node);
   RefPtr<nsRange> range = new nsRange(aPoint.node);
-  nsresult res = range->SetStart(aPoint.node, aPoint.offset);
-  MOZ_ASSERT(NS_SUCCEEDED(res));
+  nsresult rv = range->SetStart(aPoint.node, aPoint.offset);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   // Expand the range to include adjacent inlines
   PromoteRange(*range, aOperation);
 
   // Make array of ranges
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
 
   // Stuff new opRange into array
   arrayOfRanges.AppendElement(range);
 
   // Use these ranges to contruct a list of nodes to act on
-  res = GetNodesForOperation(arrayOfRanges, outArrayOfNodes, aOperation,
-                             aTouchContent);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetNodesForOperation(arrayOfRanges, outArrayOfNodes, aOperation,
+                            aTouchContent);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 /**
  * GetNodesFromSelection() constructs a list of nodes from the selection that
  * will be operated on.
  */
@@ -6047,19 +6103,19 @@ HTMLEditRules::GetNodesFromSelection(
                  nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
                  TouchContent aTouchContent)
 {
   // Promote selection ranges
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
   GetPromotedRanges(aSelection, arrayOfRanges, aOperation);
 
   // Use these ranges to contruct a list of nodes to act on.
-  nsresult res = GetNodesForOperation(arrayOfRanges, outArrayOfNodes,
-                                      aOperation, aTouchContent);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetNodesForOperation(arrayOfRanges, outArrayOfNodes,
+                                     aOperation, aTouchContent);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 /**
  * MakeTransitionList() detects all the transitions in the array, where a
  * transition means that adjacent nodes in the array don't have the same parent.
  */
@@ -6119,44 +6175,44 @@ HTMLEditRules::ReturnInHeader(Selection&
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Remember where the header is
   nsCOMPtr<nsINode> headerParent = aHeader.GetParentNode();
   int32_t offset = headerParent ? headerParent->IndexOf(&aHeader) : -1;
 
   // Get ws code to adjust any ws
   nsCOMPtr<nsINode> node = &aNode;
-  nsresult res = WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
-                                                         address_of(node),
-                                                         &aOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
+                                                        address_of(node),
+                                                        &aOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Split the header
   NS_ENSURE_STATE(node->IsContent());
   htmlEditor->SplitNodeDeep(aHeader, *node->AsContent(), aOffset);
 
   // If the left-hand heading is empty, put a mozbr in it
   nsCOMPtr<nsIContent> prevItem = htmlEditor->GetPriorHTMLSibling(&aHeader);
   if (prevItem && HTMLEditUtils::IsHeader(*prevItem)) {
     bool isEmptyNode;
-    res = htmlEditor->IsEmptyNode(prevItem, &isEmptyNode);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->IsEmptyNode(prevItem, &isEmptyNode);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (isEmptyNode) {
-      res = CreateMozBR(prevItem->AsDOMNode(), 0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = CreateMozBR(prevItem->AsDOMNode(), 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // If the new (righthand) header node is empty, delete it
   bool isEmpty;
-  res = IsEmptyBlock(aHeader, &isEmpty, MozBRCounts::no);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = IsEmptyBlock(aHeader, &isEmpty, MozBRCounts::no);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (isEmpty) {
-    res = htmlEditor->DeleteNode(&aHeader);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->DeleteNode(&aHeader);
+    NS_ENSURE_SUCCESS(rv, rv);
     // Layout tells the caret to blink in a weird place if we don't place a
     // break after the header.
     nsCOMPtr<nsIContent> sibling =
       htmlEditor->GetNextHTMLSibling(headerParent, offset + 1);
     if (!sibling || !sibling->IsHTMLElement(nsGkAtoms::br)) {
       ClearCachedStyles();
       htmlEditor->mTypeInState->ClearAllProps();
 
@@ -6165,29 +6221,29 @@ HTMLEditRules::ReturnInHeader(Selection&
         htmlEditor->CreateNode(nsGkAtoms::p, headerParent, offset + 1);
       NS_ENSURE_STATE(pNode);
 
       // Append a <br> to it
       nsCOMPtr<Element> brNode = htmlEditor->CreateBR(pNode, 0);
       NS_ENSURE_STATE(brNode);
 
       // Set selection to before the break
-      res = aSelection.Collapse(pNode, 0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = aSelection.Collapse(pNode, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       headerParent = sibling->GetParentNode();
       offset = headerParent ? headerParent->IndexOf(sibling) : -1;
       // Put selection after break
-      res = aSelection.Collapse(headerParent, offset + 1);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = aSelection.Collapse(headerParent, offset + 1);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   } else {
     // Put selection at front of righthand heading
-    res = aSelection.Collapse(&aHeader, 0);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = aSelection.Collapse(&aHeader, 0);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 /**
  * ReturnInParagraph() does the right thing for returns pressed in paragraphs.
  */
 nsresult
@@ -6199,17 +6255,16 @@ HTMLEditRules::ReturnInParagraph(Selecti
                                  bool* aHandled)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   if (!aSelection || !aPara || !node || !aCancel || !aHandled) {
     return NS_ERROR_NULL_POINTER;
   }
   *aCancel = false;
   *aHandled = false;
-  nsresult res;
 
   int32_t offset;
   nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(node, &offset);
 
   NS_ENSURE_STATE(mHTMLEditor);
   bool doesCRCreateNewP = mHTMLEditor->GetReturnInParagraphCreatesNewParagraph();
 
   bool newBRneeded = false;
@@ -6220,18 +6275,18 @@ HTMLEditRules::ReturnInParagraph(Selecti
 
   NS_ENSURE_STATE(mHTMLEditor);
   if (aNode == aPara && doesCRCreateNewP) {
     // we are at the edges of the block, newBRneeded not needed!
     sibling = node->AsContent();
   } else if (mHTMLEditor->IsTextNode(aNode)) {
     nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(aNode);
     uint32_t strLength;
-    res = textNode->GetLength(&strLength);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = textNode->GetLength(&strLength);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     // at beginning of text node?
     if (!aOffset) {
       // is there a BR prior to it?
       NS_ENSURE_STATE(mHTMLEditor);
       sibling = mHTMLEditor->GetPriorHTMLSibling(node);
       if (!sibling || !mHTMLEditor || !mHTMLEditor->IsVisBreak(sibling) ||
           TextEditUtils::HasMozAttr(GetAsDOMNode(sibling))) {
@@ -6247,18 +6302,18 @@ HTMLEditRules::ReturnInParagraph(Selecti
           TextEditUtils::HasMozAttr(GetAsDOMNode(sibling))) {
         NS_ENSURE_STATE(mHTMLEditor);
         newBRneeded = true;
         offset++;
       }
     } else {
       if (doesCRCreateNewP) {
         nsCOMPtr<nsIDOMNode> tmp;
-        res = mTextEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp));
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mTextEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp));
+        NS_ENSURE_SUCCESS(rv, rv);
         selNode = tmp;
       }
 
       newBRneeded = true;
       offset++;
     }
   } else {
     // not in a text node.
@@ -6310,54 +6365,56 @@ HTMLEditRules::SplitParagraph(nsIDOMNode
                               nsIContent* aBRNode,
                               Selection* aSelection,
                               nsCOMPtr<nsIDOMNode>* aSelNode,
                               int32_t* aOffset)
 {
   nsCOMPtr<Element> para = do_QueryInterface(aPara);
   NS_ENSURE_TRUE(para && aBRNode && aSelNode && *aSelNode && aOffset &&
                  aSelection, NS_ERROR_NULL_POINTER);
-  nsresult res = NS_OK;
 
   // split para
   // get ws code to adjust any ws
   nsCOMPtr<nsIContent> leftPara, rightPara;
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<nsINode> selNode(do_QueryInterface(*aSelNode));
-  res = WSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor,
-                                                address_of(selNode), aOffset);
+  nsresult rv =
+    WSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor,
+                                            address_of(selNode), aOffset);
+  // XXX When it fails, why do we need to return selection node?  (Why can the
+  //     caller trust the result even when it returns error?)
   *aSelNode = GetAsDOMNode(selNode);
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
   // split the paragraph
   NS_ENSURE_STATE(mHTMLEditor);
   NS_ENSURE_STATE(selNode->IsContent());
   mHTMLEditor->SplitNodeDeep(*para, *selNode->AsContent(), *aOffset,
                              HTMLEditor::EmptyContainers::yes,
                              getter_AddRefs(leftPara),
                              getter_AddRefs(rightPara));
   // get rid of the break, if it is visible (otherwise it may be needed to prevent an empty p)
   NS_ENSURE_STATE(mHTMLEditor);
   if (mHTMLEditor->IsVisBreak(aBRNode))
   {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->DeleteNode(aBRNode);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->DeleteNode(aBRNode);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // remove ID attribute on the paragraph we just created
   nsCOMPtr<nsIDOMElement> rightElt = do_QueryInterface(rightPara);
   NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->RemoveAttribute(rightElt, NS_LITERAL_STRING("id"));
-  NS_ENSURE_SUCCESS(res, res);
+  rv = mHTMLEditor->RemoveAttribute(rightElt, NS_LITERAL_STRING("id"));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // check both halves of para to see if we need mozBR
-  res = InsertMozBRIfNeeded(*leftPara);
-  NS_ENSURE_SUCCESS(res, res);
-  res = InsertMozBRIfNeeded(*rightPara);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = InsertMozBRIfNeeded(*leftPara);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = InsertMozBRIfNeeded(*rightPara);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // selection to beginning of right hand para;
   // look inside any containers that are up front.
   nsCOMPtr<nsINode> rightParaNode = do_QueryInterface(rightPara);
   NS_ENSURE_STATE(mHTMLEditor && rightParaNode);
   nsCOMPtr<nsIDOMNode> child =
     GetAsDOMNode(mHTMLEditor->GetLeftmostChild(rightParaNode, true));
   if (mHTMLEditor->IsTextNode(child) ||
@@ -6366,17 +6423,17 @@ HTMLEditRules::SplitParagraph(nsIDOMNode
     aSelection->Collapse(child,0);
   }
   else
   {
     int32_t offset;
     nsCOMPtr<nsIDOMNode> parent = EditorBase::GetNodeLocation(child, &offset);
     aSelection->Collapse(parent,offset);
   }
-  return res;
+  return NS_OK;
 }
 
 /**
  * ReturnInListItem: do the right thing for returns pressed in list items
  */
 nsresult
 HTMLEditRules::ReturnInListItem(Selection& aSelection,
                                 Element& aListItem,
@@ -6393,176 +6450,171 @@ HTMLEditRules::ReturnInListItem(Selectio
 
   nsCOMPtr<Element> list = aListItem.GetParentElement();
   int32_t itemOffset = list ? list->IndexOf(&aListItem) : -1;
 
   // If we are in an empty item, then we want to pop up out of the list, but
   // only if prefs say it's okay and if the parent isn't the active editing
   // host.
   bool isEmpty;
-  nsresult res = IsEmptyBlock(aListItem, &isEmpty, MozBRCounts::no);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = IsEmptyBlock(aListItem, &isEmpty, MozBRCounts::no);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (isEmpty && root != list && mReturnInEmptyLIKillsList) {
     // Get the list offset now -- before we might eventually split the list
     nsCOMPtr<nsINode> listParent = list->GetParentNode();
     int32_t offset = listParent ? listParent->IndexOf(list) : -1;
 
     // Are we the last list item in the list?
     bool isLast;
-    res = htmlEditor->IsLastEditableChild(aListItem.AsDOMNode(), &isLast);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->IsLastEditableChild(aListItem.AsDOMNode(), &isLast);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (!isLast) {
       // We need to split the list!
       ErrorResult rv;
       htmlEditor->SplitNode(*list, itemOffset, rv);
       NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
     }
 
     // Are we in a sublist?
     if (HTMLEditUtils::IsList(listParent)) {
       // If so, move item out of this list and into the grandparent list
-      res = htmlEditor->MoveNode(&aListItem, listParent, offset + 1);
-      NS_ENSURE_SUCCESS(res, res);
-      res = aSelection.Collapse(&aListItem, 0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->MoveNode(&aListItem, listParent, offset + 1);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = aSelection.Collapse(&aListItem, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       // Otherwise kill this item
-      res = htmlEditor->DeleteNode(&aListItem);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->DeleteNode(&aListItem);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       // Time to insert a paragraph
       nsCOMPtr<Element> pNode =
         htmlEditor->CreateNode(nsGkAtoms::p, listParent, offset + 1);
       NS_ENSURE_STATE(pNode);
 
       // Append a <br> to it
       nsCOMPtr<Element> brNode = htmlEditor->CreateBR(pNode, 0);
       NS_ENSURE_STATE(brNode);
 
       // Set selection to before the break
-      res = aSelection.Collapse(pNode, 0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = aSelection.Collapse(pNode, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     return NS_OK;
   }
 
   // Else we want a new list item at the same list level.  Get ws code to
   // adjust any ws.
   nsCOMPtr<nsINode> selNode = &aNode;
-  res = WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
-                                                address_of(selNode),
-                                                &aOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
+                                               address_of(selNode), &aOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   // Now split list item
   NS_ENSURE_STATE(selNode->IsContent());
   htmlEditor->SplitNodeDeep(aListItem, *selNode->AsContent(), aOffset);
 
   // Hack: until I can change the damaged doc range code back to being
   // extra-inclusive, I have to manually detect certain list items that may be
   // left empty.
   nsCOMPtr<nsIContent> prevItem = htmlEditor->GetPriorHTMLSibling(&aListItem);
   if (prevItem && HTMLEditUtils::IsListItem(prevItem)) {
     bool isEmptyNode;
-    res = htmlEditor->IsEmptyNode(prevItem, &isEmptyNode);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->IsEmptyNode(prevItem, &isEmptyNode);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (isEmptyNode) {
-      res = CreateMozBR(prevItem->AsDOMNode(), 0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = CreateMozBR(prevItem->AsDOMNode(), 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
-      res = htmlEditor->IsEmptyNode(&aListItem, &isEmptyNode, true);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->IsEmptyNode(&aListItem, &isEmptyNode, true);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (isEmptyNode) {
         nsCOMPtr<nsIAtom> nodeAtom = aListItem.NodeInfo()->NameAtom();
         if (nodeAtom == nsGkAtoms::dd || nodeAtom == nsGkAtoms::dt) {
           nsCOMPtr<nsINode> list = aListItem.GetParentNode();
           int32_t itemOffset = list ? list->IndexOf(&aListItem) : -1;
 
           nsIAtom* listAtom = nodeAtom == nsGkAtoms::dt ? nsGkAtoms::dd
                                                         : nsGkAtoms::dt;
           nsCOMPtr<Element> newListItem =
             htmlEditor->CreateNode(listAtom, list, itemOffset + 1);
           NS_ENSURE_STATE(newListItem);
-          res = mTextEditor->DeleteNode(&aListItem);
-          NS_ENSURE_SUCCESS(res, res);
-          res = aSelection.Collapse(newListItem, 0);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = mTextEditor->DeleteNode(&aListItem);
+          NS_ENSURE_SUCCESS(rv, rv);
+          rv = aSelection.Collapse(newListItem, 0);
+          NS_ENSURE_SUCCESS(rv, rv);
 
           return NS_OK;
         }
 
         nsCOMPtr<Element> brNode;
-        res = htmlEditor->CopyLastEditableChildStyles(GetAsDOMNode(prevItem),
-          GetAsDOMNode(&aListItem), getter_AddRefs(brNode));
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->CopyLastEditableChildStyles(GetAsDOMNode(prevItem),
+                                                     GetAsDOMNode(&aListItem),
+                                                     getter_AddRefs(brNode));
+        NS_ENSURE_SUCCESS(rv, rv);
         if (brNode) {
           nsCOMPtr<nsINode> brParent = brNode->GetParentNode();
           int32_t offset = brParent ? brParent->IndexOf(brNode) : -1;
-          res = aSelection.Collapse(brParent, offset);
-          NS_ENSURE_SUCCESS(res, res);
-
+          rv = aSelection.Collapse(brParent, offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           return NS_OK;
         }
       } else {
         WSRunObject wsObj(htmlEditor, &aListItem, 0);
         nsCOMPtr<nsINode> visNode;
         int32_t visOffset = 0;
         WSType wsType;
         wsObj.NextVisibleNode(&aListItem, 0, address_of(visNode),
                               &visOffset, &wsType);
         if (wsType == WSType::special || wsType == WSType::br ||
             visNode->IsHTMLElement(nsGkAtoms::hr)) {
           nsCOMPtr<nsINode> parent = visNode->GetParentNode();
           int32_t offset = parent ? parent->IndexOf(visNode) : -1;
-          res = aSelection.Collapse(parent, offset);
-          NS_ENSURE_SUCCESS(res, res);
-
+          rv = aSelection.Collapse(parent, offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           return NS_OK;
         } else {
-          res = aSelection.Collapse(visNode, visOffset);
-          NS_ENSURE_SUCCESS(res, res);
-
+          rv = aSelection.Collapse(visNode, visOffset);
+          NS_ENSURE_SUCCESS(rv, rv);
           return NS_OK;
         }
       }
     }
   }
-  res = aSelection.Collapse(&aListItem, 0);
-  NS_ENSURE_SUCCESS(res, res);
-
+  rv = aSelection.Collapse(&aListItem, 0);
+  NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 /**
  * MakeBlockquote() puts the list of nodes into one or more blockquotes.
  */
 nsresult
 HTMLEditRules::MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
 {
   // The idea here is to put the nodes into a minimal number of blockquotes.
   // When the user blockquotes something, they expect one blockquote.  That may
   // not be possible (for instance, if they have two table cells selected, you
   // need two blockquotes inside the cells).
-  nsresult res;
   nsCOMPtr<Element> curBlock;
   nsCOMPtr<nsINode> prevParent;
 
   for (auto& curNode : aNodeArray) {
     // Get the node to act on, and its location
     NS_ENSURE_STATE(curNode->IsContent());
 
     // If the node is a table element or list item, dive inside
     if (HTMLEditUtils::IsTableElementButNotTable(curNode) ||
         HTMLEditUtils::IsListItem(curNode)) {
       // Forget any previous block
       curBlock = nullptr;
       // Recursion time
       nsTArray<OwningNonNull<nsINode>> childArray;
       GetChildNodesForOperation(*curNode, childArray);
-      res = MakeBlockquote(childArray);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = MakeBlockquote(childArray);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // If the node has different parent than previous node, further nodes in a
     // new parent
     if (prevParent) {
       if (prevParent != curNode->GetParentNode()) {
         // Forget any previous blockquote node we were using
         curBlock = nullptr;
@@ -6571,117 +6623,115 @@ HTMLEditRules::MakeBlockquote(nsTArray<O
     } else {
       prevParent = curNode->GetParentNode();
     }
 
     // If no curBlock, make one
     if (!curBlock) {
       nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
       int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
-      res = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset);
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_STATE(mHTMLEditor);
       curBlock = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent,
                                          offset);
       NS_ENSURE_STATE(curBlock);
       // remember our new block for postprocessing
       mNewBlock = curBlock;
       // note: doesn't matter if we set mNewBlock multiple times.
     }
 
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = mHTMLEditor->MoveNode(curNode->AsContent(), curBlock, -1);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 /**
  * RemoveBlockStyle() makes the nodes have no special block type.
  */
 nsresult
 HTMLEditRules::RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
 {
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
   // Intent of this routine is to be used for converting to/from headers,
   // paragraphs, pre, and address.  Those blocks that pretty much just contain
   // inline things...
-  nsresult res;
-
   nsCOMPtr<Element> curBlock;
   nsCOMPtr<nsIContent> firstNode, lastNode;
   for (auto& curNode : aNodeArray) {
     // If curNode is a address, p, header, address, or pre, remove it
     if (HTMLEditUtils::IsFormatNode(curNode)) {
       // Process any partial progress saved
       if (curBlock) {
-        res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+        NS_ENSURE_SUCCESS(rv, rv);
         firstNode = lastNode = curBlock = nullptr;
       }
       // Remove current block
-      res = htmlEditor->RemoveBlockContainer(*curNode->AsContent());
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = htmlEditor->RemoveBlockContainer(*curNode->AsContent());
+      NS_ENSURE_SUCCESS(rv, rv);
     } else if (curNode->IsAnyOfHTMLElements(nsGkAtoms::table,
                                             nsGkAtoms::tr,
                                             nsGkAtoms::tbody,
                                             nsGkAtoms::td,
                                             nsGkAtoms::li,
                                             nsGkAtoms::blockquote,
                                             nsGkAtoms::div) ||
                 HTMLEditUtils::IsList(curNode)) {
       // Process any partial progress saved
       if (curBlock) {
-        res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+        NS_ENSURE_SUCCESS(rv, rv);
         firstNode = lastNode = curBlock = nullptr;
       }
       // Recursion time
       nsTArray<OwningNonNull<nsINode>> childArray;
       GetChildNodesForOperation(*curNode, childArray);
-      res = RemoveBlockStyle(childArray);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = RemoveBlockStyle(childArray);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else if (IsInlineNode(curNode)) {
       if (curBlock) {
         // If so, is this node a descendant?
         if (EditorUtils::IsDescendantOf(curNode, curBlock)) {
           // Then we don't need to do anything different for this node
           lastNode = curNode->AsContent();
           continue;
         } else {
           // Otherwise, we have progressed beyond end of curBlock, so let's
           // handle it now.  We need to remove the portion of curBlock that
           // contains [firstNode - lastNode].
-          res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
-          NS_ENSURE_SUCCESS(res, res);
+          nsresult rv = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+          NS_ENSURE_SUCCESS(rv, rv);
           firstNode = lastNode = curBlock = nullptr;
           // Fall out and handle curNode
         }
       }
       curBlock = htmlEditor->GetBlockNodeParent(curNode);
       if (curBlock && HTMLEditUtils::IsFormatNode(curBlock)) {
         firstNode = lastNode = curNode->AsContent();
       } else {
         // Not a block kind that we care about.
         curBlock = nullptr;
       }
     } else if (curBlock) {
       // Some node that is already sans block style.  Skip over it and process
       // any partial progress saved.
-      res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       firstNode = lastNode = curBlock = nullptr;
     }
   }
   // Process any partial progress saved
   if (curBlock) {
-    res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
+    NS_ENSURE_SUCCESS(rv, rv);
     firstNode = lastNode = curBlock = nullptr;
   }
   return NS_OK;
 }
 
 /**
  * ApplyBlockStyle() does whatever it takes to make the list of nodes into one
  * or more blocks of type aBlockTag.
@@ -6691,18 +6741,16 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
                                nsIAtom& aBlockTag)
 {
   // Intent of this routine is to be used for converting to/from headers,
   // paragraphs, pre, and address.  Those blocks that pretty much just contain
   // inline things...
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
-  nsresult res;
-
   // Remove all non-editable nodes.  Leave them be.
   for (int32_t i = aNodeArray.Length() - 1; i >= 0; i--) {
     if (!htmlEditor->IsEditable(aNodeArray[i])) {
       aNodeArray.RemoveElementAt(i);
     }
   }
 
   nsCOMPtr<Element> newBlock;
@@ -6740,98 +6788,98 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
                                             nsGkAtoms::blockquote,
                                             nsGkAtoms::div)) {
       // Forget any previous block used for previous inline nodes
       curBlock = nullptr;
       // Recursion time
       nsTArray<OwningNonNull<nsINode>> childArray;
       GetChildNodesForOperation(*curNode, childArray);
       if (childArray.Length()) {
-        res = ApplyBlockStyle(childArray, aBlockTag);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = ApplyBlockStyle(childArray, aBlockTag);
+        NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // Make sure we can put a block here
-        res = SplitAsNeeded(aBlockTag, curParent, offset);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         nsCOMPtr<Element> theBlock =
           htmlEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(theBlock);
         // Remember our new block for postprocessing
         mNewBlock = theBlock;
       }
     } else if (curNode->IsHTMLElement(nsGkAtoms::br)) {
       // If the node is a break, we honor it by putting further nodes in a new
       // parent
       if (curBlock) {
         // Forget any previous block used for previous inline nodes
         curBlock = nullptr;
-        res = htmlEditor->DeleteNode(curNode);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = htmlEditor->DeleteNode(curNode);
+        NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // The break is the first (or even only) node we encountered.  Create a
         // block for it.
-        res = SplitAsNeeded(aBlockTag, curParent, offset);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
         mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
-        res = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     } else if (IsInlineNode(curNode)) {
       // If curNode is inline, pull it into curBlock.  Note: it's assumed that
       // consecutive inline nodes in aNodeArray are actually members of the
       // same block parent.  This happens to be true now as a side effect of
       // how aNodeArray is contructed, but some additional logic should be
       // added here if that should change
       //
       // If curNode is a non editable, drop it if we are going to <pre>.
       if (&aBlockTag == nsGkAtoms::pre && !htmlEditor->IsEditable(curNode)) {
         // Do nothing to this block
         continue;
       }
 
       // If no curBlock, make one
       if (!curBlock) {
-        res = SplitAsNeeded(aBlockTag, curParent, offset);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = SplitAsNeeded(aBlockTag, curParent, offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         curBlock = htmlEditor->CreateNode(&aBlockTag, curParent, offset);
         NS_ENSURE_STATE(curBlock);
         // Remember our new block for postprocessing
         mNewBlock = curBlock;
         // Note: doesn't matter if we set mNewBlock multiple times.
       }
 
       // XXX If curNode is a br, replace it with a return if going to <pre>
 
       // This is a continuation of some inline nodes that belong together in
       // the same block item.  Use curBlock.
-      res = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return NS_OK;
 }
 
 /**
  * Given a tag name, split inOutParent up to the point where we can insert the
  * tag.  Adjust inOutParent and inOutOffset to point to new location for tag.
  */
 nsresult
 HTMLEditRules::SplitAsNeeded(nsIAtom& aTag,
                              OwningNonNull<nsINode>& aInOutParent,
                              int32_t& aInOutOffset)
 {
   // XXX Is there a better way to do this?
   nsCOMPtr<nsINode> parent = aInOutParent.forget();
-  nsresult res = SplitAsNeeded(aTag, parent, aInOutOffset);
+  nsresult rv = SplitAsNeeded(aTag, parent, aInOutOffset);
   aInOutParent = parent.forget();
-  return res;
+  return rv;
 }
 
 nsresult
 HTMLEditRules::SplitAsNeeded(nsIAtom& aTag,
                              nsCOMPtr<nsINode>& inOutParent,
                              int32_t& inOutOffset)
 {
   NS_ENSURE_TRUE(inOutParent, NS_ERROR_NULL_POINTER);
@@ -6891,46 +6939,45 @@ HTMLEditRules::JoinNodesSmart(nsIContent
   // Caller responsible for left and right node being the same type
   nsCOMPtr<nsINode> parent = aNodeLeft.GetParentNode();
   NS_ENSURE_TRUE(parent, EditorDOMPoint());
   int32_t parOffset = parent->IndexOf(&aNodeLeft);
   nsCOMPtr<nsINode> rightParent = aNodeRight.GetParentNode();
 
   // If they don't have the same parent, first move the right node to after the
   // left one
-  nsresult res;
   if (parent != rightParent) {
     NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
-    res = mHTMLEditor->MoveNode(&aNodeRight, parent, parOffset);
-    NS_ENSURE_SUCCESS(res, EditorDOMPoint());
+    nsresult rv = mHTMLEditor->MoveNode(&aNodeRight, parent, parOffset);
+    NS_ENSURE_SUCCESS(rv, EditorDOMPoint());
   }
 
   EditorDOMPoint ret(&aNodeRight, aNodeLeft.Length());
 
   // Separate join rules for differing blocks
   if (HTMLEditUtils::IsList(&aNodeLeft) || aNodeLeft.GetAsText()) {
     // For lists, merge shallow (wouldn't want to combine list items)
-    res = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight);
-    NS_ENSURE_SUCCESS(res, EditorDOMPoint());
+    nsresult rv = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight);
+    NS_ENSURE_SUCCESS(rv, EditorDOMPoint());
     return ret;
   }
 
   // Remember the last left child, and first right child
   NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
   nsCOMPtr<nsIContent> lastLeft = mHTMLEditor->GetLastEditableChild(aNodeLeft);
   NS_ENSURE_TRUE(lastLeft, EditorDOMPoint());
 
   NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
   nsCOMPtr<nsIContent> firstRight = mHTMLEditor->GetFirstEditableChild(aNodeRight);
   NS_ENSURE_TRUE(firstRight, EditorDOMPoint());
 
   // For list items, divs, etc., merge smart
   NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
-  res = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight);
-  NS_ENSURE_SUCCESS(res, EditorDOMPoint());
+  nsresult rv = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight);
+  NS_ENSURE_SUCCESS(rv, EditorDOMPoint());
 
   if (lastLeft && firstRight && mHTMLEditor &&
       mHTMLEditor->AreNodesSameType(lastLeft, firstRight) &&
       (lastLeft->GetAsText() || !mHTMLEditor ||
        (lastLeft->IsElement() && firstRight->IsElement() &&
         mHTMLEditor->mCSSEditUtils->ElementsSameStyle(lastLeft->AsElement(),
                                                   firstRight->AsElement())))) {
     NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
@@ -7046,23 +7093,23 @@ HTMLEditRules::ReapplyCachedStyles()
         NS_ENSURE_STATE(mHTMLEditor);
         bAny = mHTMLEditor->mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(
           selNode, mCachedStyles[i].tag, &(mCachedStyles[i].attr), curValue,
           CSSEditUtils::eComputed);
       }
       if (!bAny) {
         // then check typeinstate and html style
         NS_ENSURE_STATE(mHTMLEditor);
-        nsresult res = mHTMLEditor->GetInlinePropertyBase(
-                                                     *mCachedStyles[i].tag,
-                                                     &(mCachedStyles[i].attr),
-                                                     &(mCachedStyles[i].value),
-                                                     &bFirst, &bAny, &bAll,
-                                                     &curValue, false);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv =
+          mHTMLEditor->GetInlinePropertyBase(*mCachedStyles[i].tag,
+                                             &(mCachedStyles[i].attr),
+                                             &(mCachedStyles[i].value),
+                                             &bFirst, &bAny, &bAll,
+                                             &curValue, false);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       // this style has disappeared through deletion.  Add to our typeinstate:
       if (!bAny || IsStyleCachePreservingAction(mTheAction)) {
         NS_ENSURE_STATE(mHTMLEditor);
         mHTMLEditor->mTypeInState->SetProp(mCachedStyles[i].tag,
                                            mCachedStyles[i].attr,
                                            mCachedStyles[i].value);
       }
@@ -7086,40 +7133,45 @@ void
 HTMLEditRules::AdjustSpecialBreaks()
 {
   NS_ENSURE_TRUE(mHTMLEditor, );
 
   // Gather list of empty nodes
   nsTArray<OwningNonNull<nsINode>> nodeArray;
   EmptyEditableFunctor functor(mHTMLEditor);
   DOMIterator iter;
-  nsresult res = iter.Init(*mDocChangeRange);
-  NS_ENSURE_SUCCESS(res, );
+  if (NS_WARN_IF(NS_FAILED(iter.Init(*mDocChangeRange)))) {
+    return;
+  }
   iter.AppendList(functor, nodeArray);
 
   // Put moz-br's into these empty li's and td's
   for (auto& node : nodeArray) {
     // Need to put br at END of node.  It may have empty containers in it and
     // still pass the "IsEmptyNode" test, and we want the br's to be after
     // them.  Also, we want the br to be after the selection if the selection
     // is in this node.
-    nsresult res = CreateMozBR(node->AsDOMNode(), (int32_t)node->Length());
-    NS_ENSURE_SUCCESS(res, );
+    nsresult rv = CreateMozBR(node->AsDOMNode(), (int32_t)node->Length());
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return;
+    }
   }
 }
 
 nsresult
 HTMLEditRules::AdjustWhitespace(Selection* aSelection)
 {
   // get selection point
   nsCOMPtr<nsIDOMNode> selNode;
   int32_t selOffset;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->GetStartNodeAndOffset(aSelection,
+                                       getter_AddRefs(selNode), &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // ask whitespace object to tweak nbsp's
   NS_ENSURE_STATE(mHTMLEditor);
   return WSRunObject(mHTMLEditor, selNode, selOffset).AdjustWhitespace();
 }
 
 nsresult
 HTMLEditRules::PinSelectionToNewBlock(Selection* aSelection)
@@ -7128,48 +7180,50 @@ HTMLEditRules::PinSelectionToNewBlock(Se
   if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, temp;
   int32_t selOffset;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->GetStartNodeAndOffset(aSelection,
+                                       getter_AddRefs(selNode), &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   temp = selNode;
 
   // use ranges and sRangeHelper to compare sel point to new block
   nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
   NS_ENSURE_STATE(node);
   RefPtr<nsRange> range = new nsRange(node);
-  res = range->SetStart(selNode, selOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = range->SetEnd(selNode, selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = range->SetStart(selNode, selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = range->SetEnd(selNode, selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIContent> block = mNewBlock.get();
   NS_ENSURE_TRUE(block, NS_ERROR_NO_INTERFACE);
   bool nodeBefore, nodeAfter;
-  res = nsRange::CompareNodeToRange(block, range, &nodeBefore, &nodeAfter);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = nsRange::CompareNodeToRange(block, range, &nodeBefore, &nodeAfter);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (nodeBefore && nodeAfter)
     return NS_OK;  // selection is inside block
   else if (nodeBefore)
   {
     // selection is after block.  put at end of block.
     nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
     NS_ENSURE_STATE(mHTMLEditor);
     tmp = GetAsDOMNode(mHTMLEditor->GetLastEditableChild(*block));
     uint32_t endPoint;
     if (mHTMLEditor->IsTextNode(tmp) ||
         mHTMLEditor->IsContainer(tmp))
     {
-      res = EditorBase::GetLengthOfDOMNode(tmp, endPoint);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = EditorBase::GetLengthOfDOMNode(tmp, endPoint);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     else
     {
       tmp = EditorBase::GetNodeLocation(tmp, (int32_t*)&endPoint);
       endPoint++;  // want to be after this node
     }
     return aSelection->Collapse(tmp, (int32_t)endPoint);
   }
@@ -7242,18 +7296,20 @@ HTMLEditRules::AdjustSelection(Selection
   if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   // get the (collapsed) selection location
   nsCOMPtr<nsINode> selNode, temp;
   int32_t selOffset;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->GetStartNodeAndOffset(aSelection,
+                                       getter_AddRefs(selNode), &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   temp = selNode;
 
   // are we in an editable node?
   NS_ENSURE_STATE(mHTMLEditor);
   while (!mHTMLEditor->IsEditable(selNode))
   {
     // scan up the tree until we find an editable place to be
     selNode = EditorBase::GetNodeLocation(temp, &selOffset);
@@ -7265,18 +7321,18 @@ HTMLEditRules::AdjustSelection(Selection
   // make sure we aren't in an empty block - user will see no cursor.  If this
   // is happening, put a <br> in the block if allowed.
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<Element> theblock = mHTMLEditor->GetBlock(*selNode);
 
   if (theblock && mHTMLEditor->IsEditable(theblock)) {
     bool bIsEmptyNode;
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, false, false);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, false, false);
+    NS_ENSURE_SUCCESS(rv, rv);
     // check if br can go into the destination node
     NS_ENSURE_STATE(mHTMLEditor);
     if (bIsEmptyNode && mHTMLEditor->CanContainTag(*selNode, *nsGkAtoms::br)) {
       NS_ENSURE_STATE(mHTMLEditor);
       nsCOMPtr<Element> rootNode = mHTMLEditor->GetRoot();
       NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
       if (selNode == rootNode)
       {
@@ -7314,25 +7370,25 @@ HTMLEditRules::AdjustSelection(Selection
       if (nearNode && TextEditUtils::IsBreak(nearNode)) {
         NS_ENSURE_STATE(mHTMLEditor);
         if (!mHTMLEditor->IsVisBreak(nearNode))
         {
           // need to insert special moz BR. Why?  Because if we don't
           // the user will see no new line for the break.  Also, things
           // like table cells won't grow in height.
           nsCOMPtr<nsIDOMNode> brNode;
-          res = CreateMozBR(GetAsDOMNode(selNode), selOffset,
-                            getter_AddRefs(brNode));
-          NS_ENSURE_SUCCESS(res, res);
+          rv = CreateMozBR(GetAsDOMNode(selNode), selOffset,
+                           getter_AddRefs(brNode));
+          NS_ENSURE_SUCCESS(rv, rv);
           nsCOMPtr<nsIDOMNode> brParent =
             EditorBase::GetNodeLocation(brNode, &selOffset);
           // selection stays *before* moz-br, sticking to it
           aSelection->SetInterlinePosition(true);
-          res = aSelection->Collapse(brParent, selOffset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = aSelection->Collapse(brParent, selOffset);
+          NS_ENSURE_SUCCESS(rv, rv);
         }
         else
         {
           NS_ENSURE_STATE(mHTMLEditor);
           nsCOMPtr<nsIContent> nextNode =
             mHTMLEditor->GetNextHTMLNode(nearNode, true);
           if (nextNode && TextEditUtils::IsMozBR(nextNode)) {
             // selection between br and mozbr.  make it stick to mozbr
@@ -7361,102 +7417,120 @@ HTMLEditRules::AdjustSelection(Selection
                    nearNode->IsAnyOfHTMLElements(nsGkAtoms::img,
                                                  nsGkAtoms::hr))) {
     return NS_OK; // this is a good place for the caret to be
   }
 
   // look for a nearby text node.
   // prefer the correct direction.
   nsCOMPtr<nsIDOMNode> nearNodeDOM = GetAsDOMNode(nearNode);
-  res = FindNearSelectableNode(GetAsDOMNode(selNode), selOffset, aAction,
-                               address_of(nearNodeDOM));
-  NS_ENSURE_SUCCESS(res, res);
+  rv = FindNearSelectableNode(GetAsDOMNode(selNode), selOffset, aAction,
+                              address_of(nearNodeDOM));
+  NS_ENSURE_SUCCESS(rv, rv);
   nearNode = do_QueryInterface(nearNodeDOM);
 
   if (!nearNode) {
     return NS_OK;
   }
   EditorDOMPoint pt = GetGoodSelPointForNode(*nearNode, aAction);
-  res = aSelection->Collapse(pt.node, pt.offset);
-  if (NS_WARN_IF(NS_FAILED(res))) {
-    return res;
+  rv = aSelection->Collapse(pt.node, pt.offset);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
   }
   return NS_OK;
 }
 
 
 nsresult
 HTMLEditRules::FindNearSelectableNode(nsIDOMNode* aSelNode,
                                       int32_t aSelOffset,
                                       nsIEditor::EDirection& aDirection,
                                       nsCOMPtr<nsIDOMNode>* outSelectableNode)
 {
   NS_ENSURE_TRUE(aSelNode && outSelectableNode, NS_ERROR_NULL_POINTER);
   *outSelectableNode = nullptr;
-  nsresult res = NS_OK;
 
   nsCOMPtr<nsIDOMNode> nearNode, curNode;
   if (aDirection == nsIEditor::ePrevious) {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
+    nsresult rv =
+      mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
   } else {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
-  }
-  NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+  }
 
   if (!nearNode) // try the other direction then
   {
     if (aDirection == nsIEditor::ePrevious)
       aDirection = nsIEditor::eNext;
     else
       aDirection = nsIEditor::ePrevious;
 
     if (aDirection == nsIEditor::ePrevious) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
+      nsresult rv = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset,
+                                                  address_of(nearNode));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset,
+                                                 address_of(nearNode));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
   }
 
   // scan in the right direction until we find an eligible text node,
   // but don't cross any breaks, images, or table elements.
   NS_ENSURE_STATE(mHTMLEditor);
   while (nearNode && !(mHTMLEditor->IsTextNode(nearNode)
                        || TextEditUtils::IsBreak(nearNode)
                        || HTMLEditUtils::IsImage(nearNode)))
   {
     curNode = nearNode;
     if (aDirection == nsIEditor::ePrevious) {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetPriorHTMLNode(curNode, address_of(nearNode));
+      nsresult rv =
+        mHTMLEditor->GetPriorHTMLNode(curNode, address_of(nearNode));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetNextHTMLNode(curNode, address_of(nearNode));
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = mHTMLEditor->GetNextHTMLNode(curNode, address_of(nearNode));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
     NS_ENSURE_STATE(mHTMLEditor);
   }
 
   if (nearNode)
   {
     // don't cross any table elements
     if (InDifferentTableElements(nearNode, aSelNode)) {
       return NS_OK;
     }
 
     // otherwise, ok, we have found a good spot to put the selection
     *outSelectableNode = do_QueryInterface(nearNode);
   }
-  return res;
-}
-
+  return NS_OK;
+}
 
 bool
 HTMLEditRules::InDifferentTableElements(nsIDOMNode* aNode1,
                                         nsIDOMNode* aNode2)
 {
   nsCOMPtr<nsINode> node1 = do_QueryInterface(aNode1);
   nsCOMPtr<nsINode> node2 = do_QueryInterface(aNode2);
   return InDifferentTableElements(node1, node2);
@@ -7510,18 +7584,18 @@ HTMLEditRules::RemoveEmptyNodes()
   //
   // Unfortunately I can't use that strategy here, because the range may
   // include some children of a node while excluding others.  Thus I could find
   // all the _examined_ children empty, but still not have an empty parent.
 
   // need an iterator
   nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
 
-  nsresult res = iter->Init(mDocChangeRange);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = iter->Init(mDocChangeRange);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsTArray<OwningNonNull<nsINode>> arrayOfEmptyNodes, arrayOfEmptyCites, skipList;
 
   // Check for empty nodes
   while (!iter->IsDone()) {
     OwningNonNull<nsINode> node = *iter->GetCurrentNode();
 
     nsCOMPtr<nsINode> parent = node->GetParentNode();
@@ -7548,30 +7622,30 @@ HTMLEditRules::RemoveEmptyNodes()
           bIsCandidate = true;
         } else if (HTMLEditUtils::IsFormatNode(node) ||
                    HTMLEditUtils::IsListItem(node) ||
                    node->IsHTMLElement(nsGkAtoms::blockquote)) {
           // These node types are candidates if selection is not in them.  If
           // it is one of these, don't delete if selection inside.  This is so
           // we can create empty headings, etc., for the user to type into.
           bool bIsSelInNode;
-          res = SelectionEndpointInNode(node, &bIsSelInNode);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = SelectionEndpointInNode(node, &bIsSelInNode);
+          NS_ENSURE_SUCCESS(rv, rv);
           if (!bIsSelInNode) {
             bIsCandidate = true;
           }
         }
       }
 
       if (bIsCandidate) {
         // We delete mailcites even if they have a solo br in them.  Other
         // nodes we require to be empty.
-        res = htmlEditor->IsEmptyNode(node->AsDOMNode(), &bIsEmptyNode,
-                                      bIsMailCite, true);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->IsEmptyNode(node->AsDOMNode(), &bIsEmptyNode,
+                                     bIsMailCite, true);
+        NS_ENSURE_SUCCESS(rv, rv);
         if (bIsEmptyNode) {
           if (bIsMailCite) {
             // mailcites go on a separate list from other empty nodes
             arrayOfEmptyCites.AppendElement(*node);
           } else {
             arrayOfEmptyNodes.AppendElement(*node);
           }
         }
@@ -7584,37 +7658,37 @@ HTMLEditRules::RemoveEmptyNodes()
     }
 
     iter->Next();
   }
 
   // now delete the empty nodes
   for (auto& delNode : arrayOfEmptyNodes) {
     if (htmlEditor->IsModifiableNode(delNode)) {
-      res = htmlEditor->DeleteNode(delNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->DeleteNode(delNode);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // Now delete the empty mailcites.  This is a separate step because we want
   // to pull out any br's and preserve them.
   for (auto& delNode : arrayOfEmptyCites) {
     bool bIsEmptyNode;
-    res = htmlEditor->IsEmptyNode(delNode, &bIsEmptyNode, false, true);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->IsEmptyNode(delNode, &bIsEmptyNode, false, true);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (!bIsEmptyNode) {
       // We are deleting a cite that has just a br.  We want to delete cite,
       // but preserve br.
       nsCOMPtr<nsINode> parent = delNode->GetParentNode();
       int32_t offset = parent ? parent->IndexOf(delNode) : -1;
       nsCOMPtr<Element> br = htmlEditor->CreateBR(parent, offset);
       NS_ENSURE_STATE(br);
     }
-    res = htmlEditor->DeleteNode(delNode);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->DeleteNode(delNode);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::SelectionEndpointInNode(nsINode* aNode,
                                        bool* aResult)
@@ -7733,82 +7807,80 @@ HTMLEditRules::PopListItem(nsIDOMNode* a
 
   // if it's first or last list item, don't need to split the list
   // otherwise we do.
   nsCOMPtr<nsINode> curParPar = curParent->GetParentNode();
   int32_t parOffset = curParPar ? curParPar->IndexOf(curParent) : -1;
 
   bool bIsFirstListItem;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->IsFirstEditableChild(aListItem,
-                                                   &bIsFirstListItem);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->IsFirstEditableChild(aListItem, &bIsFirstListItem);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   bool bIsLastListItem;
   NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLastListItem);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLastListItem);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (!bIsFirstListItem && !bIsLastListItem)
   {
     // split the list
     nsCOMPtr<nsIDOMNode> newBlock;
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->SplitNode(GetAsDOMNode(curParent), offset,
-                                 getter_AddRefs(newBlock));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->SplitNode(GetAsDOMNode(curParent), offset,
+                                getter_AddRefs(newBlock));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (!bIsFirstListItem) parOffset++;
 
   NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->MoveNode(listItem, curParPar, parOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = mHTMLEditor->MoveNode(listItem, curParPar, parOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // unwrap list item contents if they are no longer in a list
   if (!HTMLEditUtils::IsList(curParPar) &&
       HTMLEditUtils::IsListItem(listItem)) {
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->RemoveBlockContainer(*listItem);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->RemoveBlockContainer(*listItem);
+    NS_ENSURE_SUCCESS(rv, rv);
     *aOutOfList = true;
   }
-  return res;
+  return NS_OK;
 }
 
 nsresult
 HTMLEditRules::RemoveListStructure(Element& aList)
 {
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
-  nsresult res;
-
   while (aList.GetFirstChild()) {
     OwningNonNull<nsIContent> child = *aList.GetFirstChild();
 
     if (HTMLEditUtils::IsListItem(child)) {
       bool isOutOfList;
       // Keep popping it out until it's not in a list anymore
       do {
-        res = PopListItem(child->AsDOMNode(), &isOutOfList);
-        NS_ENSURE_SUCCESS(res, res);
+        nsresult rv = PopListItem(child->AsDOMNode(), &isOutOfList);
+        NS_ENSURE_SUCCESS(rv, rv);
       } while (!isOutOfList);
     } else if (HTMLEditUtils::IsList(child)) {
-      res = RemoveListStructure(*child->AsElement());
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = RemoveListStructure(*child->AsElement());
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       // Delete any non-list items for now
-      res = htmlEditor->DeleteNode(child);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv = htmlEditor->DeleteNode(child);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
   // Delete the now-empty list
-  res = htmlEditor->RemoveBlockContainer(aList);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = htmlEditor->RemoveBlockContainer(aList);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::ConfirmSelectionInBody()
 {
   // get the body
@@ -7820,138 +7892,141 @@ HTMLEditRules::ConfirmSelectionInBody()
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<Selection> selection = mHTMLEditor->GetSelection();
   NS_ENSURE_STATE(selection);
 
   // get the selection start location
   nsCOMPtr<nsIDOMNode> selNode, temp, parent;
   int32_t selOffset;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(selection,
-                                                    getter_AddRefs(selNode),
-                                                    &selOffset);
-  if (NS_FAILED(res)) {
-    return res;
+  nsresult rv =
+    mHTMLEditor->GetStartNodeAndOffset(selection,
+                                       getter_AddRefs(selNode), &selOffset);
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   temp = selNode;
 
   // check that selNode is inside body
   while (temp && !TextEditUtils::IsBody(temp)) {
-    res = temp->GetParentNode(getter_AddRefs(parent));
+    temp->GetParentNode(getter_AddRefs(parent));
     temp = parent;
   }
 
   // if we aren't in the body, force the issue
   if (!temp)
   {
 //    uncomment this to see when we get bad selections
 //    NS_NOTREACHED("selection not in body");
     selection->Collapse(rootElement, 0);
   }
 
   // get the selection end location
   NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = mHTMLEditor->GetEndNodeAndOffset(selection,
+                                        getter_AddRefs(selNode), &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   temp = selNode;
 
   // check that selNode is inside body
   while (temp && !TextEditUtils::IsBody(temp)) {
-    res = temp->GetParentNode(getter_AddRefs(parent));
+    rv = temp->GetParentNode(getter_AddRefs(parent));
     temp = parent;
   }
 
   // if we aren't in the body, force the issue
   if (!temp)
   {
 //    uncomment this to see when we get bad selections
 //    NS_NOTREACHED("selection not in body");
     selection->Collapse(rootElement, 0);
   }
 
-  return res;
+  // XXX This is the result of the last call of GetParentNode(), it doesn't
+  //     make sense...
+  return rv;
 }
 
 nsresult
 HTMLEditRules::UpdateDocChangeRange(nsRange* aRange)
 {
-  nsresult res = NS_OK;
-
   // first make sure aRange is in the document.  It might not be if
   // portions of our editting action involved manipulating nodes
   // prior to placing them in the document (e.g., populating a list item
   // before placing it in its list)
   nsCOMPtr<nsIDOMNode> startNode;
-  res = aRange->GetStartContainer(getter_AddRefs(startNode));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = aRange->GetStartContainer(getter_AddRefs(startNode));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(mHTMLEditor);
   if (!mHTMLEditor->IsDescendantOfRoot(startNode)) {
     // just return - we don't need to adjust mDocChangeRange in this case
     return NS_OK;
   }
 
   if (!mDocChangeRange)
   {
     // clone aRange.
     mDocChangeRange = aRange->CloneRange();
   }
   else
   {
     int16_t result;
 
     // compare starts of ranges
-    res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, aRange, &result);
-    if (res == NS_ERROR_NOT_INITIALIZED) {
+    rv = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START,
+                                                aRange, &result);
+    if (rv == NS_ERROR_NOT_INITIALIZED) {
       // This will happen is mDocChangeRange is non-null, but the range is
       // uninitialized. In this case we'll set the start to aRange start.
       // The same test won't be needed further down since after we've set
       // the start the range will be collapsed to that point.
       result = 1;
-      res = NS_OK;
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      rv = NS_OK;
+    }
+    NS_ENSURE_SUCCESS(rv, rv);
     if (result > 0)  // positive result means mDocChangeRange start is after aRange start
     {
       int32_t startOffset;
-      res = aRange->GetStartOffset(&startOffset);
-      NS_ENSURE_SUCCESS(res, res);
-      res = mDocChangeRange->SetStart(startNode, startOffset);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = aRange->GetStartOffset(&startOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = mDocChangeRange->SetStart(startNode, startOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // compare ends of ranges
-    res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, aRange, &result);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END,
+                                                aRange, &result);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (result < 0)  // negative result means mDocChangeRange end is before aRange end
     {
       nsCOMPtr<nsIDOMNode> endNode;
       int32_t endOffset;
-      res = aRange->GetEndContainer(getter_AddRefs(endNode));
-      NS_ENSURE_SUCCESS(res, res);
-      res = aRange->GetEndOffset(&endOffset);
-      NS_ENSURE_SUCCESS(res, res);
-      res = mDocChangeRange->SetEnd(endNode, endOffset);
-      NS_ENSURE_SUCCESS(res, res);
-    }
-  }
-  return res;
+      rv = aRange->GetEndContainer(getter_AddRefs(endNode));
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = aRange->GetEndOffset(&endOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
+      rv = mDocChangeRange->SetEnd(endNode, endOffset);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+  }
+  return NS_OK;
 }
 
 nsresult
 HTMLEditRules::InsertMozBRIfNeeded(nsINode& aNode)
 {
   if (!IsBlockNode(aNode)) {
     return NS_OK;
   }
 
   bool isEmpty;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->IsEmptyNode(&aNode, &isEmpty);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mHTMLEditor->IsEmptyNode(&aNode, &isEmpty);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!isEmpty) {
     return NS_OK;
   }
 
   return CreateMozBR(aNode.AsDOMNode(), 0);
 }
 
 NS_IMETHODIMP
@@ -7968,20 +8043,19 @@ HTMLEditRules::DidCreateNode(const nsASt
                              nsIDOMNode* aParent,
                              int32_t aPosition,
                              nsresult aResult)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
   // assumption that Join keeps the righthand node
-  nsresult res = mUtilRange->SelectNode(aNode);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SelectNode(aNode);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::WillInsertNode(nsIDOMNode* aNode,
                               nsIDOMNode* aParent,
                               int32_t aPosition)
 {
   return NS_OK;
@@ -7991,32 +8065,30 @@ NS_IMETHODIMP
 HTMLEditRules::DidInsertNode(nsIDOMNode* aNode,
                              nsIDOMNode* aParent,
                              int32_t aPosition,
                              nsresult aResult)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
-  nsresult res = mUtilRange->SelectNode(aNode);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SelectNode(aNode);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::WillDeleteNode(nsIDOMNode* aChild)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
-  nsresult res = mUtilRange->SelectNode(aChild);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SelectNode(aChild);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::DidDeleteNode(nsIDOMNode* aChild,
                              nsresult aResult)
 {
   return NS_OK;
 }
@@ -8032,53 +8104,50 @@ NS_IMETHODIMP
 HTMLEditRules::DidSplitNode(nsIDOMNode* aExistingRightNode,
                             int32_t aOffset,
                             nsIDOMNode* aNewLeftNode,
                             nsresult aResult)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
-  nsresult res = mUtilRange->SetStart(aNewLeftNode, 0);
-  NS_ENSURE_SUCCESS(res, res);
-  res = mUtilRange->SetEnd(aExistingRightNode, 0);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SetStart(aNewLeftNode, 0);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mUtilRange->SetEnd(aExistingRightNode, 0);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::WillJoinNodes(nsIDOMNode* aLeftNode,
                              nsIDOMNode* aRightNode,
                              nsIDOMNode* aParent)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
   // remember split point
-  nsresult res = EditorBase::GetLengthOfDOMNode(aLeftNode, mJoinOffset);
-  return res;
+  return EditorBase::GetLengthOfDOMNode(aLeftNode, mJoinOffset);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::DidJoinNodes(nsIDOMNode* aLeftNode,
                             nsIDOMNode* aRightNode,
                             nsIDOMNode* aParent,
                             nsresult aResult)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
   // assumption that Join keeps the righthand node
-  nsresult res = mUtilRange->SetStart(aRightNode, mJoinOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = mUtilRange->SetEnd(aRightNode, mJoinOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SetStart(aRightNode, mJoinOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mUtilRange->SetEnd(aRightNode, mJoinOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::WillInsertText(nsIDOMCharacterData* aTextNode,
                               int32_t aOffset,
                               const nsAString& aString)
 {
   return NS_OK;
@@ -8090,22 +8159,21 @@ HTMLEditRules::DidInsertText(nsIDOMChara
                              const nsAString& aString,
                              nsresult aResult)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
   int32_t length = aString.Length();
   nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode);
-  nsresult res = mUtilRange->SetStart(theNode, aOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = mUtilRange->SetEnd(theNode, aOffset+length);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SetStart(theNode, aOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mUtilRange->SetEnd(theNode, aOffset+length);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::WillDeleteText(nsIDOMCharacterData* aTextNode,
                               int32_t aOffset,
                               int32_t aLength)
 {
   return NS_OK;
@@ -8116,22 +8184,21 @@ HTMLEditRules::DidDeleteText(nsIDOMChara
                              int32_t aOffset,
                              int32_t aLength,
                              nsresult aResult)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
   nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode);
-  nsresult res = mUtilRange->SetStart(theNode, aOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = mUtilRange->SetEnd(theNode, aOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  nsresult rv = mUtilRange->SetStart(theNode, aOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mUtilRange->SetEnd(theNode, aOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::WillDeleteSelection(nsISelection* aSelection)
 {
   if (!mListenerEnabled) {
     return NS_OK;
   }
@@ -8139,30 +8206,29 @@ HTMLEditRules::WillDeleteSelection(nsISe
     return NS_ERROR_INVALID_ARG;
   }
   RefPtr<Selection> selection = aSelection->AsSelection();
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode;
   int32_t selOffset;
 
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->GetStartNodeAndOffset(selection,
-                                                    getter_AddRefs(selNode),
-                                                    &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = mUtilRange->SetStart(selNode, selOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    mHTMLEditor->GetStartNodeAndOffset(selection,
+                                       getter_AddRefs(selNode), &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mUtilRange->SetStart(selNode, selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(selNode),
-                                         &selOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = mUtilRange->SetEnd(selNode, selOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = UpdateDocChangeRange(mUtilRange);
-  return res;
+  rv = mHTMLEditor->GetEndNodeAndOffset(selection,
+                                        getter_AddRefs(selNode), &selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = mUtilRange->SetEnd(selNode, selOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return UpdateDocChangeRange(mUtilRange);
 }
 
 NS_IMETHODIMP
 HTMLEditRules::DidDeleteSelection(nsISelection *aSelection)
 {
   return NS_OK;
 }
 
@@ -8176,17 +8242,16 @@ HTMLEditRules::RemoveAlignment(nsIDOMNod
                                bool aChildrenOnly)
 {
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   NS_ENSURE_STATE(mHTMLEditor);
   if (mHTMLEditor->IsTextNode(aNode) || HTMLEditUtils::IsTable(aNode)) {
     return NS_OK;
   }
-  nsresult res = NS_OK;
 
   nsCOMPtr<nsIDOMNode> child = aNode,tmp;
   if (aChildrenOnly)
   {
     aNode->GetFirstChild(getter_AddRefs(child));
   }
   NS_ENSURE_STATE(mHTMLEditor);
   bool useCSS = mHTMLEditor->IsCSSEnabled();
@@ -8198,62 +8263,71 @@ HTMLEditRules::RemoveAlignment(nsIDOMNod
       child->GetNextSibling(getter_AddRefs(tmp));
     }
     else
     {
       tmp = nullptr;
     }
     bool isBlock;
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->NodeIsBlockStatic(child, &isBlock);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = mHTMLEditor->NodeIsBlockStatic(child, &isBlock);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (EditorBase::NodeIsType(child, nsGkAtoms::center)) {
       // the current node is a CENTER element
       // first remove children's alignment
-      res = RemoveAlignment(child, aAlignType, true);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = RemoveAlignment(child, aAlignType, true);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       // we may have to insert BRs in first and last position of element's children
       // if the nodes before/after are not blocks and not BRs
-      res = MakeSureElemStartsOrEndsOnCR(child);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = MakeSureElemStartsOrEndsOnCR(child);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       // now remove the CENTER container
       NS_ENSURE_STATE(mHTMLEditor);
       nsCOMPtr<Element> childAsElement = do_QueryInterface(child);
       NS_ENSURE_STATE(childAsElement);
-      res = mHTMLEditor->RemoveContainer(childAsElement);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->RemoveContainer(childAsElement);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else if (isBlock || HTMLEditUtils::IsHR(child)) {
       // the current node is a block element
       nsCOMPtr<nsIDOMElement> curElem = do_QueryInterface(child);
       if (HTMLEditUtils::SupportsAlignAttr(child)) {
         // remove the ALIGN attribute if this element can have it
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->RemoveAttribute(curElem, NS_LITERAL_STRING("align"));
-        NS_ENSURE_SUCCESS(res, res);
+        rv = mHTMLEditor->RemoveAttribute(curElem, NS_LITERAL_STRING("align"));
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       if (useCSS)
       {
         if (HTMLEditUtils::IsTable(child) || HTMLEditUtils::IsHR(child)) {
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->SetAttributeOrEquivalent(curElem, NS_LITERAL_STRING("align"), aAlignType, false);
+          rv = mHTMLEditor->SetAttributeOrEquivalent(curElem,
+                                                     NS_LITERAL_STRING("align"),
+                                                     aAlignType, false);
+          if (NS_WARN_IF(NS_FAILED(rv))) {
+            return rv;
+          }
         } else {
           nsAutoString dummyCssValue;
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->mCSSEditUtils->RemoveCSSInlineStyle(child,
-            nsGkAtoms::textAlign, dummyCssValue);
+          rv = mHTMLEditor->mCSSEditUtils->RemoveCSSInlineStyle(
+                                             child,
+                                             nsGkAtoms::textAlign,
+                                             dummyCssValue);
+          if (NS_WARN_IF(NS_FAILED(rv))) {
+            return rv;
+          }
         }
-        NS_ENSURE_SUCCESS(res, res);
       }
       if (!HTMLEditUtils::IsTable(child)) {
         // unless this is a table, look at children
-        res = RemoveAlignment(child, aAlignType, true);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = RemoveAlignment(child, aAlignType, true);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
     child = tmp;
   }
   return NS_OK;
 }
 
 // Let's insert a BR as first (resp. last) child of aNode if its
@@ -8262,54 +8336,58 @@ HTMLEditRules::RemoveAlignment(nsIDOMNod
 nsresult
 HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode* aNode,
                                             bool aStarts)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> child;
-  nsresult res;
   if (aStarts)
   {
     NS_ENSURE_STATE(mHTMLEditor);
     child = GetAsDOMNode(mHTMLEditor->GetFirstEditableChild(*node));
   }
   else
   {
     NS_ENSURE_STATE(mHTMLEditor);
     child = GetAsDOMNode(mHTMLEditor->GetLastEditableChild(*node));
   }
   NS_ENSURE_TRUE(child, NS_OK);
   bool isChildBlock;
   NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->NodeIsBlockStatic(child, &isChildBlock);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = mHTMLEditor->NodeIsBlockStatic(child, &isChildBlock);
+  NS_ENSURE_SUCCESS(rv, rv);
   bool foundCR = false;
   if (isChildBlock || TextEditUtils::IsBreak(child)) {
     foundCR = true;
   } else {
     nsCOMPtr<nsIDOMNode> sibling;
     if (aStarts)
     {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetPriorHTMLSibling(aNode, address_of(sibling));
+      rv = mHTMLEditor->GetPriorHTMLSibling(aNode, address_of(sibling));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
     else
     {
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->GetNextHTMLSibling(aNode, address_of(sibling));
-    }
-    NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->GetNextHTMLSibling(aNode, address_of(sibling));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
     if (sibling)
     {
       bool isBlock;
       NS_ENSURE_STATE(mHTMLEditor);
-      res = mHTMLEditor->NodeIsBlockStatic(sibling, &isBlock);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = mHTMLEditor->NodeIsBlockStatic(sibling, &isBlock);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (isBlock || TextEditUtils::IsBreak(sibling)) {
         foundCR = true;
       }
     }
     else
     {
       foundCR = true;
     }
@@ -8319,63 +8397,62 @@ HTMLEditRules::MakeSureElemStartsOrEndsO
     int32_t offset = 0;
     if (!aStarts) {
       nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
       NS_ENSURE_STATE(node);
       offset = node->GetChildCount();
     }
     nsCOMPtr<nsIDOMNode> brNode;
     NS_ENSURE_STATE(mHTMLEditor);
-    res = mHTMLEditor->CreateBR(aNode, offset, address_of(brNode));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = mHTMLEditor->CreateBR(aNode, offset, address_of(brNode));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode* aNode)
 {
-  nsresult res = MakeSureElemStartsOrEndsOnCR(aNode, false);
-  NS_ENSURE_SUCCESS(res, res);
-  res = MakeSureElemStartsOrEndsOnCR(aNode, true);
-  return res;
+  nsresult rv = MakeSureElemStartsOrEndsOnCR(aNode, false);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return MakeSureElemStartsOrEndsOnCR(aNode, true);
 }
 
 nsresult
 HTMLEditRules::AlignBlock(Element& aElement,
                           const nsAString& aAlignType,
                           ContentsOnly aContentsOnly)
 {
   if (!IsBlockNode(aElement) && !aElement.IsHTMLElement(nsGkAtoms::hr)) {
     // We deal only with blocks; early way out
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mHTMLEditor);
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
 
-  nsresult res = RemoveAlignment(aElement.AsDOMNode(), aAlignType,
-                                 aContentsOnly == ContentsOnly::yes);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = RemoveAlignment(aElement.AsDOMNode(), aAlignType,
+                                aContentsOnly == ContentsOnly::yes);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_NAMED_LITERAL_STRING(attr, "align");
   if (htmlEditor->IsCSSEnabled()) {
     // Let's use CSS alignment; we use margin-left and margin-right for tables
     // and text-align for other block-level elements
-    res = htmlEditor->SetAttributeOrEquivalent(
-      static_cast<nsIDOMElement*>(aElement.AsDOMNode()), attr, aAlignType,
-      false);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = htmlEditor->SetAttributeOrEquivalent(
+                       static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
+                       attr, aAlignType, false);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     // HTML case; this code is supposed to be called ONLY if the element
     // supports the align attribute but we'll never know...
     if (HTMLEditUtils::SupportsAlignAttr(aElement.AsDOMNode())) {
-      res =
-        htmlEditor->SetAttribute(static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
-                                 attr, aAlignType);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->SetAttribute(
+                         static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
+                         attr, aAlignType);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::ChangeIndentation(Element& aElement,
                                  Change aChange)
@@ -8432,18 +8509,18 @@ HTMLEditRules::ChangeIndentation(Element
   // Remove unnecessary divs
   if (!aElement.IsHTMLElement(nsGkAtoms::div) ||
       &aElement == htmlEditor->GetActiveEditingHost() ||
       !htmlEditor->IsDescendantOfEditorRoot(&aElement) ||
       HTMLEditor::HasAttributes(&aElement)) {
     return NS_OK;
   }
 
-  nsresult res = htmlEditor->RemoveContainer(&aElement);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = htmlEditor->RemoveContainer(&aElement);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
                                     bool* aCancel,
                                     bool* aHandled)
@@ -8459,65 +8536,65 @@ HTMLEditRules::WillAbsolutePosition(Sele
   *aHandled = true;
 
   nsCOMPtr<Element> focusElement = htmlEditor->GetSelectionContainer();
   if (focusElement && HTMLEditUtils::IsImage(focusElement)) {
     mNewBlock = focusElement;
     return NS_OK;
   }
 
-  nsresult res = NormalizeSelection(&aSelection);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = NormalizeSelection(&aSelection);
+  NS_ENSURE_SUCCESS(rv, rv);
   AutoSelectionRestorer selectionRestorer(&aSelection, htmlEditor);
 
   // Convert the selection ranges into "promoted" selection ranges: this
   // basically just expands the range to include the immediate block parent,
   // and then further expands to include any ancestors whose children are all
   // in the range.
 
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
   GetPromotedRanges(aSelection, arrayOfRanges,
                     EditAction::setAbsolutePosition);
 
   // Use these ranges to contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  res = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
-                             EditAction::setAbsolutePosition);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
+                            EditAction::setAbsolutePosition);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // If nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // Get selection location
     NS_ENSURE_STATE(aSelection.GetRangeAt(0) &&
                     aSelection.GetRangeAt(0)->GetStartParent());
     OwningNonNull<nsINode> parent =
       *aSelection.GetRangeAt(0)->GetStartParent();
     int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
 
     // Make sure we can put a block here
-    res = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = SplitAsNeeded(*nsGkAtoms::div, parent, offset);
+    NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<Element> positionedDiv =
       htmlEditor->CreateNode(nsGkAtoms::div, parent, offset);
     NS_ENSURE_STATE(positionedDiv);
     // Remember our new block for postprocessing
     mNewBlock = positionedDiv;
     // Delete anything that was in the list of nodes
     while (!arrayOfNodes.IsEmpty()) {
       OwningNonNull<nsINode> curNode = arrayOfNodes[0];
-      res = htmlEditor->DeleteNode(curNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->DeleteNode(curNode);
+      NS_ENSURE_SUCCESS(rv, rv);
       arrayOfNodes.RemoveElementAt(0);
     }
     // Put selection in new block
-    res = aSelection.Collapse(positionedDiv, 0);
+    *aHandled = true;
+    rv = aSelection.Collapse(positionedDiv, 0);
     // Don't restore the selection
     selectionRestorer.Abort();
-    *aHandled = true;
-    NS_ENSURE_SUCCESS(res, res);
+    NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   // Okay, now go through all the nodes and put them in a blockquote, or
   // whatever is appropriate.  Woohoo!
   nsCOMPtr<Element> curList, curPositionedDiv, indentedLI;
   for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) {
     // Here's where we actually figure out what to do
@@ -8539,36 +8616,36 @@ HTMLEditRules::WillAbsolutePosition(Sele
       // Check to see if curList is still appropriate.  Which it is if curNode
       // is still right after it in the same list.
       if (curList) {
         sibling = htmlEditor->GetPriorHTMLSibling(curNode);
       }
 
       if (!curList || (sibling && sibling != curList)) {
         // Create a new nested list of correct type
-        res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
-                            offset);
-        NS_ENSURE_SUCCESS(res, res);
+        rv =
+          SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         if (!curPositionedDiv) {
           nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
           int32_t parentOffset = curParentParent
             ? curParentParent->IndexOf(curParent) : -1;
           curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParentParent,
                                                     parentOffset);
           mNewBlock = curPositionedDiv;
         }
         curList = htmlEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                          curPositionedDiv, -1);
         NS_ENSURE_STATE(curList);
         // curList is now the correct thing to put curNode in.  Remember our
         // new block for postprocessing.
       }
       // Tuck the node into the end of the active list
-      res = htmlEditor->MoveNode(curNode, curList, -1);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = htmlEditor->MoveNode(curNode, curList, -1);
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       // Not a list item, use blockquote?  If we are inside a list item, we
       // don't want to blockquote, we want to sublist the list item.  We may
       // have several nodes listed in the array of nodes to act on, that are in
       // the same list item.  Since we only want to indent that li once, we
       // must keep track of the most recent indented list item, and not indent
       // it if we find another node to act on that is still inside the same li.
       nsCOMPtr<Element> listItem = IsInListItem(curNode);
@@ -8582,59 +8659,59 @@ HTMLEditRules::WillAbsolutePosition(Sele
         // Check to see if curList is still appropriate.  Which it is if
         // curNode is still right after it in the same list.
         if (curList) {
           sibling = htmlEditor->GetPriorHTMLSibling(curNode);
         }
 
         if (!curList || (sibling && sibling != curList)) {
           // Create a new nested list of correct type
-          res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
-                              offset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent,
+                             offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           if (!curPositionedDiv) {
             nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode();
             int32_t parentOffset = curParentParent ?
               curParentParent->IndexOf(curParent) : -1;
             curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div,
                                                       curParentParent,
                                                       parentOffset);
             mNewBlock = curPositionedDiv;
           }
           curList = htmlEditor->CreateNode(curParent->NodeInfo()->NameAtom(),
                                            curPositionedDiv, -1);
           NS_ENSURE_STATE(curList);
         }
-        res = htmlEditor->MoveNode(listItem, curList, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->MoveNode(listItem, curList, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
         // Remember we indented this li
         indentedLI = listItem;
       } else {
         // Need to make a div to put things in if we haven't already
 
         if (!curPositionedDiv) {
           if (curNode->IsHTMLElement(nsGkAtoms::div)) {
             curPositionedDiv = curNode->AsElement();
             mNewBlock = curPositionedDiv;
             curList = nullptr;
             continue;
           }
-          res = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
-          NS_ENSURE_SUCCESS(res, res);
+          rv = SplitAsNeeded(*nsGkAtoms::div, curParent, offset);
+          NS_ENSURE_SUCCESS(rv, rv);
           curPositionedDiv = htmlEditor->CreateNode(nsGkAtoms::div, curParent,
                                                     offset);
           NS_ENSURE_STATE(curPositionedDiv);
           // Remember our new block for postprocessing
           mNewBlock = curPositionedDiv;
           // curPositionedDiv is now the correct thing to put curNode in
         }
 
         // Tuck the node into the end of the active blockquote
-        res = htmlEditor->MoveNode(curNode, curPositionedDiv, -1);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = htmlEditor->MoveNode(curNode, curPositionedDiv, -1);
+        NS_ENSURE_SUCCESS(rv, rv);
         // Forget curList, if any
         curList = nullptr;
       }
     }
   }
   return NS_OK;
 }
 
@@ -8657,19 +8734,19 @@ HTMLEditRules::WillRemoveAbsolutePositio
 
   // initialize out param
   // we want to ignore aCancel from WillInsert()
   *aCancel = false;
   *aHandled = true;
 
   nsCOMPtr<nsIDOMElement>  elt;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res =
+  nsresult rv =
     mHTMLEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt));
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_STATE(mHTMLEditor);
   AutoSelectionRestorer selectionRestorer(aSelection, mHTMLEditor);
 
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<nsIHTMLAbsPosEditor> absPosHTMLEditor = mHTMLEditor;
   return absPosHTMLEditor->AbsolutelyPositionElement(elt, false);
 }
@@ -8685,19 +8762,19 @@ HTMLEditRules::WillRelativeChangeZIndex(
 
   // initialize out param
   // we want to ignore aCancel from WillInsert()
   *aCancel = false;
   *aHandled = true;
 
   nsCOMPtr<nsIDOMElement>  elt;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res =
+  nsresult rv =
     mHTMLEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt));
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_STATE(mHTMLEditor);
   AutoSelectionRestorer selectionRestorer(aSelection, mHTMLEditor);
 
   NS_ENSURE_STATE(mHTMLEditor);
   nsCOMPtr<nsIHTMLAbsPosEditor> absPosHTMLEditor = mHTMLEditor;
   int32_t zIndex;
   return absPosHTMLEditor->RelativeChangeElementZIndex(elt, aChange, &zIndex);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1068,21 +1068,21 @@ HTMLEditor::TabInTable(bool inIsShift,
 
   // find enclosing table
   nsCOMPtr<Element> table = GetEnclosingTable(cellElement);
   NS_ENSURE_TRUE(table, NS_OK);
 
   // advance to next cell
   // first create an iterator over the table
   nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
-  nsresult res = iter->Init(table);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = iter->Init(table);
+  NS_ENSURE_SUCCESS(rv, rv);
   // position iter at block
-  res = iter->PositionAt(cellElement);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = iter->PositionAt(cellElement);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsINode> node;
   do {
     if (inIsShift) {
       iter->Prev();
     } else {
       iter->Next();
     }
@@ -1095,33 +1095,33 @@ HTMLEditor::TabInTable(bool inIsShift,
       *outHandled = true;
       return NS_OK;
     }
   } while (!iter->IsDone());
 
   if (!(*outHandled) && !inIsShift) {
     // If we haven't handled it yet, then we must have run off the end of the
     // table.  Insert a new row.
-    res = InsertTableRow(1, true);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = InsertTableRow(1, true);
+    NS_ENSURE_SUCCESS(rv, rv);
     *outHandled = true;
     // Put selection in right place.  Use table code to get selection and index
     // to new row...
     RefPtr<Selection> selection;
     nsCOMPtr<nsIDOMElement> tblElement, cell;
     int32_t row;
-    res = GetCellContext(getter_AddRefs(selection),
-                         getter_AddRefs(tblElement),
-                         getter_AddRefs(cell),
-                         nullptr, nullptr,
-                         &row, nullptr);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetCellContext(getter_AddRefs(selection),
+                        getter_AddRefs(tblElement),
+                        getter_AddRefs(cell),
+                        nullptr, nullptr,
+                        &row, nullptr);
+    NS_ENSURE_SUCCESS(rv, rv);
     // ...so that we can ask for first cell in that row...
-    res = GetCellAt(tblElement, row, 0, getter_AddRefs(cell));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetCellAt(tblElement, row, 0, getter_AddRefs(cell));
+    NS_ENSURE_SUCCESS(rv, rv);
     // ...and then set selection there.  (Note that normally you should use
     // CollapseSelectionToDeepestNonTableFirstChild(), but we know cell is an
     // empty new cell, so this works fine)
     if (cell) {
       selection->Collapse(cell, 0);
     }
   }
 
@@ -1241,27 +1241,27 @@ HTMLEditor::ReplaceHeadContentsWithHTML(
            err.ErrorCodeAsInt());
 #endif
     return err.StealNSResult();
   }
   NS_ENSURE_TRUE(docfrag, NS_ERROR_NULL_POINTER);
 
   // First delete all children in head
   while (nsCOMPtr<nsIContent> child = headNode->GetFirstChild()) {
-    nsresult res = DeleteNode(child);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = DeleteNode(child);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Now insert the new nodes
   int32_t offsetOfNewNode = 0;
 
   // Loop over the contents of the fragment and move into the document
   while (nsCOMPtr<nsIContent> child = docfrag->GetFirstChild()) {
-    nsresult res = InsertNode(*child, *headNode, offsetOfNewNode++);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = InsertNode(*child, *headNode, offsetOfNewNode++);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString)
 {
@@ -1310,77 +1310,104 @@ HTMLEditor::RebuildDocumentFromSource(co
   }
 
   // Time to change the document
   AutoEditBatch beginBatching(this);
 
   nsReadingIterator<char16_t> endtotal;
   aSourceString.EndReading(endtotal);
 
-  nsresult res;
   if (foundhead) {
     if (foundclosehead) {
-      res = ReplaceHeadContentsWithHTML(Substring(beginhead, beginclosehead));
+      nsresult rv =
+        ReplaceHeadContentsWithHTML(Substring(beginhead, beginclosehead));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else if (foundbody) {
-      res = ReplaceHeadContentsWithHTML(Substring(beginhead, beginbody));
+      nsresult rv =
+        ReplaceHeadContentsWithHTML(Substring(beginhead, beginbody));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else {
       // XXX Without recourse to some parser/content sink/docshell hackery we
       // don't really know where the head ends and the body begins so we assume
       // that there is no body
-      res = ReplaceHeadContentsWithHTML(Substring(beginhead, endtotal));
+      nsresult rv = ReplaceHeadContentsWithHTML(Substring(beginhead, endtotal));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
   } else {
     nsReadingIterator<char16_t> begintotal;
     aSourceString.BeginReading(begintotal);
     NS_NAMED_LITERAL_STRING(head, "<head>");
     if (foundclosehead) {
-      res = ReplaceHeadContentsWithHTML(head + Substring(begintotal,
-                                                         beginclosehead));
+      nsresult rv =
+        ReplaceHeadContentsWithHTML(head + Substring(begintotal,
+                                                     beginclosehead));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else if (foundbody) {
-      res = ReplaceHeadContentsWithHTML(head + Substring(begintotal,
-                                                         beginbody));
+      nsresult rv = ReplaceHeadContentsWithHTML(head + Substring(begintotal,
+                                                                 beginbody));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else {
       // XXX Without recourse to some parser/content sink/docshell hackery we
       // don't really know where the head ends and the body begins so we assume
       // that there is no head
-      res = ReplaceHeadContentsWithHTML(head);
+      nsresult rv = ReplaceHeadContentsWithHTML(head);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
   }
-  NS_ENSURE_SUCCESS(res, res);
-
-  res = SelectAll();
-  NS_ENSURE_SUCCESS(res, res);
+
+  nsresult rv = SelectAll();
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (!foundbody) {
     NS_NAMED_LITERAL_STRING(body, "<body>");
     // XXX Without recourse to some parser/content sink/docshell hackery we
     // don't really know where the head ends and the body begins
     if (foundclosehead) {
       // assume body starts after the head ends
-      res = LoadHTML(body + Substring(endclosehead, endtotal));
+      nsresult rv = LoadHTML(body + Substring(endclosehead, endtotal));
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else if (foundhead) {
       // assume there is no body
-      res = LoadHTML(body);
+      nsresult rv = LoadHTML(body);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     } else {
       // assume there is no head, the entire source is body
-      res = LoadHTML(body + aSourceString);
+      nsresult rv = LoadHTML(body + aSourceString);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
     }
-    NS_ENSURE_SUCCESS(res, res);
 
     nsCOMPtr<Element> divElement =
       CreateElementWithDefaults(NS_LITERAL_STRING("div"));
     NS_ENSURE_TRUE(divElement, NS_ERROR_FAILURE);
 
     CloneAttributes(bodyElement, divElement);
 
     return BeginningOfDocument();
   }
 
-  res = LoadHTML(Substring(beginbody, endtotal));
-  NS_ENSURE_SUCCESS(res, res);
+  rv = LoadHTML(Substring(beginbody, endtotal));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Now we must copy attributes user might have edited on the <body> tag
   // because InsertHTML (actually, CreateContextualFragment()) will never
   // return a body node in the DOM fragment
 
   // We already know where "<body" begins
   nsReadingIterator<char16_t> beginclosebody = beginbody;
   nsReadingIterator<char16_t> endclosebody;
@@ -1393,20 +1420,20 @@ HTMLEditor::RebuildDocumentFromSource(co
   // by replacing "body" with "div" so we get a node
   nsAutoString bodyTag;
   bodyTag.AssignLiteral("<div ");
   bodyTag.Append(Substring(endbody, endclosebody));
 
   RefPtr<nsRange> range = selection->GetRangeAt(0);
   NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
-  ErrorResult rv;
+  ErrorResult erv;
   RefPtr<DocumentFragment> docfrag =
-    range->CreateContextualFragment(bodyTag, rv);
-  NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
+    range->CreateContextualFragment(bodyTag, erv);
+  NS_ENSURE_TRUE(!erv.Failed(), erv.StealNSResult());
   NS_ENSURE_TRUE(docfrag, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIContent> child = docfrag->GetFirstChild();
   NS_ENSURE_TRUE(child && child->IsElement(), NS_ERROR_NULL_POINTER);
 
   // Copy all attributes from the div child to current body element
   CloneAttributes(bodyElement, child->AsElement());
 
@@ -1489,18 +1516,16 @@ HTMLEditor::NormalizeEOLInsertPosition(n
 
 NS_IMETHODIMP
 HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
                                      bool aDeleteSelection)
 {
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
-  nsresult res = NS_ERROR_NOT_INITIALIZED;
-
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
 
   ForceCompositionEnd();
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::insertElement,
@@ -1510,30 +1535,32 @@ HTMLEditor::InsertElementAtSelection(nsI
   if (!selection) {
     return NS_ERROR_FAILURE;
   }
 
   // hand off to the rules system, see if it has anything to say about this
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::insertElement);
   ruleInfo.insertElement = aElement;
-  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || (NS_FAILED(res))) return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
   if (!handled)
   {
     if (aDeleteSelection)
     {
       if (!IsBlockNode(element)) {
         // E.g., inserting an image.  In this case we don't need to delete any
         // inline wrappers before we do the insertion.  Otherwise we let
         // DeleteSelectionAndPrepareToCreateNode do the deletion for us, which
         // calls DeleteSelection with aStripWrappers = eStrip.
-        res = DeleteSelection(nsIEditor::eNone, nsIEditor::eNoStrip);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = DeleteSelection(nsIEditor::eNone, nsIEditor::eNoStrip);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
 
       nsresult result = DeleteSelectionAndPrepareToCreateNode();
       NS_ENSURE_SUCCESS(result, result);
     }
 
     // If deleting, selection will be collapsed.
     // so if not, we collapse it
@@ -1546,50 +1573,53 @@ HTMLEditor::InsertElementAtSelection(nsI
         selection->CollapseToStart();
       } else {
         selection->CollapseToEnd();
       }
     }
 
     nsCOMPtr<nsIDOMNode> parentSelectedNode;
     int32_t offsetForInsert;
-    res = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode));
+    rv = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode));
     // XXX: ERROR_HANDLING bad XPCOM usage
-    if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&offsetForInsert)) && parentSelectedNode)
-    {
+    if (NS_SUCCEEDED(rv) &&
+        NS_SUCCEEDED(selection->GetAnchorOffset(&offsetForInsert)) &&
+        parentSelectedNode) {
       // Adjust position based on the node we are going to insert.
       NormalizeEOLInsertPosition(element, address_of(parentSelectedNode),
                                  &offsetForInsert);
 
-      res = InsertNodeAtPoint(node, address_of(parentSelectedNode), &offsetForInsert, false);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = InsertNodeAtPoint(node, address_of(parentSelectedNode),
+                             &offsetForInsert, false);
+      NS_ENSURE_SUCCESS(rv, rv);
       // Set caret after element, but check for special case
       //  of inserting table-related elements: set in first cell instead
       if (!SetCaretInTableCell(aElement))
       {
-        res = SetCaretAfterElement(aElement);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = SetCaretAfterElement(aElement);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       // check for inserting a whole table at the end of a block. If so insert a br after it.
       if (HTMLEditUtils::IsTable(node)) {
         bool isLast;
-        res = IsLastEditableChild(node, &isLast);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = IsLastEditableChild(node, &isLast);
+        NS_ENSURE_SUCCESS(rv, rv);
         if (isLast)
         {
           nsCOMPtr<nsIDOMNode> brNode;
-          res = CreateBR(parentSelectedNode, offsetForInsert+1, address_of(brNode));
-          NS_ENSURE_SUCCESS(res, res);
+          rv = CreateBR(parentSelectedNode, offsetForInsert + 1,
+                        address_of(brNode));
+          NS_ENSURE_SUCCESS(rv, rv);
           selection->Collapse(parentSelectedNode, offsetForInsert+1);
         }
       }
     }
   }
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  rv = rules->DidDoAction(selection, &ruleInfo, rv);
+  return rv;
 }
 
 
 /**
  * InsertNodeAtPoint() attempts to insert aNode into the document, at a point
  * specified by {*ioParent,*ioOffset}.  Checks with strict dtd to see if
  * containment is allowed.  If not allowed, will attempt to find a parent in
  * the parent hierarchy of *ioParent that will accept aNode as a child.  If
@@ -1611,17 +1641,16 @@ HTMLEditor::InsertNodeAtPoint(nsIDOMNode
                               bool aNoEmptyNodes)
 {
   nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
   NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(ioParent, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(*ioParent, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(ioOffset, NS_ERROR_NULL_POINTER);
 
-  nsresult res = NS_OK;
   nsCOMPtr<nsIContent> parent = do_QueryInterface(*ioParent);
   NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIContent> topChild = parent;
   nsCOMPtr<nsIContent> origParent = parent;
 
   // Search up the parent chain to find a suitable container
   while (!CanContain(*parent, *node)) {
     // If the current parent is a root (body or table element)
@@ -1648,68 +1677,67 @@ HTMLEditor::InsertNodeAtPoint(nsIDOMNode
     int32_t offset = SplitNodeDeep(*topChild, *origParent, *ioOffset,
                                    aNoEmptyNodes ? EmptyContainers::no
                                                  : EmptyContainers::yes);
     NS_ENSURE_STATE(offset != -1);
     *ioParent = GetAsDOMNode(parent);
     *ioOffset = offset;
   }
   // Now we can insert the new node
-  res = InsertNode(*node, *parent, *ioOffset);
-  return res;
+  return InsertNode(*node, *parent, *ioOffset);
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectElement(nsIDOMElement* aElement)
 {
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_STATE(element || !aElement);
-  nsresult res = NS_ERROR_NULL_POINTER;
 
   // Must be sure that element is contained in the document body
-  if (IsDescendantOfEditorRoot(element)) {
-    RefPtr<Selection> selection = GetSelection();
-    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
-    nsCOMPtr<nsIDOMNode>parent;
-    res = aElement->GetParentNode(getter_AddRefs(parent));
-    if (NS_SUCCEEDED(res) && parent)
-    {
-      int32_t offsetInParent = GetChildOffset(aElement, parent);
-
-      // Collapse selection to just before desired element,
-      res = selection->Collapse(parent, offsetInParent);
-      if (NS_SUCCEEDED(res)) {
-        // then extend it to just after
-        res = selection->Extend(parent, offsetInParent + 1);
-      }
+  if (!IsDescendantOfEditorRoot(element)) {
+    return NS_ERROR_NULL_POINTER;
+  }
+
+  RefPtr<Selection> selection = GetSelection();
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
+  nsCOMPtr<nsIDOMNode>parent;
+  nsresult rv = aElement->GetParentNode(getter_AddRefs(parent));
+  if (NS_SUCCEEDED(rv) && parent) {
+    int32_t offsetInParent = GetChildOffset(aElement, parent);
+
+    // Collapse selection to just before desired element,
+    rv = selection->Collapse(parent, offsetInParent);
+    if (NS_SUCCEEDED(rv)) {
+      // then extend it to just after
+      rv = selection->Extend(parent, offsetInParent + 1);
     }
   }
-  return res;
+  return rv;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement)
 {
   nsCOMPtr<Element> element = do_QueryInterface(aElement);
   NS_ENSURE_STATE(element || !aElement);
-  nsresult res = NS_ERROR_NULL_POINTER;
 
   // Be sure the element is contained in the document body
-  if (aElement && IsDescendantOfEditorRoot(element)) {
-    RefPtr<Selection> selection = GetSelection();
-    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
-    nsCOMPtr<nsIDOMNode>parent;
-    res = aElement->GetParentNode(getter_AddRefs(parent));
-    NS_ENSURE_SUCCESS(res, res);
-    NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-    int32_t offsetInParent = GetChildOffset(aElement, parent);
-    // Collapse selection to just after desired element,
-    res = selection->Collapse(parent, offsetInParent + 1);
-  }
-  return res;
+  if (!aElement || !IsDescendantOfEditorRoot(element)) {
+    return NS_ERROR_NULL_POINTER;
+  }
+
+  RefPtr<Selection> selection = GetSelection();
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
+  nsCOMPtr<nsIDOMNode>parent;
+  nsresult rv = aElement->GetParentNode(getter_AddRefs(parent));
+  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
+  int32_t offsetInParent = GetChildOffset(aElement, parent);
+  // Collapse selection to just after desired element,
+  return selection->Collapse(parent, offsetInParent + 1);
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetParagraphFormat(const nsAString& aParagraphFormat)
 {
   nsAutoString tag; tag.Assign(aParagraphFormat);
   ToLowerCase(tag);
   if (tag.EqualsLiteral("dd") || tag.EqualsLiteral("dt"))
@@ -1729,43 +1757,39 @@ HTMLEditor::GetParagraphState(bool* aMix
 
   return htmlRules->GetParagraphState(aMixed, outFormat);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetBackgroundColorState(bool* aMixed,
                                     nsAString& aOutColor)
 {
-  nsresult res;
   if (IsCSSEnabled()) {
     // if we are in CSS mode, we have to check if the containing block defines
     // a background color
-    res = GetCSSBackgroundColorState(aMixed, aOutColor, true);
-  }
-  else {
-    // in HTML mode, we look only at page's background
-    res = GetHTMLBackgroundColorState(aMixed, aOutColor);
-  }
-  return res;
+    return GetCSSBackgroundColorState(aMixed, aOutColor, true);
+  }
+  // in HTML mode, we look only at page's background
+  return GetHTMLBackgroundColorState(aMixed, aOutColor);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetHighlightColorState(bool* aMixed,
                                    nsAString& aOutColor)
 {
-  nsresult res = NS_OK;
   *aMixed = false;
   aOutColor.AssignLiteral("transparent");
-  if (IsCSSEnabled()) {
-    // in CSS mode, text background can be added by the Text Highlight button
-    // we need to query the background of the selection without looking for
-    // the block container of the ranges in the selection
-    res = GetCSSBackgroundColorState(aMixed, aOutColor, false);
-  }
-  return res;
+  if (!IsCSSEnabled()) {
+    return NS_OK;
+  }
+
+  // in CSS mode, text background can be added by the Text Highlight button
+  // we need to query the background of the selection without looking for
+  // the block container of the ranges in the selection
+  return GetCSSBackgroundColorState(aMixed, aOutColor, false);
 }
 
 nsresult
 HTMLEditor::GetCSSBackgroundColorState(bool* aMixed,
                                        nsAString& aOutColor,
                                        bool aBlockLevel)
 {
   NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
@@ -1855,20 +1879,20 @@ HTMLEditor::GetHTMLBackgroundColorState(
   //TODO: We don't handle "mixed" correctly!
   NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
   *aMixed = false;
   aOutColor.Truncate();
 
   nsCOMPtr<nsIDOMElement> domElement;
   int32_t selectedCount;
   nsAutoString tagName;
-  nsresult res = GetSelectedOrParentTableElement(tagName,
-                                                 &selectedCount,
-                                                 getter_AddRefs(domElement));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetSelectedOrParentTableElement(tagName,
+                                                &selectedCount,
+                                                getter_AddRefs(domElement));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<dom::Element> element = do_QueryInterface(domElement);
 
   while (element) {
     // We are in a cell or selected table
     element->GetAttr(kNameSpaceID_None, nsGkAtoms::bgcolor, aOutColor);
 
     // Done if we have a color explicitly set
@@ -1948,17 +1972,16 @@ HTMLEditor::GetIndentState(bool* aCanInd
   return htmlRules->GetIndentState(aCanIndent, aCanOutdent);
 }
 
 NS_IMETHODIMP
 HTMLEditor::MakeOrChangeList(const nsAString& aListType,
                              bool entireList,
                              const nsAString& aBulletType)
 {
-  nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
@@ -1967,18 +1990,20 @@ HTMLEditor::MakeOrChangeList(const nsASt
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(EditAction::makeList);
   ruleInfo.blockType = &aListType;
   ruleInfo.entireList = entireList;
   ruleInfo.bulletType = &aBulletType;
-  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || (NS_FAILED(res))) return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
     bool isCollapsed = selection->Collapsed();
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
                    selection->GetRangeAt(0)->GetStartParent() &&
@@ -2008,29 +2033,27 @@ HTMLEditor::MakeOrChangeList(const nsASt
       }
 
       // make a list
       nsCOMPtr<Element> newList = CreateNode(listAtom, parent, offset);
       NS_ENSURE_STATE(newList);
       // make a list item
       nsCOMPtr<Element> newItem = CreateNode(nsGkAtoms::li, newList, 0);
       NS_ENSURE_STATE(newItem);
-      res = selection->Collapse(newItem,0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = selection->Collapse(newItem, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveList(const nsAString& aListType)
 {
-  nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
@@ -2039,79 +2062,81 @@ HTMLEditor::RemoveList(const nsAString& 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(EditAction::removeList);
   if (aListType.LowerCaseEqualsLiteral("ol"))
     ruleInfo.bOrdered = true;
   else  ruleInfo.bOrdered = false;
-  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || (NS_FAILED(res))) return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
   // no default behavior for this yet.  what would it mean?
 
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 nsresult
 HTMLEditor::MakeDefinitionItem(const nsAString& aItemType)
 {
-  nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::makeDefListItem,
                                nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(EditAction::makeDefListItem);
   ruleInfo.blockType = &aItemType;
-  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || (NS_FAILED(res))) return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
   if (!handled)
   {
     // todo: no default for now.  we count on rules to handle it.
   }
 
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 nsresult
 HTMLEditor::InsertBasicBlock(const nsAString& aBlockType)
 {
-  nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
 
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, EditAction::makeBasicBlock,
                                nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(EditAction::makeBasicBlock);
   ruleInfo.blockType = &aBlockType;
-  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || (NS_FAILED(res))) return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
     bool isCollapsed = selection->Collapsed();
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
                    selection->GetRangeAt(0)->GetStartParent() &&
@@ -2141,29 +2166,27 @@ HTMLEditor::InsertBasicBlock(const nsASt
         NS_ENSURE_STATE(offset != -1);
       }
 
       // make a block
       nsCOMPtr<Element> newBlock = CreateNode(blockAtom, parent, offset);
       NS_ENSURE_STATE(newBlock);
 
       // reposition selection to inside the block
-      res = selection->Collapse(newBlock,0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = selection->Collapse(newBlock, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
 
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 NS_IMETHODIMP
 HTMLEditor::Indent(const nsAString& aIndent)
 {
-  nsresult res;
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   bool cancel, handled;
   EditAction opID = EditAction::indent;
   if (aIndent.LowerCaseEqualsLiteral("outdent"))
@@ -2173,18 +2196,20 @@ HTMLEditor::Indent(const nsAString& aInd
   AutoEditBatch beginBatching(this);
   AutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   TextRulesInfo ruleInfo(opID);
-  res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || (NS_FAILED(res))) return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
 
   if (!handled)
   {
     // Do default - insert a blockquote node if selection collapsed
     bool isCollapsed = selection->Collapsed();
 
     NS_ENSURE_TRUE(selection->GetRangeAt(0) &&
                    selection->GetRangeAt(0)->GetStartParent() &&
@@ -2213,30 +2238,28 @@ HTMLEditor::Indent(const nsAString& aInd
           offset = SplitNodeDeep(*topChild, *node, offset);
           NS_ENSURE_STATE(offset != -1);
         }
 
         // make a blockquote
         nsCOMPtr<Element> newBQ = CreateNode(nsGkAtoms::blockquote, parent, offset);
         NS_ENSURE_STATE(newBQ);
         // put a space in it so layout will draw the list item
-        res = selection->Collapse(newBQ,0);
-        NS_ENSURE_SUCCESS(res, res);
-        res = InsertText(NS_LITERAL_STRING(" "));
-        NS_ENSURE_SUCCESS(res, res);
+        rv = selection->Collapse(newBQ, 0);
+        NS_ENSURE_SUCCESS(rv, rv);
+        rv = InsertText(NS_LITERAL_STRING(" "));
+        NS_ENSURE_SUCCESS(rv, rv);
         // reposition selection to before the space character
         NS_ENSURE_STATE(selection->GetRangeAt(0));
-        res = selection->Collapse(selection->GetRangeAt(0)->GetStartParent(),
-                                  0);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = selection->Collapse(selection->GetRangeAt(0)->GetStartParent(), 0);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 //TODO: IMPLEMENT ALIGNMENT!
 
 NS_IMETHODIMP
 HTMLEditor::Align(const nsAString& aAlignType)
 {
   // Protect the edit rules object from dying
@@ -2247,22 +2270,22 @@ HTMLEditor::Align(const nsAString& aAlig
 
   bool cancel, handled;
 
   // Find out if the selection is collapsed:
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   TextRulesInfo ruleInfo(EditAction::align);
   ruleInfo.alignType = &aAlignType;
-  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  if (cancel || NS_FAILED(res))
-    return res;
-
-  res = rules->DidDoAction(selection, &ruleInfo, res);
-  return res;
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  if (cancel || NS_FAILED(rv)) {
+    return rv;
+  }
+
+  return rules->DidDoAction(selection, &ruleInfo, rv);
 }
 
 already_AddRefed<Element>
 HTMLEditor::GetElementOrParentByTagName(const nsAString& aTagName,
                                         nsINode* aNode)
 {
   MOZ_ASSERT(!aTagName.IsEmpty());
 
@@ -2386,32 +2409,32 @@ HTMLEditor::GetSelectedElement(const nsA
   bool isNamedAnchorTag = IsNamedAnchorTag(TagName);
 
   nsCOMPtr<nsIDOMElement> selectedElement;
   RefPtr<nsRange> range = selection->GetRangeAt(0);
   NS_ENSURE_STATE(range);
 
   nsCOMPtr<nsIDOMNode> startParent;
   int32_t startOffset, endOffset;
-  nsresult res = range->GetStartContainer(getter_AddRefs(startParent));
-  NS_ENSURE_SUCCESS(res, res);
-  res = range->GetStartOffset(&startOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = range->GetStartContainer(getter_AddRefs(startParent));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = range->GetStartOffset(&startOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMNode> endParent;
-  res = range->GetEndContainer(getter_AddRefs(endParent));
-  NS_ENSURE_SUCCESS(res, res);
-  res = range->GetEndOffset(&endOffset);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = range->GetEndContainer(getter_AddRefs(endParent));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = range->GetEndOffset(&endOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Optimization for a single selected element
   if (startParent && startParent == endParent && (endOffset-startOffset) == 1)
   {
     nsCOMPtr<nsIDOMNode> selectedNode = GetChildAt(startParent, startOffset);
-    NS_ENSURE_SUCCESS(res, NS_OK);
+    NS_ENSURE_SUCCESS(rv, NS_OK);
     if (selectedNode)
     {
       selectedNode->GetNodeName(domTagName);
       ToLowerCase(domTagName);
 
       // Test for appropriate node type requested
       if (anyTag || (TagName == domTagName) ||
           (isLinkTag && HTMLEditUtils::IsLink(selectedNode)) ||
@@ -2425,47 +2448,50 @@ HTMLEditor::GetSelectedElement(const nsA
   if (!bNodeFound)
   {
     if (isLinkTag)
     {
       // Link tag is a special case - we return the anchor node
       //  found for any selection that is totally within a link,
       //  included a collapsed selection (just a caret in a link)
       nsCOMPtr<nsIDOMNode> anchorNode;
-      res = selection->GetAnchorNode(getter_AddRefs(anchorNode));
-      NS_ENSURE_SUCCESS(res, res);
+      rv = selection->GetAnchorNode(getter_AddRefs(anchorNode));
+      NS_ENSURE_SUCCESS(rv, rv);
       int32_t anchorOffset = -1;
       if (anchorNode)
         selection->GetAnchorOffset(&anchorOffset);
 
       nsCOMPtr<nsIDOMNode> focusNode;
-      res = selection->GetFocusNode(getter_AddRefs(focusNode));
-      NS_ENSURE_SUCCESS(res, res);
+      rv = selection->GetFocusNode(getter_AddRefs(focusNode));
+      NS_ENSURE_SUCCESS(rv, rv);
       int32_t focusOffset = -1;
       if (focusNode)
         selection->GetFocusOffset(&focusOffset);
 
       // Link node must be the same for both ends of selection
-      if (NS_SUCCEEDED(res) && anchorNode)
-      {
+      if (NS_SUCCEEDED(rv) && anchorNode) {
         nsCOMPtr<nsIDOMElement> parentLinkOfAnchor;
-        res = GetElementOrParentByTagName(NS_LITERAL_STRING("href"), anchorNode, getter_AddRefs(parentLinkOfAnchor));
+        rv = GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
+                                         anchorNode,
+                                         getter_AddRefs(parentLinkOfAnchor));
         // XXX: ERROR_HANDLING  can parentLinkOfAnchor be null?
-        if (NS_SUCCEEDED(res) && parentLinkOfAnchor)
-        {
+        if (NS_SUCCEEDED(rv) && parentLinkOfAnchor) {
           if (isCollapsed)
           {
             // We have just a caret in the link
             bNodeFound = true;
           } else if(focusNode)
           {  // Link node must be the same for both ends of selection
             nsCOMPtr<nsIDOMElement> parentLinkOfFocus;
-            res = GetElementOrParentByTagName(NS_LITERAL_STRING("href"), focusNode, getter_AddRefs(parentLinkOfFocus));
-            if (NS_SUCCEEDED(res) && parentLinkOfFocus == parentLinkOfAnchor)
+            rv = GetElementOrParentByTagName(NS_LITERAL_STRING("href"),
+                                             focusNode,
+                                             getter_AddRefs(parentLinkOfFocus));
+            if (NS_SUCCEEDED(rv) && parentLinkOfFocus == parentLinkOfAnchor) {
               bNodeFound = true;
+            }
           }
 
           // We found a link node parent
           if (bNodeFound) {
             // GetElementOrParentByTagName addref'd this, so we don't need to do it here
             *aReturn = parentLinkOfAnchor;
             NS_IF_ADDREF(*aReturn);
             return NS_OK;
@@ -2485,18 +2511,19 @@ HTMLEditor::GetSelectedElement(const nsA
       }
     }
 
     if (!isCollapsed)   // Don't bother to examine selection if it is collapsed
     {
       RefPtr<nsRange> currange = selection->GetRangeAt(0);
       if (currange) {
         nsCOMPtr<nsIContentIterator> iter =
-          do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
-        NS_ENSURE_SUCCESS(res, res);
+          do_CreateInstance("@mozilla.org/content/post-content-iterator;1",
+                            &rv);
+        NS_ENSURE_SUCCESS(rv, rv);
 
         iter->Init(currange);
         // loop through the content iterator for each content node
         while (!iter->IsDone())
         {
           // Query interface to cast nsIContent to nsIDOMNode
           //  then get tagType to compare to  aTagName
           // Clone node of each desired type and append it to the aDomFrag
@@ -2543,27 +2570,27 @@ HTMLEditor::GetSelectedElement(const nsA
         }
       } else {
         // Should never get here?
         isCollapsed = true;
         NS_WARNING("isCollapsed was FALSE, but no elements found in selection\n");
       }
     }
   }
-  if (bNodeFound) {
-    *aReturn = selectedElement;
-    if (selectedElement) {
-      // Getters must addref
-      NS_ADDREF(*aReturn);
-    }
-  } else {
-    res = NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
-  }
-
-  return res;
+
+  if (!bNodeFound) {
+    return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
+  }
+
+  *aReturn = selectedElement;
+  if (selectedElement) {
+    // Getters must addref
+    NS_ADDREF(*aReturn);
+  }
+  return rv;
 }
 
 already_AddRefed<Element>
 HTMLEditor::CreateElementWithDefaults(const nsAString& aTagName)
 {
   MOZ_ASSERT(!aTagName.IsEmpty());
 
   nsAutoString tagName(aTagName);
@@ -2605,20 +2632,21 @@ HTMLEditor::CreateElementWithDefaults(co
     }
     newElement->SetAttribute(NS_LITERAL_STRING("border"),
                              NS_LITERAL_STRING("1"), rv);
     if (NS_WARN_IF(rv.Failed())) {
       rv.SuppressException();
       return nullptr;
     }
   } else if (tagName.EqualsLiteral("td")) {
-    nsresult res = SetAttributeOrEquivalent(
+    nsresult rv =
+      SetAttributeOrEquivalent(
         static_cast<nsIDOMElement*>(newElement->AsDOMNode()),
         NS_LITERAL_STRING("valign"), NS_LITERAL_STRING("top"), true);
-    NS_ENSURE_SUCCESS(res, nullptr);
+    NS_ENSURE_SUCCESS(rv, nullptr);
   }
   // ADD OTHER TAGS HERE
 
   return newElement.forget();
 }
 
 NS_IMETHODIMP
 HTMLEditor::CreateElementWithDefaults(const nsAString& aTagName,
@@ -2651,18 +2679,18 @@ HTMLEditor::InsertLinkAroundSelection(ns
 
   // Be sure we were given an anchor element
   nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aAnchorElement);
   if (!anchor) {
     return NS_OK;
   }
 
   nsAutoString href;
-  nsresult res = anchor->GetHref(href);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = anchor->GetHref(href);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (href.IsEmpty()) {
     return NS_OK;
   }
 
   AutoEditBatch beginBatching(this);
 
   // Set all attributes found on the supplied anchor element
   nsCOMPtr<nsIDOMMozNamedAttrMap> attrMap;
@@ -2670,89 +2698,84 @@ HTMLEditor::InsertLinkAroundSelection(ns
   NS_ENSURE_TRUE(attrMap, NS_ERROR_FAILURE);
 
   uint32_t count;
   attrMap->GetLength(&count);
   nsAutoString name, value;
 
   for (uint32_t i = 0; i < count; ++i) {
     nsCOMPtr<nsIDOMAttr> attribute;
-    res = attrMap->Item(i, getter_AddRefs(attribute));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = attrMap->Item(i, getter_AddRefs(attribute));
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (attribute) {
       // We must clear the string buffers
       //   because GetName, GetValue appends to previous string!
       name.Truncate();
       value.Truncate();
 
-      res = attribute->GetName(name);
-      NS_ENSURE_SUCCESS(res, res);
-
-      res = attribute->GetValue(value);
-      NS_ENSURE_SUCCESS(res, res);
-
-      res = SetInlineProperty(nsGkAtoms::a, name, value);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = attribute->GetName(name);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = attribute->GetValue(value);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = SetInlineProperty(nsGkAtoms::a, name, value);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditor::SetHTMLBackgroundColor(const nsAString& aColor)
 {
   NS_PRECONDITION(mDocWeak, "Missing Editor DOM Document");
 
   // Find a selected or enclosing table element to set background on
   nsCOMPtr<nsIDOMElement> element;
   int32_t selectedCount;
   nsAutoString tagName;
-  nsresult res = GetSelectedOrParentTableElement(tagName, &selectedCount,
-                                                 getter_AddRefs(element));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = GetSelectedOrParentTableElement(tagName, &selectedCount,
+                                                getter_AddRefs(element));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   bool setColor = !aColor.IsEmpty();
 
   NS_NAMED_LITERAL_STRING(bgcolor, "bgcolor");
   if (element)
   {
     if (selectedCount > 0)
     {
       // Traverse all selected cells
       nsCOMPtr<nsIDOMElement> cell;
-      res = GetFirstSelectedCell(nullptr, getter_AddRefs(cell));
-      if (NS_SUCCEEDED(res) && cell)
-      {
+      rv = GetFirstSelectedCell(nullptr, getter_AddRefs(cell));
+      if (NS_SUCCEEDED(rv) && cell) {
         while(cell)
         {
-          if (setColor)
-            res = SetAttribute(cell, bgcolor, aColor);
-          else
-            res = RemoveAttribute(cell, bgcolor);
-          if (NS_FAILED(res)) break;
+          rv = setColor ? SetAttribute(cell, bgcolor, aColor) :
+                          RemoveAttribute(cell, bgcolor);
+          if (NS_FAILED(rv)) {
+            return rv;
+          }
 
           GetNextSelectedCell(nullptr, getter_AddRefs(cell));
         }
-        return res;
+        return NS_OK;
       }
     }
     // If we failed to find a cell, fall through to use originally-found element
   } else {
     // No table element -- set the background color on the body tag
     element = do_QueryInterface(GetRoot());
     NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
   }
   // Use the editor method that goes through the transaction system
-  if (setColor)
-    res = SetAttribute(element, bgcolor, aColor);
-  else
-    res = RemoveAttribute(element, bgcolor);
-
-  return res;
+  return setColor ? SetAttribute(element, bgcolor, aColor) :
+                    RemoveAttribute(element, bgcolor);
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetBodyAttribute(const nsAString& aAttribute,
                              const nsAString& aValue)
 {
   // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level
 
@@ -3102,18 +3125,18 @@ HTMLEditor::GetEmbeddedObjects(nsIArray*
 }
 
 NS_IMETHODIMP
 HTMLEditor::DeleteSelectionImpl(EDirection aAction,
                                 EStripWrappers aStripWrappers)
 {
   MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
 
-  nsresult res = EditorBase::DeleteSelectionImpl(aAction, aStripWrappers);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = EditorBase::DeleteSelectionImpl(aAction, aStripWrappers);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // If we weren't asked to strip any wrappers, we're done.
   if (aStripWrappers == eNoStrip) {
     return NS_OK;
   }
 
   RefPtr<Selection> selection = GetSelection();
   // Just checking that the selection itself is collapsed doesn't seem to work
@@ -3130,32 +3153,32 @@ HTMLEditor::DeleteSelectionImpl(EDirecti
   nsCOMPtr<nsIContent> blockParent = content;
   while (blockParent && !IsBlockNode(blockParent)) {
     blockParent = blockParent->GetParent();
   }
   if (!blockParent) {
     return NS_OK;
   }
   bool emptyBlockParent;
-  res = IsEmptyNode(blockParent, &emptyBlockParent);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = IsEmptyNode(blockParent, &emptyBlockParent);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (emptyBlockParent) {
     return NS_OK;
   }
 
   if (content && !IsBlockNode(content) && !content->Length() &&
       content->IsEditable() && content != content->GetEditingHost()) {
     while (content->GetParent() && !IsBlockNode(content->GetParent()) &&
            content->GetParent()->Length() == 1 &&
            content->GetParent()->IsEditable() &&
            content->GetParent() != content->GetEditingHost()) {
       content = content->GetParent();
     }
-    res = DeleteNode(content);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = DeleteNode(content);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditor::DeleteNode(nsINode* aNode)
 {
@@ -3257,19 +3280,19 @@ HTMLEditor::DoContentInserted(nsIDocumen
       if (aInsertedOrAppended == eAppended) {
         // Count all the appended nodes
         nsIContent* sibling = aChild->GetNextSibling();
         while (sibling) {
           endIndex++;
           sibling = sibling->GetNextSibling();
         }
       }
-      nsresult res = range->Set(aContainer, aIndexInContainer,
-                                aContainer, endIndex);
-      if (NS_SUCCEEDED(res)) {
+      nsresult rv = range->Set(aContainer, aIndexInContainer,
+                               aContainer, endIndex);
+      if (NS_SUCCEEDED(rv)) {
         mInlineSpellChecker->SpellCheckRange(range);
       }
     }
   }
 }
 
 void
 HTMLEditor::ContentRemoved(nsIDocument* aDocument,
@@ -3363,51 +3386,52 @@ NS_IMETHODIMP
 HTMLEditor::GetHeadContentsAsHTML(nsAString& aOutputString)
 {
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // Save current selection
   AutoSelectionRestorer selectionRestorer(selection, this);
 
-  nsresult res = SetSelectionAroundHeadChildren(selection, mDocWeak);
-  NS_ENSURE_SUCCESS(res, res);
-
-  res = OutputToString(NS_LITERAL_STRING("text/html"),
-                       nsIDocumentEncoder::OutputSelectionOnly,
-                       aOutputString);
-  if (NS_SUCCEEDED(res))
+  nsresult rv = SetSelectionAroundHeadChildren(selection, mDocWeak);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = OutputToString(NS_LITERAL_STRING("text/html"),
+                      nsIDocumentEncoder::OutputSelectionOnly,
+                      aOutputString);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+
+  // Selection always includes <body></body>,
+  //  so terminate there
+  nsReadingIterator<char16_t> findIter,endFindIter;
+  aOutputString.BeginReading(findIter);
+  aOutputString.EndReading(endFindIter);
+  //counting on our parser to always lower case!!!
+  if (CaseInsensitiveFindInReadable(NS_LITERAL_STRING("<body"),
+                                    findIter, endFindIter))
   {
-    // Selection always includes <body></body>,
-    //  so terminate there
-    nsReadingIterator<char16_t> findIter,endFindIter;
-    aOutputString.BeginReading(findIter);
-    aOutputString.EndReading(endFindIter);
-    //counting on our parser to always lower case!!!
-    if (CaseInsensitiveFindInReadable(NS_LITERAL_STRING("<body"),
-                                      findIter, endFindIter))
+    nsReadingIterator<char16_t> beginIter;
+    aOutputString.BeginReading(beginIter);
+    int32_t offset = Distance(beginIter, findIter);//get the distance
+
+    nsWritingIterator<char16_t> writeIter;
+    aOutputString.BeginWriting(writeIter);
+    // Ensure the string ends in a newline
+    char16_t newline ('\n');
+    findIter.advance(-1);
+    if (offset ==0 || (offset >0 &&  (*findIter) != newline)) //check for 0
     {
-      nsReadingIterator<char16_t> beginIter;
-      aOutputString.BeginReading(beginIter);
-      int32_t offset = Distance(beginIter, findIter);//get the distance
-
-      nsWritingIterator<char16_t> writeIter;
-      aOutputString.BeginWriting(writeIter);
-      // Ensure the string ends in a newline
-      char16_t newline ('\n');
-      findIter.advance(-1);
-      if (offset ==0 || (offset >0 &&  (*findIter) != newline)) //check for 0
-      {
-        writeIter.advance(offset);
-        *writeIter = newline;
-        aOutputString.Truncate(offset+1);
-      }
+      writeIter.advance(offset);
+      *writeIter = newline;
+      aOutputString.Truncate(offset+1);
     }
   }
-  return res;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::DebugUnitTests(int32_t* outNumTests,
                            int32_t* outNumTestsFailed)
 {
 #ifdef DEBUG
   NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
@@ -3483,22 +3507,19 @@ HTMLEditor::StartOperation(EditAction op
  */
 NS_IMETHODIMP
 HTMLEditor::EndOperation()
 {
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   // post processing
-  nsresult res = NS_OK;
-  if (rules) {
-    res = rules->AfterEdit(mAction, mDirection);
-  }
+  nsresult rv = rules ? rules->AfterEdit(mAction, mDirection) : NS_OK;
   EditorBase::EndOperation();  // will clear mAction, mDirection
-  return res;
+  return rv;
 }
 
 bool
 HTMLEditor::TagCanContainTag(nsIAtom& aParentTag,
                              nsIAtom& aChildTag)
 {
   nsIParserService* parserService = nsContentUtils::GetParserService();
 
@@ -3550,18 +3571,18 @@ HTMLEditor::SelectEntireDocument(Selecti
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
   // get editor root node
   nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
 
   // is doc empty?
   bool bDocIsEmpty;
-  nsresult res = rules->DocumentIsEmpty(&bDocIsEmpty);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = rules->DocumentIsEmpty(&bDocIsEmpty);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (bDocIsEmpty)
   {
     // if its empty dont select entire doc - that would select the bogus node
     return aSelection->Collapse(rootElement, 0);
   }
 
   return EditorBase::SelectEntireDocument(aSelection);
@@ -3880,18 +3901,18 @@ HTMLEditor::RemoveBlockContainer(nsICont
         // Insert br node
         nsCOMPtr<Element> br = CreateBR(&aNode, 0);
         NS_ENSURE_STATE(br);
       }
     }
   }
 
   // Now remove container
-  nsresult res = RemoveContainer(&aNode);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = RemoveContainer(&aNode);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 /**
  * GetPriorHTMLSibling() returns the previous editable sibling, if there is
  * one within the parent.
  */
@@ -4255,28 +4276,28 @@ HTMLEditor::IsVisTextNode(nsIContent* aN
   MOZ_ASSERT(outIsEmptyNode);
 
   *outIsEmptyNode = true;
 
   uint32_t length = aNode->TextLength();
   if (aSafeToAskFrames)
   {
     nsCOMPtr<nsISelectionController> selCon;
-    nsresult res = GetSelectionController(getter_AddRefs(selCon));
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = GetSelectionController(getter_AddRefs(selCon));
+    NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
     bool isVisible = false;
     // ask the selection controller for information about whether any
     // of the data in the node is really rendered.  This is really
     // something that frames know about, but we aren't supposed to talk to frames.
     // So we put a call in the selection controller interface, since it's already
     // in bed with frames anyway.  (this is a fix for bug 22227, and a
     // partial fix for bug 46209)
-    res = selCon->CheckVisibilityContent(aNode, 0, length, &isVisible);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = selCon->CheckVisibilityContent(aNode, 0, length, &isVisible);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (isVisible)
     {
       *outIsEmptyNode = false;
     }
   }
   else if (length)
   {
     if (aNode->TextIsOnlyWhitespace())
@@ -4435,102 +4456,91 @@ HTMLEditor::IsEmptyNodeImpl(nsINode* aNo
 nsresult
 HTMLEditor::SetAttributeOrEquivalent(nsIDOMElement* aElement,
                                      const nsAString& aAttribute,
                                      const nsAString& aValue,
                                      bool aSuppressTransaction)
 {
   nsAutoScriptBlocker scriptBlocker;
 
-  nsresult res = NS_OK;
   if (IsCSSEnabled() && mCSSEditUtils) {
     int32_t count;
-    res = mCSSEditUtils->SetCSSEquivalentToHTMLStyle(aElement, nullptr,
-                                                     &aAttribute, &aValue,
-                                                     &count,
-                                                     aSuppressTransaction);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mCSSEditUtils->SetCSSEquivalentToHTMLStyle(aElement, nullptr,
+                                                 &aAttribute, &aValue,
+                                                 &count,
+                                                 aSuppressTransaction);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (count) {
       // we found an equivalence ; let's remove the HTML attribute itself if it is set
       nsAutoString existingValue;
       bool wasSet = false;
-      res = GetAttributeValue(aElement, aAttribute, existingValue, &wasSet);
-      NS_ENSURE_SUCCESS(res, res);
-      if (wasSet) {
-        if (aSuppressTransaction)
-          res = aElement->RemoveAttribute(aAttribute);
-        else
-          res = RemoveAttribute(aElement, aAttribute);
+      rv = GetAttributeValue(aElement, aAttribute, existingValue, &wasSet);
+      NS_ENSURE_SUCCESS(rv, rv);
+      if (!wasSet) {
+        return NS_OK;
       }
+      return aSuppressTransaction ? aElement->RemoveAttribute(aAttribute) :
+                                    RemoveAttribute(aElement, aAttribute);
     }
-    else {
-      // count is an integer that represents the number of CSS declarations applied to the
-      // element. If it is zero, we found no equivalence in this implementation for the
-      // attribute
-      if (aAttribute.EqualsLiteral("style")) {
-        // if it is the style attribute, just add the new value to the existing style
-        // attribute's value
-        nsAutoString existingValue;
-        bool wasSet = false;
-        res = GetAttributeValue(aElement, NS_LITERAL_STRING("style"), existingValue, &wasSet);
-        NS_ENSURE_SUCCESS(res, res);
-        existingValue.Append(' ');
-        existingValue.Append(aValue);
-        if (aSuppressTransaction)
-          res = aElement->SetAttribute(aAttribute, existingValue);
-        else
-          res = SetAttribute(aElement, aAttribute, existingValue);
-      }
-      else {
-        // we have no CSS equivalence for this attribute and it is not the style
-        // attribute; let's set it the good'n'old HTML way
-        if (aSuppressTransaction)
-          res = aElement->SetAttribute(aAttribute, aValue);
-        else
-          res = SetAttribute(aElement, aAttribute, aValue);
-      }
+
+    // count is an integer that represents the number of CSS declarations applied to the
+    // element. If it is zero, we found no equivalence in this implementation for the
+    // attribute
+    if (aAttribute.EqualsLiteral("style")) {
+      // if it is the style attribute, just add the new value to the existing style
+      // attribute's value
+      nsAutoString existingValue;
+      bool wasSet = false;
+      nsresult rv = GetAttributeValue(aElement, NS_LITERAL_STRING("style"),
+                                      existingValue, &wasSet);
+      NS_ENSURE_SUCCESS(rv, rv);
+      existingValue.Append(' ');
+      existingValue.Append(aValue);
+      return aSuppressTransaction ?
+        aElement->SetAttribute(aAttribute, existingValue) :
+        SetAttribute(aElement, aAttribute, existingValue);
     }
-  }
-  else {
-    // we are not in an HTML+CSS editor; let's set the attribute the HTML way
-    if (aSuppressTransaction)
-      res = aElement->SetAttribute(aAttribute, aValue);
-    else
-      res = SetAttribute(aElement, aAttribute, aValue);
-  }
-  return res;
+
+    // we have no CSS equivalence for this attribute and it is not the style
+    // attribute; let's set it the good'n'old HTML way
+    return aSuppressTransaction ? aElement->SetAttribute(aAttribute, aValue) :
+                                  SetAttribute(aElement, aAttribute, aValue);
+  }
+
+  // we are not in an HTML+CSS editor; let's set the attribute the HTML way
+  return aSuppressTransaction ? aElement->SetAttribute(aAttribute, aValue) :
+                                SetAttribute(aElement, aAttribute, aValue);
 }
 
 nsresult
 HTMLEditor::RemoveAttributeOrEquivalent(nsIDOMElement* aElement,
                                         const nsAString& aAttribute,
                                         bool aSuppressTransaction)
 {
   nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
   NS_ENSURE_TRUE(element, NS_OK);
 
   nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute);
   MOZ_ASSERT(attribute);
 
-  nsresult res = NS_OK;
   if (IsCSSEnabled() && mCSSEditUtils) {
-    res = mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
+    nsresult rv =
+      mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
         element, nullptr, &aAttribute, nullptr, aSuppressTransaction);
-    NS_ENSURE_SUCCESS(res, res);
-  }
-
-  if (element->HasAttr(kNameSpaceID_None, attribute)) {
-    if (aSuppressTransaction) {
-      res = element->UnsetAttr(kNameSpaceID_None, attribute,
-                               /* aNotify = */ true);
-    } else {
-      res = RemoveAttribute(aElement, aAttribute);
-    }
-  }
-  return res;
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
+  if (!element->HasAttr(kNameSpaceID_None, attribute)) {
+    return NS_OK;
+  }
+
+  return aSuppressTransaction ?
+    element->UnsetAttr(kNameSpaceID_None, attribute, /* aNotify = */ true) :
+    RemoveAttribute(aElement, aAttribute);
 }
 
 nsresult
 HTMLEditor::SetIsCSSEnabled(bool aIsCSSPrefChecked)
 {
   if (!mCSSEditUtils) {
     return NS_ERROR_NOT_INITIALIZED;
   }
@@ -4568,18 +4578,18 @@ HTMLEditor::SetCSSBackgroundColor(const 
   AutoEditBatch batchIt(this);
   AutoRules beginRulesSniffing(this, EditAction::insertElement,
                                nsIEditor::eNext);
   AutoSelectionRestorer selectionRestorer(selection, this);
   AutoTransactionsConserveSelection dontSpazMySelection(this);
 
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::setTextProperty);
-  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     NS_NAMED_LITERAL_STRING(bgcolor, "bgcolor");
     for (uint32_t i = 0; i < selection->RangeCount(); i++) {
       RefPtr<nsRange> range = selection->GetRangeAt(i);
       NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
       nsCOMPtr<Element> cachedBlockParent;
@@ -4629,21 +4639,21 @@ HTMLEditor::SetCSSBackgroundColor(const 
 
         OwningNonNull<nsIContentIterator> iter =
           NS_NewContentSubtreeIterator();
 
         nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
         nsCOMPtr<nsINode> node;
 
         // Iterate range and build up array
-        res = iter->Init(range);
+        rv = iter->Init(range);
         // Init returns an error if no nodes in range.  This can easily happen
         // with the subtree iterator if the selection doesn't contain any
         // *whole* nodes.
-        if (NS_SUCCEEDED(res)) {
+        if (NS_SUCCEEDED(rv)) {
           for (; !iter->IsDone(); iter->Next()) {
             node = do_QueryInterface(iter->GetCurrentNode());
             NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
             if (IsEditable(node)) {
               arrayOfNodes.AppendElement(*node);
             }
           }
@@ -4685,37 +4695,34 @@ HTMLEditor::SetCSSBackgroundColor(const 
                                                        false);
           }
         }
       }
     }
   }
   if (!cancel) {
     // Post-process
-    res = rules->DidDoAction(selection, &ruleInfo, res);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetBackgroundColor(const nsAString& aColor)
 {
-  nsresult res;
   if (IsCSSEnabled()) {
     // if we are in CSS mode, we have to apply the background color to the
     // containing block (or the body if we have no block-level element in
     // the document)
-    res = SetCSSBackgroundColor(aColor);
-  }
-  else {
-    // but in HTML mode, we can only set the document's background color
-    res = SetHTMLBackgroundColor(aColor);
-  }
-  return res;
+    return SetCSSBackgroundColor(aColor);
+  }
+
+  // but in HTML mode, we can only set the document's background color
+  return SetHTMLBackgroundColor(aColor);
 }
 
 /**
  * NodesSameType() does these nodes have the same tag?
  */
 bool
 HTMLEditor::AreNodesSameType(nsIContent* aNode1,
                              nsIContent* aNode2)
@@ -4740,38 +4747,36 @@ nsresult
 HTMLEditor::CopyLastEditableChildStyles(nsIDOMNode* aPreviousBlock,
                                         nsIDOMNode* aNewBlock,
                                         Element** aOutBrNode)
 {
   nsCOMPtr<nsINode> newBlock = do_QueryInterface(aNewBlock);
   NS_ENSURE_STATE(newBlock || !aNewBlock);
   *aOutBrNode = nullptr;
   nsCOMPtr<nsIDOMNode> child, tmp;
-  nsresult res;
   // first, clear out aNewBlock.  Contract is that we want only the styles from previousBlock.
-  res = aNewBlock->GetFirstChild(getter_AddRefs(child));
-  while (NS_SUCCEEDED(res) && child)
-  {
-    res = DeleteNode(child);
-    NS_ENSURE_SUCCESS(res, res);
-    res = aNewBlock->GetFirstChild(getter_AddRefs(child));
+  nsresult rv = aNewBlock->GetFirstChild(getter_AddRefs(child));
+  while (NS_SUCCEEDED(rv) && child) {
+    rv = DeleteNode(child);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = aNewBlock->GetFirstChild(getter_AddRefs(child));
   }
   // now find and clone the styles
   child = aPreviousBlock;
   tmp = aPreviousBlock;
   while (tmp) {
     child = tmp;
     nsCOMPtr<nsINode> child_ = do_QueryInterface(child);
     NS_ENSURE_STATE(child_ || !child);
     tmp = GetAsDOMNode(GetLastEditableChild(*child_));
   }
   while (child && TextEditUtils::IsBreak(child)) {
     nsCOMPtr<nsIDOMNode> priorNode;
-    res = GetPriorHTMLNode(child, address_of(priorNode));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetPriorHTMLNode(child, address_of(priorNode));
+    NS_ENSURE_SUCCESS(rv, rv);
     child = priorNode;
   }
   nsCOMPtr<Element> newStyles, deepestStyle;
   nsCOMPtr<nsINode> childNode = do_QueryInterface(child);
   nsCOMPtr<Element> childElement;
   if (childNode) {
     childElement = childNode->IsElement() ? childNode->AsElement()
                                           : childNode->GetParentElement();
@@ -4823,31 +4828,32 @@ HTMLEditor::GetElementOrigin(nsIDOMEleme
   aY = nsPresContext::AppUnitsToIntCSSPixels(off.y);
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditor::EndUpdateViewBatch()
 {
-  nsresult res = EditorBase::EndUpdateViewBatch();
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = EditorBase::EndUpdateViewBatch();
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (mUpdateCount) {
+    return NS_OK;
+  }
 
   // We may need to show resizing handles or update existing ones after
   // all transactions are done. This way of doing is preferred to DOM
   // mutation events listeners because all the changes the user can apply
   // to a document may result in multiple events, some of them quite hard
   // to listen too (in particular when an ancestor of the selection is
   // changed but the selection itself is not changed).
-  if (mUpdateCount == 0) {
-    RefPtr<Selection> selection = GetSelection();
-    NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
-    res = CheckSelectionStateForAnonymousButtons(selection);
-  }
-  return res;
+  RefPtr<Selection> selection = GetSelection();
+  NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
+  return CheckSelectionStateForAnonymousButtons(selection);
 }
 
 NS_IMETHODIMP
 HTMLEditor::GetSelectionContainer(nsIDOMElement** aReturn)
 {
   nsCOMPtr<nsIDOMElement> container =
     static_cast<nsIDOMElement*>(GetAsDOMNode(GetSelectionContainer()));
   NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
@@ -4875,19 +4881,19 @@ HTMLEditor::GetSelectionContainer()
 
       nsCOMPtr<nsINode> startContainer = range->GetStartParent();
       int32_t startOffset = range->StartOffset();
       nsCOMPtr<nsINode> endContainer = range->GetEndParent();
       int32_t endOffset = range->EndOffset();
 
       if (startContainer == endContainer && startOffset + 1 == endOffset) {
         nsCOMPtr<nsIDOMElement> focusElement;
-        nsresult res = GetSelectedElement(EmptyString(),
-                                          getter_AddRefs(focusElement));
-        NS_ENSURE_SUCCESS(res, nullptr);
+        nsresult rv = GetSelectedElement(EmptyString(),
+                                         getter_AddRefs(focusElement));
+        NS_ENSURE_SUCCESS(rv, nullptr);
         if (focusElement) {
           focusNode = do_QueryInterface(focusElement);
         }
       }
       if (!focusNode) {
         focusNode = range->GetCommonAncestor();
       }
     } else {
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -134,23 +134,23 @@ ResizerMouseMotionListener::HandleEvent(
  * mozilla::HTMLEditor
  ******************************************************************************/
 
 already_AddRefed<Element>
 HTMLEditor::CreateResizer(int16_t aLocation,
                           nsIDOMNode* aParentNode)
 {
   nsCOMPtr<nsIDOMElement> retDOM;
-  nsresult res = CreateAnonymousElement(NS_LITERAL_STRING("span"),
-                                        aParentNode,
-                                        NS_LITERAL_STRING("mozResizer"),
-                                        false,
-                                        getter_AddRefs(retDOM));
+  nsresult rv = CreateAnonymousElement(NS_LITERAL_STRING("span"),
+                                       aParentNode,
+                                       NS_LITERAL_STRING("mozResizer"),
+                                       false,
+                                       getter_AddRefs(retDOM));
 
-  NS_ENSURE_SUCCESS(res, nullptr);
+  NS_ENSURE_SUCCESS(rv, nullptr);
   NS_ENSURE_TRUE(retDOM, nullptr);
 
   // add the mouse listener so we can detect a click on a resizer
   nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(retDOM);
   evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mEventListener,
                               true);
 
   nsAutoString locationStr;
@@ -179,19 +179,19 @@ HTMLEditor::CreateResizer(int16_t aLocat
       locationStr = kBottom;
       break;
     case nsIHTMLObjectResizer::eBottomRight:
       locationStr = kBottomRight;
       break;
   }
 
   nsCOMPtr<Element> ret = do_QueryInterface(retDOM);
-  res = ret->SetAttr(kNameSpaceID_None, nsGkAtoms::anonlocation, locationStr,
-                     true);
-  NS_ENSURE_SUCCESS(res, nullptr);
+  rv = ret->SetAttr(kNameSpaceID_None, nsGkAtoms::anonlocation, locationStr,
+                    true);
+  NS_ENSURE_SUCCESS(rv, nullptr);
   return ret.forget();
 }
 
 already_AddRefed<Element>
 HTMLEditor::CreateShadow(nsIDOMNode* aParentNode,
                          nsIDOMElement* aOriginalObject)
 {
   // let's create an image through the element factory
@@ -266,51 +266,53 @@ HTMLEditor::SetAllResizersPosition()
 }
 
 NS_IMETHODIMP
 HTMLEditor::RefreshResizers()
 {
   // nothing to do if resizers are not displayed...
   NS_ENSURE_TRUE(mResizedObject, NS_OK);
 
-  nsresult res = GetPositionAndDimensions(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)),
-                                          mResizedObjectX,
-                                          mResizedObjectY,
-                                          mResizedObjectWidth,
-                                          mResizedObjectHeight,
-                                          mResizedObjectBorderLeft,
-                                          mResizedObjectBorderTop,
-                                          mResizedObjectMarginLeft,
-                                          mResizedObjectMarginTop);
+  nsresult rv =
+    GetPositionAndDimensions(
+      static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)),
+      mResizedObjectX,
+      mResizedObjectY,
+      mResizedObjectWidth,
+      mResizedObjectHeight,
+      mResizedObjectBorderLeft,
+      mResizedObjectBorderTop,
+      mResizedObjectMarginLeft,
+      mResizedObjectMarginTop);
 
-  NS_ENSURE_SUCCESS(res, res);
-  res = SetAllResizersPosition();
-  NS_ENSURE_SUCCESS(res, res);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = SetAllResizersPosition();
+  NS_ENSURE_SUCCESS(rv, rv);
   return SetShadowPosition(mResizingShadow, mResizedObject,
                            mResizedObjectX, mResizedObjectY);
 }
 
 NS_IMETHODIMP
 HTMLEditor::ShowResizers(nsIDOMElement* aResizedElement)
 {
-  nsresult res = ShowResizersInner(aResizedElement);
-  if (NS_FAILED(res))
+  nsresult rv = ShowResizersInner(aResizedElement);
+  if (NS_FAILED(rv)) {
     HideResizers();
-  return res;
+  }
+  return rv;
 }
 
 nsresult
 HTMLEditor::ShowResizersInner(nsIDOMElement* aResizedElement)
 {
   NS_ENSURE_ARG_POINTER(aResizedElement);
-  nsresult res;
 
   nsCOMPtr<nsIDOMNode> parentNode;
-  res = aResizedElement->GetParentNode(getter_AddRefs(parentNode));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = aResizedElement->GetParentNode(getter_AddRefs(parentNode));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (mResizedObject) {
     NS_ERROR("call HideResizers first");
     return NS_ERROR_UNEXPECTED;
   }
   mResizedObject = do_QueryInterface(aResizedElement);
   NS_ENSURE_STATE(mResizedObject);
 
@@ -329,57 +331,59 @@ HTMLEditor::ShowResizersInner(nsIDOMElem
 
   mBottomLeftHandle = CreateResizer(nsIHTMLObjectResizer::eBottomLeft,  parentNode);
   NS_ENSURE_TRUE(mBottomLeftHandle, NS_ERROR_FAILURE);
   mBottomHandle = CreateResizer(nsIHTMLObjectResizer::eBottom,      parentNode);
   NS_ENSURE_TRUE(mBottomHandle, NS_ERROR_FAILURE);
   mBottomRightHandle = CreateResizer(nsIHTMLObjectResizer::eBottomRight, parentNode);
   NS_ENSURE_TRUE(mBottomRightHandle, NS_ERROR_FAILURE);
 
-  res = GetPositionAndDimensions(aResizedElement,
-                                 mResizedObjectX,
-                                 mResizedObjectY,
-                                 mResizedObjectWidth,
-                                 mResizedObjectHeight,
-                                 mResizedObjectBorderLeft,
-                                 mResizedObjectBorderTop,
-                                 mResizedObjectMarginLeft,
-                                 mResizedObjectMarginTop);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetPositionAndDimensions(aResizedElement,
+                                mResizedObjectX,
+                                mResizedObjectY,
+                                mResizedObjectWidth,
+                                mResizedObjectHeight,
+                                mResizedObjectBorderLeft,
+                                mResizedObjectBorderTop,
+                                mResizedObjectMarginLeft,
+                                mResizedObjectMarginTop);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // and let's set their absolute positions in the document
-  res = SetAllResizersPosition();
-  NS_ENSURE_SUCCESS(res, res);
+  rv = SetAllResizersPosition();
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // now, let's create the resizing shadow
   mResizingShadow = CreateShadow(parentNode, aResizedElement);
   NS_ENSURE_TRUE(mResizingShadow, NS_ERROR_FAILURE);
   // and set its position
-  res = SetShadowPosition(mResizingShadow, mResizedObject,
-                          mResizedObjectX, mResizedObjectY);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = SetShadowPosition(mResizingShadow, mResizedObject,
+                         mResizedObjectX, mResizedObjectY);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // and then the resizing info tooltip
   mResizingInfo = CreateResizingInfo(parentNode);
   NS_ENSURE_TRUE(mResizingInfo, NS_ERROR_FAILURE);
 
   // and listen to the "resize" event on the window first, get the
   // window from the document...
   nsCOMPtr<nsIDocument> doc = GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(doc->GetWindow());
   if (!target) { return NS_ERROR_NULL_POINTER; }
 
   mResizeEventListenerP = new DocumentResizeEventListener(this);
   if (!mResizeEventListenerP) { return NS_ERROR_OUT_OF_MEMORY; }
-  res = target->AddEventListener(NS_LITERAL_STRING("resize"), mResizeEventListenerP, false);
-
+  rv = target->AddEventListener(NS_LITERAL_STRING("resize"),
+                                mResizeEventListenerP, false);
+  // XXX Even when it failed to add event listener, should we need to set
+  //     _moz_resizing attribute?
   aResizedElement->SetAttribute(NS_LITERAL_STRING("_moz_resizing"), NS_LITERAL_STRING("true"));
-  return res;
+  return rv;
 }
 
 NS_IMETHODIMP
 HTMLEditor::HideResizers()
 {
   NS_ENSURE_TRUE(mResizedObject, NS_OK);
 
   // get the presshell's document observer interface.
@@ -441,33 +445,35 @@ HTMLEditor::HideResizers()
                                 true);
     mActivatedHandle = nullptr;
   }
 
   // don't forget to remove the listeners !
 
   nsCOMPtr<nsIDOMEventTarget> target = GetDOMEventTarget();
 
-  DebugOnly<nsresult> res;
   if (target && mMouseMotionListenerP)
   {
-    res = target->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
-                                      mMouseMotionListenerP, true);
-    NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove mouse motion listener");
+    DebugOnly<nsresult> rv =
+      target->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
+                                  mMouseMotionListenerP, true);
+    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener");
   }
   mMouseMotionListenerP = nullptr;
 
   nsCOMPtr<nsIDocument> doc = GetDocument();
   if (!doc) { return NS_ERROR_NULL_POINTER; }
   target = do_QueryInterface(doc->GetWindow());
   if (!target) { return NS_ERROR_NULL_POINTER; }
 
   if (mResizeEventListenerP) {
-    res = target->RemoveEventListener(NS_LITERAL_STRING("resize"), mResizeEventListenerP, false);
-    NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove resize event listener");
+    DebugOnly<nsresult> rv =
+      target->RemoveEventListener(NS_LITERAL_STRING("resize"),
+                                  mResizeEventListenerP, false);
+    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove resize event listener");
   }
   mResizeEventListenerP = nullptr;
 
   mResizedObject->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing, true);
   mResizedObject = nullptr;
 
   return NS_OK;
 }
@@ -564,18 +570,19 @@ HTMLEditor::MouseDown(int32_t aClientX,
                       nsIDOMElement* aTarget,
                       nsIDOMEvent* aEvent)
 {
   bool anonElement = false;
   if (aTarget && NS_SUCCEEDED(aTarget->HasAttribute(NS_LITERAL_STRING("_moz_anonclass"), &anonElement)))
     // we caught a click on an anonymous element
     if (anonElement) {
       nsAutoString anonclass;
-      nsresult res = aTarget->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
-      NS_ENSURE_SUCCESS(res, res);
+      nsresult rv =
+        aTarget->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
+      NS_ENSURE_SUCCESS(rv, rv);
       if (anonclass.EqualsLiteral("mozResizer")) {
         // and that element is a resizer, let's start resizing!
         aEvent->PreventDefault();
 
         mOriginalX = aClientX;
         mOriginalY = aClientY;
         return StartResizing(aTarget);
       }
@@ -671,20 +678,20 @@ HTMLEditor::SetResizingInfoPosition(int3
   // Offset info box by 20 so it's not directly under the mouse cursor.
   const int mouseCursorOffset = 20;
   mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::left,
                                       infoXPosition + mouseCursorOffset);
   mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::top,
                                       infoYPosition + mouseCursorOffset);
 
   nsCOMPtr<nsIContent> textInfo = mResizingInfo->GetFirstChild();
-  ErrorResult rv;
+  ErrorResult erv;
   if (textInfo) {
-    mResizingInfo->RemoveChild(*textInfo, rv);
-    NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
+    mResizingInfo->RemoveChild(*textInfo, erv);
+    NS_ENSURE_TRUE(!erv.Failed(), erv.StealNSResult());
     textInfo = nullptr;
   }
 
   nsAutoString widthStr, heightStr, diffWidthStr, diffHeightStr;
   widthStr.AppendInt(aW);
   heightStr.AppendInt(aH);
   int32_t diffWidth  = aW - mResizedObjectWidth;
   int32_t diffHeight = aH - mResizedObjectHeight;
@@ -696,41 +703,39 @@ HTMLEditor::SetResizingInfoPosition(int3
   diffHeightStr.AppendInt(diffHeight);
 
   nsAutoString info(widthStr + NS_LITERAL_STRING(" x ") + heightStr +
                     NS_LITERAL_STRING(" (") + diffWidthStr +
                     NS_LITERAL_STRING(", ") + diffHeightStr +
                     NS_LITERAL_STRING(")"));
 
   nsCOMPtr<nsIDOMText> nodeAsText;
-  nsresult res = domdoc->CreateTextNode(info, getter_AddRefs(nodeAsText));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = domdoc->CreateTextNode(info, getter_AddRefs(nodeAsText));
+  NS_ENSURE_SUCCESS(rv, rv);
   textInfo = do_QueryInterface(nodeAsText);
-  mResizingInfo->AppendChild(*textInfo, rv);
-  NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
+  mResizingInfo->AppendChild(*textInfo, erv);
+  NS_ENSURE_TRUE(!erv.Failed(), erv.StealNSResult());
 
-  res = mResizingInfo->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
-
-  return res;
+  return mResizingInfo->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
 }
 
 nsresult
 HTMLEditor::SetShadowPosition(Element* aShadow,
                               Element* aOriginalObject,
                               int32_t aOriginalObjectX,
                               int32_t aOriginalObjectY)
 {
   SetAnonymousElementPosition(aOriginalObjectX, aOriginalObjectY, static_cast<nsIDOMElement*>(GetAsDOMNode(aShadow)));
 
   if (HTMLEditUtils::IsImage(aOriginalObject)) {
     nsAutoString imageSource;
     aOriginalObject->GetAttr(kNameSpaceID_None, nsGkAtoms::src, imageSource);
-    nsresult res = aShadow->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
-                                    imageSource, true);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = aShadow->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
+                                   imageSource, true);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 int32_t
 HTMLEditor::GetNewResizingIncrement(int32_t aX,
                                     int32_t aY,
                                     int32_t aID)
--- a/editor/libeditor/HTMLInlineTableEditor.cpp
+++ b/editor/libeditor/HTMLInlineTableEditor.cpp
@@ -133,27 +133,28 @@ NS_IMETHODIMP
 HTMLEditor::DoInlineTableEditingAction(nsIDOMElement* aElement)
 {
   NS_ENSURE_ARG_POINTER(aElement);
   bool anonElement = false;
   if (aElement &&
       NS_SUCCEEDED(aElement->HasAttribute(NS_LITERAL_STRING("_moz_anonclass"), &anonElement)) &&
       anonElement) {
     nsAutoString anonclass;
-    nsresult res = aElement->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      aElement->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (!StringBeginsWith(anonclass, NS_LITERAL_STRING("mozTable")))
       return NS_OK;
 
     nsCOMPtr<nsIDOMNode> tableNode = GetEnclosingTable(mInlineEditedCell);
     nsCOMPtr<nsIDOMElement> tableElement = do_QueryInterface(tableNode);
     int32_t rowCount, colCount;
-    res = GetTableSize(tableElement, &rowCount, &colCount);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = GetTableSize(tableElement, &rowCount, &colCount);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     bool hideUI = false;
     bool hideResizersWithInlineTableUI = (GetAsDOMNode(mResizedObject) == tableElement);
 
     if (anonclass.EqualsLiteral("mozTableAddColumnBefore"))
       InsertTableColumn(1, false);
     else if (anonclass.EqualsLiteral("mozTableAddColumnAfter"))
       InsertTableColumn(1, true);
@@ -212,61 +213,63 @@ HTMLEditor::RefreshInlineTableEditingUI(
   nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(mInlineEditedCell);
   if (!htmlElement) {
     return NS_ERROR_NULL_POINTER;
   }
 
   int32_t xCell, yCell, wCell, hCell;
   GetElementOrigin(mInlineEditedCell, xCell, yCell);
 
-  nsresult res = htmlElement->GetOffsetWidth(&wCell);
-  NS_ENSURE_SUCCESS(res, res);
-  res = htmlElement->GetOffsetHeight(&hCell);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = htmlElement->GetOffsetWidth(&wCell);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = htmlElement->GetOffsetHeight(&hCell);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   int32_t xHoriz = xCell + wCell/2;
   int32_t yVert  = yCell + hCell/2;
 
   nsCOMPtr<nsIDOMNode> tableNode = GetEnclosingTable(mInlineEditedCell);
   nsCOMPtr<nsIDOMElement> tableElement = do_QueryInterface(tableNode);
   int32_t rowCount, colCount;
-  res = GetTableSize(tableElement, &rowCount, &colCount);
-  NS_ENSURE_SUCCESS(res, res);
+  rv = GetTableSize(tableElement, &rowCount, &colCount);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   SetAnonymousElementPosition(xHoriz-10, yCell-7,  mAddColumnBeforeButton);
 #ifdef DISABLE_TABLE_DELETION
   NS_NAMED_LITERAL_STRING(classStr, "class");
 
   if (colCount== 1) {
     mRemoveColumnButton->SetAttribute(classStr,
                                       NS_LITERAL_STRING("hidden"));
   }
   else {
     bool hasClass = false;
-    res = mRemoveColumnButton->HasAttribute(classStr, &hasClass);
-    if (NS_SUCCEEDED(res) && hasClass)
+    rv = mRemoveColumnButton->HasAttribute(classStr, &hasClass);
+    if (NS_SUCCEEDED(rv) && hasClass) {
       mRemoveColumnButton->RemoveAttribute(classStr);
+    }
 #endif
     SetAnonymousElementPosition(xHoriz-4, yCell-7,  mRemoveColumnButton);
 #ifdef DISABLE_TABLE_DELETION
   }
 #endif
   SetAnonymousElementPosition(xHoriz+6, yCell-7,  mAddColumnAfterButton);
 
   SetAnonymousElementPosition(xCell-7, yVert-10,  mAddRowBeforeButton);
 #ifdef DISABLE_TABLE_DELETION
   if (rowCount== 1) {
     mRemoveRowButton->SetAttribute(classStr,
                                    NS_LITERAL_STRING("hidden"));
   }
   else {
     bool hasClass = false;
-    res = mRemoveRowButton->HasAttribute(classStr, &hasClass);
-    if (NS_SUCCEEDED(res) && hasClass)
+    rv = mRemoveRowButton->HasAttribute(classStr, &hasClass);
+    if (NS_SUCCEEDED(rv) && hasClass) {
       mRemoveRowButton->RemoveAttribute(classStr);
+    }
 #endif
     SetAnonymousElementPosition(xCell-7, yVert-4,  mRemoveRowButton);
 #ifdef DISABLE_TABLE_DELETION
   }
 #endif
   SetAnonymousElementPosition(xCell-7, yVert+6,  mAddRowAfterButton);
 
   return NS_OK;
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -131,38 +131,38 @@ HTMLEditor::SetInlineProperty(nsIAtom* a
   AutoRules beginRulesSniffing(this, EditAction::insertElement,
                                nsIEditor::eNext);
   AutoSelectionRestorer selectionRestorer(selection, this);
   AutoTransactionsConserveSelection dontSpazMySelection(this);
 
   bool cancel, handled;
   TextRulesInfo ruleInfo(EditAction::setTextProperty);
   // Protect the edit rules object from dying
-  nsresult res = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!cancel && !handled) {
     // Loop through the ranges in the selection
     uint32_t rangeCount = selection->RangeCount();
     for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; rangeIdx++) {
       RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
 
       // Adjust range to include any ancestors whose children are entirely
       // selected
-      res = PromoteInlineRange(*range);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = PromoteInlineRange(*range);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       // Check for easy case: both range endpoints in same text node
       nsCOMPtr<nsINode> startNode = range->GetStartParent();
       nsCOMPtr<nsINode> endNode = range->GetEndParent();
       if (startNode && startNode == endNode && startNode->GetAsText()) {
-        res = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
-                                          range->StartOffset(),
-                                          range->EndOffset(),
-                                          *aProperty, &aAttribute, aValue);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
+                                         range->StartOffset(),
+                                         range->EndOffset(),
+                                         *aProperty, &aAttribute, aValue);
+        NS_ENSURE_SUCCESS(rv, rv);
         continue;
       }
 
       // Not the easy case.  Range not contained in single text node.  There
       // are up to three phases here.  There are all the nodes reported by the
       // subtree iterator to be processed.  And there are potentially a
       // starting textnode and an ending textnode which are only partially
       // contained by the range.
@@ -172,60 +172,60 @@ HTMLEditor::SetInlineProperty(nsIAtom* a
       // (since doing operations on the document during iteration would perturb
       // the iterator).
 
       OwningNonNull<nsIContentIterator> iter = NS_NewContentSubtreeIterator();
 
       nsTArray<OwningNonNull<nsIContent>> arrayOfNodes;
 
       // Iterate range and build up array
-      res = iter->Init(range);
+      rv = iter->Init(range);
       // Init returns an error if there are no nodes in range.  This can easily
       // happen with the subtree iterator if the selection doesn't contain any
       // *whole* nodes.
-      if (NS_SUCCEEDED(res)) {
+      if (NS_SUCCEEDED(rv)) {
         for (; !iter->IsDone(); iter->Next()) {
           OwningNonNull<nsINode> node = *iter->GetCurrentNode();
 
           if (node->IsContent() && IsEditable(node)) {
             arrayOfNodes.AppendElement(*node->AsContent());
           }
         }
       }
       // First check the start parent of the range to see if it needs to be
       // separately handled (it does if it's a text node, due to how the
       // subtree iterator works - it will not have reported it).
       if (startNode && startNode->GetAsText() && IsEditable(startNode)) {
-        res = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
-                                          range->StartOffset(),
-                                          startNode->Length(), *aProperty,
-                                          &aAttribute, aValue);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = SetInlinePropertyOnTextNode(*startNode->GetAsText(),
+                                         range->StartOffset(),
+                                         startNode->Length(), *aProperty,
+                                         &aAttribute, aValue);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
 
       // Then loop through the list, set the property on each node
       for (auto& node : arrayOfNodes) {
-        res = SetInlinePropertyOnNode(*node, *aProperty, &aAttribute, aValue);
-        NS_ENSURE_SUCCESS(res, res);
+        rv = SetInlinePropertyOnNode(*node, *aProperty, &aAttribute, aValue);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
 
       // Last check the end parent of the range to see if it needs to be
       // separately handled (it does if it's a text node, due to how the
       // subtree iterator works - it will not have reported it).
       if (endNode && endNode->GetAsText() && IsEditable(endNode)) {
-        res = SetInlinePropertyOnTextNode(*endNode->GetAsText(), 0,
+        rv = SetInlinePropertyOnTextNode(*endNode->GetAsText(), 0,
                                           range->EndOffset(), *aProperty,
                                           &aAttribute, aValue);
-        NS_ENSURE_SUCCESS(res, res);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
   if (!cancel) {
     // Post-process
-    return rules->DidDoAction(selection, &ruleInfo, res);
+    return rules->DidDoAction(selection, &ruleInfo, rv);
   }
   return NS_OK;
 }
 
 // Helper function for SetInlinePropertyOn*: is aNode a simple old <b>, <font>,
 // <span style="">, etc. that we can reuse instead of creating a new one?
 bool
 HTMLEditor::IsSimpleModifiableNode(nsIContent* aContent,
@@ -393,31 +393,30 @@ HTMLEditor::SetInlinePropertyOnNodeImpl(
                                               aValue);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
     return NS_OK;
   }
 
   // First check if there's an adjacent sibling we can put our node into.
-  nsresult res;
   nsCOMPtr<nsIContent> previousSibling = GetPriorHTMLSibling(&aNode);
   nsCOMPtr<nsIContent> nextSibling = GetNextHTMLSibling(&aNode);
   if (IsSimpleModifiableNode(previousSibling, &aProperty, aAttribute, &aValue)) {
-    res = MoveNode(&aNode, previousSibling, -1);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = MoveNode(&aNode, previousSibling, -1);
+    NS_ENSURE_SUCCESS(rv, rv);
     if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
-      res = JoinNodes(*previousSibling, *nextSibling);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = JoinNodes(*previousSibling, *nextSibling);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     return NS_OK;
   }
   if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
-    res = MoveNode(&aNode, nextSibling, 0);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv = MoveNode(&aNode, nextSibling, 0);
+    NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   // Don't need to do anything if property already set on node
   if (mCSSEditUtils->IsCSSEditableProperty(&aNode, &aProperty, aAttribute)) {
     if (mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(
           &aNode, &aProperty, aAttribute, aValue, CSSEditUtils::eComputed)) {
       return NS_OK;
@@ -442,20 +441,21 @@ HTMLEditor::SetInlinePropertyOnNodeImpl(
       tmp = aNode.AsElement();
     } else {
       tmp = InsertContainerAbove(&aNode, nsGkAtoms::span);
       NS_ENSURE_STATE(tmp);
     }
 
     // Add the CSS styles corresponding to the HTML style request
     int32_t count;
-    res = mCSSEditUtils->SetCSSEquivalentToHTMLStyle(tmp->AsDOMNode(),
-                                                     &aProperty, aAttribute,
-                                                     &aValue, &count, false);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      mCSSEditUtils->SetCSSEquivalentToHTMLStyle(tmp->AsDOMNode(),
+                                                 &aProperty, aAttribute,
+                                                 &aValue, &count, false);
+    NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
   // is it already the right kind of node, but with wrong attribute?
   if (aNode.IsHTMLElement(&aProperty)) {
     // Just set the attribute on it.
     nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(&aNode);
     return SetAttribute(elem, *aAttribute, aValue);
@@ -475,18 +475,18 @@ HTMLEditor::SetInlinePropertyOnNode(nsIC
                                     const nsAString* aAttribute,
                                     const nsAString& aValue)
 {
   nsCOMPtr<nsIContent> previousSibling = aNode.GetPreviousSibling(),
                        nextSibling = aNode.GetNextSibling();
   NS_ENSURE_STATE(aNode.GetParentNode());
   OwningNonNull<nsINode> parent = *aNode.GetParentNode();
 
-  nsresult res = RemoveStyleInside(aNode, &aProperty, aAttribute);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = RemoveStyleInside(aNode, &aProperty, aAttribute);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (aNode.GetParentNode()) {
     // The node is still where it was
     return SetInlinePropertyOnNodeImpl(aNode, aProperty,
                                        aAttribute, aValue);
   }
 
   // It's vanished.  Use the old siblings for reference to construct a
@@ -501,56 +501,56 @@ HTMLEditor::SetInlinePropertyOnNode(nsIC
     ? previousSibling->GetNextSibling() : parent->GetFirstChild();
   for (; cur && cur != nextSibling; cur = cur->GetNextSibling()) {
     if (IsEditable(cur)) {
       nodesToSet.AppendElement(*cur);
     }
   }
 
   for (auto& node : nodesToSet) {
-    res = SetInlinePropertyOnNodeImpl(node, aProperty, aAttribute, aValue);
-    NS_ENSURE_SUCCESS(res, res);
+    rv = SetInlinePropertyOnNodeImpl(node, aProperty, aAttribute, aValue);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditor::SplitStyleAboveRange(nsRange* inRange,
                                  nsIAtom* aProperty,
                                  const nsAString* aAttribute)
 {
   NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
-  nsresult res;
 
   nsCOMPtr<nsINode> startNode = inRange->GetStartParent();
   int32_t startOffset = inRange->StartOffset();
   nsCOMPtr<nsINode> endNode = inRange->GetEndParent();
   int32_t endOffset = inRange->EndOffset();
 
   nsCOMPtr<nsINode> origStartNode = startNode;
 
   // split any matching style nodes above the start of range
   {
     AutoTrackDOMPoint tracker(mRangeUpdater, address_of(endNode), &endOffset);
-    res = SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty,
-                               aAttribute);
-    NS_ENSURE_SUCCESS(res, res);
+    nsresult rv =
+      SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty,
+                           aAttribute);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // second verse, same as the first...
-  res = SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty,
-                             aAttribute);
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv =
+    SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty,
+                         aAttribute);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // reset the range
-  res = inRange->SetStart(startNode, startOffset);
-  NS_ENSURE_SUCCESS(res, res);
-  res = inRange->SetEnd(endNode, endOffset);
-  return res;
+  rv = inRange->SetStart(startNode, startOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return inRange->SetEnd(endNode, endOffset);
 }
 
 nsresult
 HTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsINode>* aNode,
                                  int32_t* aOffset,
                                  // null here means we split all properties
                                  nsIAtom* aProperty,
                                  const nsAString* aAttribute,
@@ -603,28 +603,28 @@ HTMLEditor::SplitStyleAbovePoint(nsCOMPt
 
 nsresult
 HTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode,
                        int32_t* aOffset,
                        nsIAtom* aProperty,
                        const nsAString* aAttribute)
 {
   nsCOMPtr<nsIContent> leftNode, rightNode;
-  nsresult res = SplitStyleAbovePoint(aNode, aOffset, aProperty,
-                                      aAttribute, getter_AddRefs(leftNode),
-                                      getter_AddRefs(rightNode));
-  NS_ENSURE_SUCCESS(res, res);
+  nsresult rv = SplitStyleAbovePoint(aNode, aOffset, aProperty,
+                                     aAttribute, getter_AddRefs(leftNode),
+                                     getter_AddRefs(rightNode));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (leftNode) {
     bool bIsEmptyNode;
     IsEmptyNode(leftNode, &bIsEmptyNode, false, true);
     if (bIsEmptyNode) {
       // delete leftNode if it became empty
-      res = DeleteNode(leftNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = DeleteNode(leftNode);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   if (rightNode) {
     nsCOMPtr<nsINode> secondSplitParent = GetLeftmostChild(rightNode);
     // don't try to split non-containers (br's, images, hr's, etc.)
     if (!secondSplitParent) {
       secondSplitParent = rightNode;
     }
@@ -633,52 +633,52 @@ HTMLEditor::ClearStyle(nsCOMPtr<nsINode>
       if (TextEditUtils::IsBreak(secondSplitParent)) {
         savedBR = do_QueryInterface(secondSplitParent);
         NS_ENSURE_STATE(savedBR);
       }
 
       secondSplitParent = secondSplitParent->GetParentNode();
     }
     *aOffset = 0;
-    res = SplitStyleAbovePoint(address_of(secondSplitParent),
-                               aOffset, aProperty, aAttribute,
-                               getter_AddRefs(leftNode),
-                               getter_AddRefs(rightNode));
-    NS_ENSURE_SUCCESS(res, res);
+    rv = SplitStyleAbovePoint(address_of(secondSplitParent),
+                              aOffset, aProperty, aAttribute,
+                              getter_AddRefs(leftNode),
+                              getter_AddRefs(rightNode));
+    NS_ENSURE_SUCCESS(rv, rv);
     // should be impossible to not get a new leftnode here
     nsCOMPtr<nsINode> newSelParent = GetLeftmostChild(leftNode);
     if (!newSelParent) {
       newSelParent = leftNode;
     }
     // If rightNode starts with a br, suck it out of right node and into
     // leftNode.  This is so we you don't revert back to the previous style
     // if you happen to click at the end of a line.
     if (savedBR) {
-      res = MoveNode(savedBR, newSelParent, 0);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = MoveNode(savedBR, newSelParent, 0);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     bool bIsEmptyNode;
     IsEmptyNode(rightNode, &bIsEmptyNode, false, true);
     if (bIsEmptyNode) {
       // delete rightNode if it became empty
-      res = DeleteNode(rightNode);
-      NS_ENSURE_SUCCESS(res, res);
+      rv = DeleteNode(rightNode);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
     // remove the style on this new hierarchy
     int32_t newSelOffset = 0;
     {
       // Track the point at the new hierarchy.  This is so we can know where
       // to put the selection after we call RemoveStyleInside().
       // RemoveStyleInside() could remove any and all of those nodes, so I
       // have to use the range t