Bug 1311606 Rename |result| of nsresult variants to |rv| in editor r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 25 Oct 2016 00:43:49 +0900
changeset 362126 5283a6d1c99f4bef96db734a83487b8569dd4c9f
parent 362125 99efd9af4a01001209a5072c67497e0ff973ca3e
child 362127 b20258d9a61bd4a746d7bdcb3026b4adb2e0c7ad
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)
reviewerssmaug
bugs1311606
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 1311606 Rename |result| of nsresult variants to |rv| in editor r=smaug For conforming to our coding rules, |result| of nsresult variants should be renamed to |rv|. MozReview-Commit-ID: Bk8CyLAnvXQ
editor/libeditor/ChangeStyleTransaction.cpp
editor/libeditor/EditAggregateTransaction.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/SelectionState.cpp
editor/libeditor/TextEditor.cpp
editor/libeditor/TextEditorTest.cpp
editor/libeditor/TypeInState.cpp
editor/txmgr/nsTransactionItem.cpp
editor/txmgr/nsTransactionList.cpp
editor/txmgr/nsTransactionManager.cpp
editor/txmgr/tests/TestTXMgr.cpp
editor/txtsvc/nsTextServicesDocument.cpp
--- a/editor/libeditor/ChangeStyleTransaction.cpp
+++ b/editor/libeditor/ChangeStyleTransaction.cpp
@@ -145,108 +145,101 @@ ChangeStyleTransaction::DoTransaction()
  
   nsAutoString propertyNameString;
   mProperty->ToString(propertyNameString);
 
   mUndoAttributeWasSet = mElement->HasAttr(kNameSpaceID_None,
                                            nsGkAtoms::style);
 
   nsAutoString values;
-  nsresult result = cssDecl->GetPropertyValue(propertyNameString, values);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = cssDecl->GetPropertyValue(propertyNameString, values);
+  NS_ENSURE_SUCCESS(rv, rv);
   mUndoValue.Assign(values);
 
   // Does this property accept more than one value? (bug 62682)
   bool multiple = AcceptsMoreThanOneValue(*mProperty);
 
   if (mRemoveProperty) {
     nsAutoString returnString;
     if (multiple) {
       // Let's remove only the value we have to remove and not the others
 
       // The two lines below are a workaround because
       // nsDOMCSSDeclaration::GetPropertyCSSValue is not yet implemented (bug
       // 62682)
       RemoveValueFromListOfValues(values, NS_LITERAL_STRING("none"));
       RemoveValueFromListOfValues(values, mValue);
       if (values.IsEmpty()) {
-        result = cssDecl->RemoveProperty(propertyNameString, returnString);
-        NS_ENSURE_SUCCESS(result, result);
+        rv = cssDecl->RemoveProperty(propertyNameString, returnString);
+        NS_ENSURE_SUCCESS(rv, rv);
       } else {
         nsAutoString priority;
         cssDecl->GetPropertyPriority(propertyNameString, priority);
-        result = cssDecl->SetProperty(propertyNameString, values,
-                                      priority);
-        NS_ENSURE_SUCCESS(result, result);
+        rv = cssDecl->SetProperty(propertyNameString, values, priority);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     } else {
-      result = cssDecl->RemoveProperty(propertyNameString, returnString);
-      NS_ENSURE_SUCCESS(result, result);
+      rv = cssDecl->RemoveProperty(propertyNameString, returnString);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   } else {
     nsAutoString priority;
     cssDecl->GetPropertyPriority(propertyNameString, priority);
     if (multiple) {
       // Let's add the value we have to add to the others
 
       // The line below is a workaround because
       // nsDOMCSSDeclaration::GetPropertyCSSValue is not yet implemented (bug
       // 62682)
       AddValueToMultivalueProperty(values, mValue);
     } else {
       values.Assign(mValue);
     }
-    result = cssDecl->SetProperty(propertyNameString, values,
-                                  priority);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = cssDecl->SetProperty(propertyNameString, values, priority);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Let's be sure we don't keep an empty style attribute
   uint32_t length;
-  result = cssDecl->GetLength(&length);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = cssDecl->GetLength(&length);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!length) {
-    result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     mRedoAttributeWasSet = true;
   }
 
   return cssDecl->GetPropertyValue(propertyNameString, mRedoValue);
 }
 
 nsresult
 ChangeStyleTransaction::SetStyle(bool aAttributeWasSet,
                                  nsAString& aValue)
 {
-  nsresult result = NS_OK;
   if (aAttributeWasSet) {
     // The style attribute was not empty, let's recreate the declaration
     nsAutoString propertyNameString;
     mProperty->ToString(propertyNameString);
 
     nsCOMPtr<nsStyledElement> inlineStyles = do_QueryInterface(mElement);
     NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsICSSDeclaration> cssDecl = inlineStyles->Style();
 
     if (aValue.IsEmpty()) {
       // An empty value means we have to remove the property
       nsAutoString returnString;
-      result = cssDecl->RemoveProperty(propertyNameString, returnString);
-    } else {
-      // Let's recreate the declaration as it was
-      nsAutoString priority;
-      cssDecl->GetPropertyPriority(propertyNameString, priority);
-      result = cssDecl->SetProperty(propertyNameString, aValue, priority);
+      return cssDecl->RemoveProperty(propertyNameString, returnString);
     }
-  } else {
-    result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
+    // Let's recreate the declaration as it was
+    nsAutoString priority;
+    cssDecl->GetPropertyPriority(propertyNameString, priority);
+    return cssDecl->SetProperty(propertyNameString, aValue, priority);
   }
-
-  return result;
+  return mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
 }
 
 NS_IMETHODIMP
 ChangeStyleTransaction::UndoTransaction()
 {
   return SetStyle(mUndoAttributeWasSet, mUndoValue);
 }
 
--- a/editor/libeditor/EditAggregateTransaction.cpp
+++ b/editor/libeditor/EditAggregateTransaction.cpp
@@ -28,63 +28,63 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(EditA
 NS_IMPL_ADDREF_INHERITED(EditAggregateTransaction, EditTransactionBase)
 NS_IMPL_RELEASE_INHERITED(EditAggregateTransaction, EditTransactionBase)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditAggregateTransaction)
 NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
 
 NS_IMETHODIMP
 EditAggregateTransaction::DoTransaction()
 {
-  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
+  // FYI: It's legal (but not very useful) to have an empty child list.
   for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
     nsITransaction *txn = mChildren[i];
     if (!txn) {
       return NS_ERROR_NULL_POINTER;
     }
-    result = txn->DoTransaction();
-    if (NS_FAILED(result)) {
-      break;
+    nsresult rv = txn->DoTransaction();
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditAggregateTransaction::UndoTransaction()
 {
-  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
-  // undo goes through children backwards
+  // FYI: It's legal (but not very useful) to have an empty child list.
+  // Undo goes through children backwards.
   for (uint32_t i = mChildren.Length(); i--; ) {
     nsITransaction *txn = mChildren[i];
     if (!txn) {
       return NS_ERROR_NULL_POINTER;
     }
-    result = txn->UndoTransaction();
-    if (NS_FAILED(result)) {
-      break;
+    nsresult rv = txn->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditAggregateTransaction::RedoTransaction()
 {
-  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
+  // It's legal (but not very useful) to have an empty child list.
   for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
     nsITransaction *txn = mChildren[i];
     if (!txn) {
       return NS_ERROR_NULL_POINTER;
     }
-    result = txn->RedoTransaction();
-    if (NS_FAILED(result)) {
-      break;
+    nsresult rv = txn->RedoTransaction();
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditAggregateTransaction::Merge(nsITransaction* aTransaction,
                                 bool* aDidMerge)
 {
   if (aDidMerge) {
     *aDidMerge = false;
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1446,24 +1446,24 @@ EditorBase::SplitNode(nsIContent& aNode,
     CreateTxnForSplitNode(aNode, aOffset);
   aResult = DoTransaction(transaction);
 
   nsCOMPtr<nsIContent> newNode = aResult.Failed() ? nullptr
                                                   : transaction->GetNewNode();
 
   mRangeUpdater.SelAdjSplitNode(aNode, aOffset, newNode);
 
-  nsresult result = aResult.StealNSResult();
+  nsresult rv = aResult.StealNSResult();
   for (auto& listener : mActionListeners) {
     listener->DidSplitNode(aNode.AsDOMNode(), aOffset, GetAsDOMNode(newNode),
-                           result);
+                           rv);
   }
   // Note: result might be a success code, so we can't use Throw() to
   // set it on aResult.
-  aResult = result;
+  aResult = rv;
 
   return newNode;
 }
 
 NS_IMETHODIMP
 EditorBase::JoinNodes(nsIDOMNode* aLeftNode,
                       nsIDOMNode* aRightNode,
                       nsIDOMNode*)
@@ -1490,32 +1490,32 @@ EditorBase::JoinNodes(nsINode& aLeftNode
   // Find the number of children of the lefthand node
   uint32_t oldLeftNodeLen = aLeftNode.Length();
 
   for (auto& listener : mActionListeners) {
     listener->WillJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
                             parent->AsDOMNode());
   }
 
-  nsresult result = NS_OK;
+  nsresult rv = NS_OK;
   RefPtr<JoinNodeTransaction> transaction =
     CreateTxnForJoinNode(aLeftNode, aRightNode);
   if (transaction)  {
-    result = DoTransaction(transaction);
+    rv = DoTransaction(transaction);
   }
 
   mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, *parent, offset,
                                 (int32_t)oldLeftNodeLen);
 
   for (auto& listener : mActionListeners) {
     listener->DidJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
-                           parent->AsDOMNode(), result);
-  }
-
-  return result;
+                           parent->AsDOMNode(), rv);
+  }
+
+  return rv;
 }
 
 NS_IMETHODIMP
 EditorBase::DeleteNode(nsIDOMNode* aNode)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   NS_ENSURE_STATE(node);
   return DeleteNode(node);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -253,26 +253,26 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
                  nsISelectionController* aSelCon,
                  uint32_t aFlags,
                  const nsAString& aInitialValue)
 {
   NS_PRECONDITION(aDoc && !aSelCon, "bad arg");
   NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
   MOZ_ASSERT(aInitialValue.IsEmpty(), "Non-empty initial values not supported");
 
-  nsresult result = NS_OK, rulesRes = NS_OK;
+  nsresult rulesRv = NS_OK;
 
   {
     // block to scope AutoEditInitRulesTrigger
-    AutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
+    AutoEditInitRulesTrigger rulesTrigger(this, rulesRv);
 
     // Init the plaintext editor
-    result = TextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue);
-    if (NS_FAILED(result)) {
-      return result;
+    nsresult rv = TextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue);
+    if (NS_FAILED(rv)) {
+      return rv;
     }
 
     // Init mutation observer
     nsCOMPtr<nsINode> document = do_QueryInterface(aDoc);
     document->AddMutationObserverUnlessExists(this);
 
     // disable Composer-only features
     if (IsMailEditor()) {
@@ -312,19 +312,19 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
         selection->AddSelectionListener(listener);
       }
       listener = do_QueryInterface(mSelectionListenerP);
       if (listener) {
         selection->AddSelectionListener(listener);
       }
     }
   }
-
-  NS_ENSURE_SUCCESS(rulesRes, rulesRes);
-  return result;
+  NS_ENSURE_SUCCESS(rulesRv, rulesRv);
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::PreDestroy(bool aDestroyingFrames)
 {
   if (mDidPreDestroy) {
     return NS_OK;
   }
@@ -1548,18 +1548,18 @@ HTMLEditor::InsertElementAtSelection(nsI
         // 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.
         rv = DeleteSelection(nsIEditor::eNone, nsIEditor::eNoStrip);
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
-      nsresult result = DeleteSelectionAndPrepareToCreateNode();
-      NS_ENSURE_SUCCESS(result, result);
+      nsresult rv = DeleteSelectionAndPrepareToCreateNode();
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // If deleting, selection will be collapsed.
     // so if not, we collapse it
     if (!aDeleteSelection) {
       // Named Anchor is a special case,
       // We collapse to insert element BEFORE the selection
       // For all other tags, we insert AFTER the selection
@@ -3632,17 +3632,16 @@ HTMLEditor::IsTextPropertySetByContent(n
 void
 HTMLEditor::IsTextPropertySetByContent(nsIDOMNode* aNode,
                                        nsIAtom* aProperty,
                                        const nsAString* aAttribute,
                                        const nsAString* aValue,
                                        bool& aIsSet,
                                        nsAString* outValue)
 {
-  nsresult result;
   aIsSet = false;  // must be initialized to false for code below to work
   nsAutoString propName;
   aProperty->ToString(propName);
   nsCOMPtr<nsIDOMNode>node = aNode;
 
   while (node) {
     nsCOMPtr<nsIDOMElement>element;
     element = do_QueryInterface(node);
@@ -3675,18 +3674,17 @@ HTMLEditor::IsTextPropertySetByContent(n
         }
         if (found) {
           aIsSet = true;
           break;
         }
       }
     }
     nsCOMPtr<nsIDOMNode>temp;
-    result = node->GetParentNode(getter_AddRefs(temp));
-    if (NS_SUCCEEDED(result) && temp) {
+    if (NS_SUCCEEDED(node->GetParentNode(getter_AddRefs(temp))) && temp) {
       node = temp;
     } else {
       node = nullptr;
     }
   }
 }
 
 bool
@@ -3755,20 +3753,20 @@ HTMLEditor::CollapseAdjacentTextNodes(ns
   AutoTransactionsConserveSelection dontSpazMySelection(this);
   nsTArray<nsCOMPtr<nsIDOMNode> > textNodes;
   // we can't actually do anything during iteration, so store the text nodes in an array
   // don't bother ref counting them because we know we can hold them for the
   // lifetime of this method
 
 
   // build a list of editable text nodes
-  nsresult result;
+  nsresult rv = NS_ERROR_UNEXPECTED;
   nsCOMPtr<nsIContentIterator> iter =
-    do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &result);
-  NS_ENSURE_SUCCESS(result, result);
+    do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   iter->Init(aInRange);
 
   while (!iter->IsDone()) {
     nsINode* node = iter->GetCurrentNode();
     if (node->NodeType() == nsIDOMNode::TEXT_NODE &&
         IsEditable(static_cast<nsIContent*>(node))) {
       nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(node);
@@ -3783,32 +3781,31 @@ HTMLEditor::CollapseAdjacentTextNodes(ns
   while (textNodes.Length() > 1) {
     // we assume a textNodes entry can't be nullptr
     nsIDOMNode *leftTextNode = textNodes[0];
     nsIDOMNode *rightTextNode = textNodes[1];
     NS_ASSERTION(leftTextNode && rightTextNode,"left or rightTextNode null in CollapseAdjacentTextNodes");
 
     // get the prev sibling of the right node, and see if its leftTextNode
     nsCOMPtr<nsIDOMNode> prevSibOfRightNode;
-    result =
-      rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
-    NS_ENSURE_SUCCESS(result, result);
+    rv = rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
+    NS_ENSURE_SUCCESS(rv, rv);
     if (prevSibOfRightNode && prevSibOfRightNode == leftTextNode) {
       nsCOMPtr<nsIDOMNode> parent;
-      result = rightTextNode->GetParentNode(getter_AddRefs(parent));
-      NS_ENSURE_SUCCESS(result, result);
+      rv = rightTextNode->GetParentNode(getter_AddRefs(parent));
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-      result = JoinNodes(leftTextNode, rightTextNode, parent);
-      NS_ENSURE_SUCCESS(result, result);
+      rv = JoinNodes(leftTextNode, rightTextNode, parent);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     textNodes.RemoveElementAt(0); // remove the leftmost text node from the list
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 HTMLEditor::SetSelectionAtDocumentStart(Selection* aSelection)
 {
   dom::Element* rootElement = GetRoot();
   NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
 
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -341,18 +341,18 @@ RangeUpdater::SelAdjSplitNode(nsIContent
   if (!count) {
     return NS_OK;
   }
 
   nsCOMPtr<nsINode> parent = aOldRightNode.GetParentNode();
   int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;
 
   // first part is same as inserting aNewLeftnode
-  nsresult result = SelAdjInsertNode(parent, offset - 1);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = SelAdjInsertNode(parent, offset - 1);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // next step is to check for range enpoints inside aOldRightNode
   for (size_t i = 0; i < count; i++) {
     RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == &aOldRightNode) {
       if (item->startOffset > aOffset) {
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -560,110 +560,108 @@ TextEditor::InsertBR(nsCOMPtr<nsIDOMNode
   selection->SetInterlinePosition(true);
   return selection->Collapse(selNode, selOffset+1);
 }
 
 nsresult
 TextEditor::ExtendSelectionForDelete(Selection* aSelection,
                                      nsIEditor::EDirection* aAction)
 {
-  nsresult result = NS_OK;
-
   bool bCollapsed = aSelection->Collapsed();
 
   if (*aAction == eNextWord ||
       *aAction == ePreviousWord ||
       (*aAction == eNext && bCollapsed) ||
       (*aAction == ePrevious && bCollapsed) ||
       *aAction == eToBeginningOfLine ||
       *aAction == eToEndOfLine) {
     nsCOMPtr<nsISelectionController> selCont;
     GetSelectionController(getter_AddRefs(selCont));
     NS_ENSURE_TRUE(selCont, NS_ERROR_NO_INTERFACE);
 
+    nsresult rv;
     switch (*aAction) {
       case eNextWord:
-        result = selCont->WordExtendForDelete(true);
+        rv = selCont->WordExtendForDelete(true);
         // DeleteSelectionImpl doesn't handle these actions
         // because it's inside batching, so don't confuse it:
         *aAction = eNone;
         break;
       case ePreviousWord:
-        result = selCont->WordExtendForDelete(false);
+        rv = selCont->WordExtendForDelete(false);
         *aAction = eNone;
         break;
       case eNext:
-        result = selCont->CharacterExtendForDelete();
+        rv = selCont->CharacterExtendForDelete();
         // Don't set aAction to eNone (see Bug 502259)
         break;
       case ePrevious: {
         // Only extend the selection where the selection is after a UTF-16
         // surrogate pair or a variation selector.
         // For other cases we don't want to do that, in order
         // to make sure that pressing backspace will only delete the last
         // typed character.
         nsCOMPtr<nsIDOMNode> node;
         int32_t offset;
-        result = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
-        NS_ENSURE_SUCCESS(result, result);
+        rv = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
         // node might be anonymous DIV, so we find better text node
         FindBetterInsertionPoint(node, offset);
 
         if (IsTextNode(node)) {
           nsCOMPtr<nsIDOMCharacterData> charData = do_QueryInterface(node);
           if (charData) {
             nsAutoString data;
-            result = charData->GetData(data);
-            NS_ENSURE_SUCCESS(result, result);
+            rv = charData->GetData(data);
+            NS_ENSURE_SUCCESS(rv, rv);
 
             if ((offset > 1 &&
                  NS_IS_LOW_SURROGATE(data[offset - 1]) &&
                  NS_IS_HIGH_SURROGATE(data[offset - 2])) ||
                 (offset > 0 &&
                  gfxFontUtils::IsVarSelector(data[offset - 1]))) {
-              result = selCont->CharacterExtendForBackspace();
+              rv = selCont->CharacterExtendForBackspace();
             }
           }
         }
         break;
       }
       case eToBeginningOfLine:
         selCont->IntraLineMove(true, false);          // try to move to end
-        result = selCont->IntraLineMove(false, true); // select to beginning
+        rv = selCont->IntraLineMove(false, true); // select to beginning
         *aAction = eNone;
         break;
       case eToEndOfLine:
-        result = selCont->IntraLineMove(true, true);
+        rv = selCont->IntraLineMove(true, true);
         *aAction = eNext;
         break;
       default:       // avoid several compiler warnings
-        result = NS_OK;
+        rv = NS_OK;
         break;
     }
+    return rv;
   }
-  return result;
+  return NS_OK;
 }
 
 nsresult
 TextEditor::DeleteSelection(EDirection aAction,
                             EStripWrappers aStripWrappers)
 {
   MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
 
   if (!mRules) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
-  nsresult result;
-
   // delete placeholder txns merge.
   AutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
   AutoRules beginRulesSniffing(this, EditAction::deleteSelection, aAction);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
@@ -671,38 +669,37 @@ TextEditor::DeleteSelection(EDirection a
   //  platforms that use "caret-style" caret positioning collapse the
   //  selection to the  start and then create a new selection.
   //  Platforms that use "selection-style" caret positioning just delete the
   //  existing selection without extending it.
   if (!selection->Collapsed() &&
       (aAction == eNextWord || aAction == ePreviousWord ||
        aAction == eToBeginningOfLine || aAction == eToEndOfLine)) {
     if (mCaretStyle == 1) {
-      result = selection->CollapseToStart();
-      NS_ENSURE_SUCCESS(result, result);
+      nsresult rv = selection->CollapseToStart();
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       aAction = eNone;
     }
   }
 
   TextRulesInfo ruleInfo(EditAction::deleteSelection);
   ruleInfo.collapsedAction = aAction;
   ruleInfo.stripWrappers = aStripWrappers;
   bool cancel, handled;
-  result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!cancel && !handled) {
-    result = DeleteSelectionImpl(aAction, aStripWrappers);
+    rv = DeleteSelectionImpl(aAction, aStripWrappers);
   }
   if (!cancel) {
     // post-process
-    result = rules->DidDoAction(selection, &ruleInfo, result);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
-
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 TextEditor::InsertText(const nsAString& aStringToInsert)
 {
   if (!mRules) {
     return NS_ERROR_NOT_INITIALIZED;
   }
@@ -1086,25 +1083,25 @@ TextEditor::Undo(uint32_t aCount)
 
   NotifyEditorObservers(eNotifyEditorObserversOfBefore);
 
   AutoRules beginRulesSniffing(this, EditAction::undo, nsIEditor::eNone);
 
   TextRulesInfo ruleInfo(EditAction::undo);
   RefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
-  nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
 
-  if (!cancel && NS_SUCCEEDED(result)) {
-    result = EditorBase::Undo(aCount);
-    result = rules->DidDoAction(selection, &ruleInfo, result);
+  if (!cancel && NS_SUCCEEDED(rv)) {
+    rv = EditorBase::Undo(aCount);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 TextEditor::Redo(uint32_t aCount)
 {
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
@@ -1114,25 +1111,25 @@ TextEditor::Redo(uint32_t aCount)
 
   NotifyEditorObservers(eNotifyEditorObserversOfBefore);
 
   AutoRules beginRulesSniffing(this, EditAction::redo, nsIEditor::eNone);
 
   TextRulesInfo ruleInfo(EditAction::redo);
   RefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
-  nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
 
-  if (!cancel && NS_SUCCEEDED(result)) {
-    result = EditorBase::Redo(aCount);
-    result = rules->DidDoAction(selection, &ruleInfo, result);
+  if (!cancel && NS_SUCCEEDED(rv)) {
+    rv = EditorBase::Redo(aCount);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
-  return result;
+  return rv;
 }
 
 bool
 TextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed)
 {
   RefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return false;
--- a/editor/libeditor/TextEditorTest.cpp
+++ b/editor/libeditor/TextEditorTest.cpp
@@ -43,120 +43,122 @@ void TextEditorTest::Run(nsIEditor *aEdi
   if (!aEditor) return;
   mTextEditor = do_QueryInterface(aEditor);
   mEditor = do_QueryInterface(aEditor);
   RunUnitTest(outNumTests, outNumTestsFailed);
 }
 
 nsresult TextEditorTest::RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
 
   *outNumTests = 0;
   *outNumTestsFailed = 0;
 
-  result = InitDoc();
-  TEST_RESULT(result);
+  nsresult rv = InitDoc();
+  TEST_RESULT(rv);
   // shouldn't we just bail on error here?
 
   // insert some simple text
-  result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
   // insert some more text
-  result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states.  I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham.  Injustice anywhere is a threat to justice everywhere"));
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states.  I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham.  Injustice anywhere is a threat to justice everywhere"));
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
-  result = TestInsertBreak();
-  TEST_RESULT(result);
+  rv = TestInsertBreak();
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
-  result = TestTextProperties();
-  TEST_RESULT(result);
+  rv = TestTextProperties();
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
   // get us back to the original document
-  result = mEditor->Undo(12);
-  TEST_RESULT(result);
+  rv = mEditor->Undo(12);
+  TEST_RESULT(rv);
 
-  return result;
+  return rv;
 }
 
 nsresult TextEditorTest::InitDoc()
 {
-  nsresult result = mEditor->SelectAll();
-  TEST_RESULT(result);
-  result = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
-  TEST_RESULT(result);
-  return result;
+  nsresult rv = mEditor->SelectAll();
+  TEST_RESULT(rv);
+  rv = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
+  TEST_RESULT(rv);
+  return rv;
 }
 
 nsresult TextEditorTest::TestInsertBreak()
 {
   nsCOMPtr<nsISelection>selection;
-  nsresult result = mEditor->GetSelection(getter_AddRefs(selection));
-  TEST_RESULT(result);
+  nsresult rv = mEditor->GetSelection(getter_AddRefs(selection));
+  TEST_RESULT(rv);
   TEST_POINTER(selection.get());
   nsCOMPtr<nsIDOMNode>anchor;
-  result = selection->GetAnchorNode(getter_AddRefs(anchor));
-  TEST_RESULT(result);
+  rv = selection->GetAnchorNode(getter_AddRefs(anchor));
+  TEST_RESULT(rv);
   TEST_POINTER(anchor.get());
   selection->Collapse(anchor, 0);
   // insert one break
   printf("inserting a break\n");
-  result = mTextEditor->InsertLineBreak();
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertLineBreak();
+  TEST_RESULT(rv);
   mEditor->DebugDumpContent();
 
   // insert a second break adjacent to the first
   printf("inserting a second break\n");
-  result = mTextEditor->InsertLineBreak();
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertLineBreak();
+  TEST_RESULT(rv);
   mEditor->DebugDumpContent();
 
-  return result;
+  return rv;
 }
 
 nsresult TextEditorTest::TestTextProperties()
 {
   nsCOMPtr<nsIDOMDocument>doc;
-  nsresult result = mEditor->GetDocument(getter_AddRefs(doc));
-  TEST_RESULT(result);
+  nsresult rv = mEditor->GetDocument(getter_AddRefs(doc));
+  TEST_RESULT(rv);
   TEST_POINTER(doc.get());
   nsCOMPtr<nsIDOMNodeList>nodeList;
   // XXX This is broken, text nodes are not elements.
   nsAutoString textTag(NS_LITERAL_STRING("#text"));
-  result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
-  TEST_RESULT(result);
+  rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
+  TEST_RESULT(rv);
   TEST_POINTER(nodeList.get());
   uint32_t count;
   nodeList->GetLength(&count);
   NS_ASSERTION(0!=count, "there are no text nodes in the document!");
   nsCOMPtr<nsIDOMNode>textNode;
-  result = nodeList->Item(count-1, getter_AddRefs(textNode));
-  TEST_RESULT(result);
+  rv = nodeList->Item(count - 1, getter_AddRefs(textNode));
+  TEST_RESULT(rv);
   TEST_POINTER(textNode.get());
 
   // set the whole text node to bold
   printf("set the whole first text node to bold\n");
   nsCOMPtr<nsISelection>selection;
-  result = mEditor->GetSelection(getter_AddRefs(selection));
-  TEST_RESULT(result);
+  rv = mEditor->GetSelection(getter_AddRefs(selection));
+  TEST_RESULT(rv);
   TEST_POINTER(selection.get());
   nsCOMPtr<nsIDOMCharacterData>textData;
   textData = do_QueryInterface(textNode);
   uint32_t length;
   textData->GetLength(&length);
   selection->Collapse(textNode, 0);
   selection->Extend(textNode, length);
 
@@ -164,98 +166,94 @@ nsresult TextEditorTest::TestTextPropert
   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   bool any = false;
   bool all = false;
   bool first=false;
 
   const nsAFlatString& empty = EmptyString();
 
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(false==first, "first should be false");
   NS_ASSERTION(false==any, "any should be false");
   NS_ASSERTION(false==all, "all should be false");
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   // remove the bold we just set
   printf("set the whole first text node to not bold\n");
-  result = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(false==first, "first should be false");
   NS_ASSERTION(false==any, "any should be false");
   NS_ASSERTION(false==all, "all should be false");
   mEditor->DebugDumpContent();
 
   // set all but the first and last character to bold
   printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
   selection->Collapse(textNode, 1);
   selection->Extend(textNode, length-1);
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
   // make all that same text italic
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   // make all the text underlined, except for the first 2 and last 2 characters
-  result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
-  TEST_RESULT(result);
+  rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
+  TEST_RESULT(rv);
   TEST_POINTER(nodeList.get());
   nodeList->GetLength(&count);
   NS_ASSERTION(0!=count, "there are no text nodes in the document!");
-  result = nodeList->Item(count-2, getter_AddRefs(textNode));
-  TEST_RESULT(result);
+  rv = nodeList->Item(count-2, getter_AddRefs(textNode));
+  TEST_RESULT(rv);
   TEST_POINTER(textNode.get());
   textData = do_QueryInterface(textNode);
   textData->GetLength(&length);
   NS_ASSERTION(length==915, "wrong text node");
   selection->Collapse(textNode, 1);
   selection->Extend(textNode, length-2);
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
-  return result;
+  return rv;
 }
 
-
-
 #endif
-
-
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -88,21 +88,21 @@ TypeInState::NotifySelectionChanged(nsID
 
   if (aSelection) {
     int32_t rangeCount = selection->RangeCount();
 
     if (selection->Collapsed() && rangeCount) {
       nsCOMPtr<nsIDOMNode> selNode;
       int32_t selOffset = 0;
 
-      nsresult result =
+      nsresult rv =
         EditorBase::GetStartNodeAndOffset(selection, getter_AddRefs(selNode),
                                           &selOffset);
 
-      NS_ENSURE_SUCCESS(result, result);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       if (selNode &&
           selNode == mLastSelectionContainer &&
           selOffset == mLastSelectionOffset) {
         // We got a bogus selection changed notification!
         return NS_OK;
       }
 
--- a/editor/txmgr/nsTransactionItem.cpp
+++ b/editor/txmgr/nsTransactionItem.cpp
@@ -91,240 +91,247 @@ nsTransactionItem::GetIsBatch(bool *aIsB
   *aIsBatch = !mTransaction;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetNumberOfChildren(int32_t *aNumChildren)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
 
   *aNumChildren = 0;
 
   int32_t ui = 0;
   int32_t ri = 0;
 
-  result = GetNumberOfUndoItems(&ui);
+  nsresult rv = GetNumberOfUndoItems(&ui);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  result = GetNumberOfRedoItems(&ri);
+  rv = GetNumberOfRedoItems(&ri);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   *aNumChildren = ui + ri;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetChild(int32_t aIndex, nsTransactionItem **aChild)
 {
   NS_ENSURE_TRUE(aChild, NS_ERROR_NULL_POINTER);
 
   *aChild = 0;
 
   int32_t numItems = 0;
-  nsresult result = GetNumberOfChildren(&numItems);
+  nsresult rv = GetNumberOfChildren(&numItems);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_ENSURE_SUCCESS(result, result);
-
-  if (aIndex < 0 || aIndex >= numItems)
+  if (aIndex < 0 || aIndex >= numItems) {
     return NS_ERROR_FAILURE;
+  }
 
   // Children are expected to be in the order they were added,
   // so the child first added would be at the bottom of the undo
   // stack, or if there are no items on the undo stack, it would
   // be at the top of the redo stack.
 
-  result = GetNumberOfUndoItems(&numItems);
+  rv = GetNumberOfUndoItems(&numItems);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (numItems > 0 && aIndex < numItems) {
     NS_ENSURE_TRUE(mUndoStack, NS_ERROR_FAILURE);
 
     RefPtr<nsTransactionItem> child = mUndoStack->GetItem(aIndex);
     child.forget(aChild);
     return *aChild ? NS_OK : NS_ERROR_FAILURE;
   }
 
   // Adjust the index for the redo stack:
 
   aIndex -=  numItems;
 
-  result = GetNumberOfRedoItems(&numItems);
+  rv = GetNumberOfRedoItems(&numItems);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_TRUE(mRedoStack && numItems != 0 && aIndex < numItems, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> child = mRedoStack->GetItem(aIndex);
   child.forget(aChild);
   return *aChild ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult
 nsTransactionItem::DoTransaction()
 {
-  if (mTransaction)
+  if (mTransaction) {
     return mTransaction->DoTransaction();
+  }
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::UndoTransaction(nsTransactionManager *aTxMgr)
 {
-  nsresult result = UndoChildren(aTxMgr);
+  nsresult rv = UndoChildren(aTxMgr);
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     RecoverFromUndoError(aTxMgr);
-    return result;
+    return rv;
   }
 
-  if (!mTransaction)
+  if (!mTransaction) {
     return NS_OK;
+  }
 
-  result = mTransaction->UndoTransaction();
+  rv = mTransaction->UndoTransaction();
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     RecoverFromUndoError(aTxMgr);
-    return result;
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
 {
   RefPtr<nsTransactionItem> item;
-  nsresult result = NS_OK;
   int32_t sz = 0;
 
   if (mUndoStack) {
     if (!mRedoStack && mUndoStack) {
       mRedoStack = new nsTransactionStack(nsTransactionStack::FOR_REDO);
     }
 
     /* Undo all of the transaction items children! */
     sz = mUndoStack->GetSize();
 
+    nsresult rv = NS_OK;
     while (sz-- > 0) {
       item = mUndoStack->Peek();
 
       if (!item) {
         return NS_ERROR_FAILURE;
       }
 
       nsCOMPtr<nsITransaction> t = item->GetTransaction();
 
       bool doInterrupt = false;
 
-      result = aTxMgr->WillUndoNotify(t, &doInterrupt);
+      rv = aTxMgr->WillUndoNotify(t, &doInterrupt);
 
-      if (NS_FAILED(result)) {
-        return result;
+      if (NS_FAILED(rv)) {
+        return rv;
       }
 
       if (doInterrupt) {
         return NS_OK;
       }
 
-      result = item->UndoTransaction(aTxMgr);
+      rv = item->UndoTransaction(aTxMgr);
 
-      if (NS_SUCCEEDED(result)) {
+      if (NS_SUCCEEDED(rv)) {
         item = mUndoStack->Pop();
         mRedoStack->Push(item.forget());
       }
 
-      nsresult result2 = aTxMgr->DidUndoNotify(t, result);
+      nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
 
-      if (NS_SUCCEEDED(result)) {
-        result = result2;
+      if (NS_SUCCEEDED(rv)) {
+        rv = rv2;
       }
     }
+    // XXX NS_OK if there is no Undo items or all methods work fine, otherwise,
+    //     the result of the last item's UndoTransaction() or
+    //     DidUndoNotify() if UndoTransaction() succeeded.
+    return rv;
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
 {
-  nsresult result;
-
   nsCOMPtr<nsITransaction> transaction(mTransaction);
   if (transaction) {
-    result = transaction->RedoTransaction();
+    nsresult rv = transaction->RedoTransaction();
 
-    NS_ENSURE_SUCCESS(result, result);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  result = RedoChildren(aTxMgr);
+  nsresult rv = RedoChildren(aTxMgr);
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     RecoverFromRedoError(aTxMgr);
-    return result;
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
 {
   RefPtr<nsTransactionItem> item;
-  nsresult result = NS_OK;
 
-  if (!mRedoStack)
+  if (!mRedoStack) {
     return NS_OK;
+  }
 
   /* Redo all of the transaction items children! */
   int32_t sz = mRedoStack->GetSize();
 
+  nsresult rv = NS_OK;
   while (sz-- > 0) {
     item = mRedoStack->Peek();
 
     if (!item) {
       return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsITransaction> t = item->GetTransaction();
 
     bool doInterrupt = false;
 
-    result = aTxMgr->WillRedoNotify(t, &doInterrupt);
+    rv = aTxMgr->WillRedoNotify(t, &doInterrupt);
 
-    if (NS_FAILED(result)) {
-      return result;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
 
     if (doInterrupt) {
       return NS_OK;
     }
 
-    result = item->RedoTransaction(aTxMgr);
+    rv = item->RedoTransaction(aTxMgr);
 
-    if (NS_SUCCEEDED(result)) {
+    if (NS_SUCCEEDED(rv)) {
       item = mRedoStack->Pop();
       mUndoStack->Push(item.forget());
     }
 
-    nsresult result2 = aTxMgr->DidUndoNotify(t, result);
+    // XXX Shouldn't this DidRedoNotify()? (bug 1311626)
+    nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
 
-    if (NS_SUCCEEDED(result)) {
-      result = result2;
+    if (NS_SUCCEEDED(rv)) {
+      rv = rv2;
     }
   }
-
-  return result;
+  // XXX NS_OK if there is no Redo items or all methods work fine, otherwise,
+  //     the result of the last item's RedoTransaction() or
+  //     DidUndoNotify() if UndoTransaction() succeeded.
+  return rv;
 }
 
 nsresult
 nsTransactionItem::GetNumberOfUndoItems(int32_t *aNumItems)
 {
   NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   if (!mUndoStack) {
@@ -366,22 +373,21 @@ nsTransactionItem::RecoverFromRedoError(
 {
   //
   // If this method gets called, we already successfully called
   // RedoTransaction() for the transaction item itself. Undo all
   // the children that successfully called RedoTransaction(),
   // then undo the transaction item itself.
   //
 
-  nsresult result;
+  nsresult rv = UndoChildren(aTxMgr);
 
-  result = UndoChildren(aTxMgr);
-
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
-  if (!mTransaction)
+  if (!mTransaction) {
     return NS_OK;
+  }
 
   return mTransaction->UndoTransaction();
 }
 
--- a/editor/txmgr/nsTransactionList.cpp
+++ b/editor/txmgr/nsTransactionList.cpp
@@ -44,46 +44,43 @@ NS_IMETHODIMP nsTransactionList::GetNumI
   NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   *aNumItems = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     *aNumItems = mTxnStack->GetSize();
-  else if (mTxnItem)
-    result = mTxnItem->GetNumberOfChildren(aNumItems);
+  } else if (mTxnItem) {
+    return mTxnItem->GetNumberOfChildren(aNumItems);
+  }
 
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsTransactionList::ItemIsBatch(int32_t aIndex, bool *aIsBatch)
 {
   NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER);
 
   *aIsBatch = false;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetIsBatch(aIsBatch);
 }
 
 NS_IMETHODIMP nsTransactionList::GetData(int32_t aIndex,
                                          uint32_t *aLength,
@@ -93,18 +90,18 @@ NS_IMETHODIMP nsTransactionList::GetData
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
   if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
   } else if (mTxnItem) {
-    nsresult result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMArray<nsISupports>& data = item->GetData();
 
   nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(data.Count() *
     sizeof(nsISupports*)));
 
   for (int32_t i = 0; i < data.Count(); i++) {
@@ -124,24 +121,22 @@ NS_IMETHODIMP nsTransactionList::GetItem
   *aItem = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   *aItem = item->GetTransaction().take();
 
   return NS_OK;
 }
 
@@ -152,24 +147,22 @@ NS_IMETHODIMP nsTransactionList::GetNumC
   *aNumChildren = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetNumberOfChildren(aNumChildren);
 }
 
 NS_IMETHODIMP nsTransactionList::GetChildListForItem(int32_t aIndex, nsITransactionList **aTxnList)
 {
@@ -178,28 +171,25 @@ NS_IMETHODIMP nsTransactionList::GetChil
   *aTxnList = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   *aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item);
 
   NS_ENSURE_TRUE(*aTxnList, NS_ERROR_OUT_OF_MEMORY);
 
   NS_ADDREF(*aTxnList);
 
   return NS_OK;
 }
-
--- a/editor/txmgr/nsTransactionManager.cpp
+++ b/editor/txmgr/nsTransactionManager.cpp
@@ -54,55 +54,53 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTransactionManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTransactionManager)
 
 NS_IMETHODIMP
 nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   bool doInterrupt = false;
 
-  result = WillDoNotify(aTransaction, &doInterrupt);
+  nsresult rv = WillDoNotify(aTransaction, &doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = BeginTransaction(aTransaction, nullptr);
+  rv = BeginTransaction(aTransaction, nullptr);
 
-  if (NS_FAILED(result)) {
-    DidDoNotify(aTransaction, result);
-    return result;
+  if (NS_FAILED(rv)) {
+    DidDoNotify(aTransaction, rv);
+    return rv;
   }
 
-  result = EndTransaction(false);
+  rv = EndTransaction(false);
 
-  nsresult result2 = DidDoNotify(aTransaction, result);
+  nsresult rv2 = DidDoNotify(aTransaction, rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of EndTransaction() or DidDoNotify() if EndTransaction()
+  //     succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::UndoTransaction()
 {
-  nsresult result       = NS_OK;
-
   // It is illegal to call UndoTransaction() while the transaction manager is
   // executing a  transaction's DoTransaction() method! If this happens,
   // the UndoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
 
   if (!mDoStack.IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
 
@@ -114,47 +112,47 @@ nsTransactionManager::UndoTransaction()
   if (!tx) {
     return NS_OK;
   }
 
   nsCOMPtr<nsITransaction> t = tx->GetTransaction();
 
   bool doInterrupt = false;
 
-  result = WillUndoNotify(t, &doInterrupt);
+  nsresult rv = WillUndoNotify(t, &doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = tx->UndoTransaction(this);
+  rv = tx->UndoTransaction(this);
 
-  if (NS_SUCCEEDED(result)) {
+  if (NS_SUCCEEDED(rv)) {
     tx = mUndoStack.Pop();
     mRedoStack.Push(tx.forget());
   }
 
-  nsresult result2 = DidUndoNotify(t, result);
+  nsresult rv2 = DidUndoNotify(t, rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of UndoTransaction() or DidUndoNotify() if UndoTransaction()
+  //     succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::RedoTransaction()
 {
-  nsresult result       = NS_OK;
-
   // It is illegal to call RedoTransaction() while the transaction manager is
   // executing a  transaction's DoTransaction() method! If this happens,
   // the RedoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
 
   if (!mDoStack.IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
 
@@ -166,139 +164,137 @@ nsTransactionManager::RedoTransaction()
   if (!tx) {
     return NS_OK;
   }
 
   nsCOMPtr<nsITransaction> t = tx->GetTransaction();
 
   bool doInterrupt = false;
 
-  result = WillRedoNotify(t, &doInterrupt);
+  nsresult rv = WillRedoNotify(t, &doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = tx->RedoTransaction(this);
+  rv = tx->RedoTransaction(this);
 
-  if (NS_SUCCEEDED(result)) {
+  if (NS_SUCCEEDED(rv)) {
     tx = mRedoStack.Pop();
     mUndoStack.Push(tx.forget());
   }
 
-  nsresult result2 = DidRedoNotify(t, result);
+  nsresult rv2 = DidRedoNotify(t, rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of RedoTransaction() or DidRedoNotify() if RedoTransaction()
+  //     succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::Clear()
 {
-  nsresult result;
+  nsresult rv = ClearRedoStack();
 
-  result = ClearRedoStack();
-
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
-  result = ClearUndoStack();
-
-  return result;
+  return ClearUndoStack();
 }
 
 NS_IMETHODIMP
 nsTransactionManager::BeginBatch(nsISupports* aData)
 {
-  nsresult result;
-
   // We can batch independent transactions together by simply pushing
   // a dummy transaction item on the do stack. This dummy transaction item
   // will be popped off the do stack, and then pushed on the undo stack
   // in EndBatch().
 
   bool doInterrupt = false;
 
-  result = WillBeginBatchNotify(&doInterrupt);
+  nsresult rv = WillBeginBatchNotify(&doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = BeginTransaction(0, aData);
+  rv = BeginTransaction(0, aData);
 
-  nsresult result2 = DidBeginBatchNotify(result);
+  nsresult rv2 = DidBeginBatchNotify(rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of BeginTransaction() or DidBeginBatchNotify() if
+  //     BeginTransaction() succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::EndBatch(bool aAllowEmpty)
 {
-  nsCOMPtr<nsITransaction> ti;
-  nsresult result;
-
   // XXX: Need to add some mechanism to detect the case where the transaction
   //      at the top of the do stack isn't the dummy transaction, so we can
   //      throw an error!! This can happen if someone calls EndBatch() within
   //      the DoTransaction() method of a transaction.
   //
   //      For now, we can detect this case by checking the value of the
   //      dummy transaction's mTransaction field. If it is our dummy
   //      transaction, it should be nullptr. This may not be true in the
   //      future when we allow users to execute a transaction when beginning
   //      a batch!!!!
 
   RefPtr<nsTransactionItem> tx = mDoStack.Peek();
 
+  nsCOMPtr<nsITransaction> ti;
   if (tx) {
     ti = tx->GetTransaction();
   }
 
   if (!tx || ti) {
     return NS_ERROR_FAILURE;
   }
 
   bool doInterrupt = false;
 
-  result = WillEndBatchNotify(&doInterrupt);
+  nsresult rv = WillEndBatchNotify(&doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = EndTransaction(aAllowEmpty);
+  rv = EndTransaction(aAllowEmpty);
 
-  nsresult result2 = DidEndBatchNotify(result);
+  nsresult rv2 = DidEndBatchNotify(rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of EndTransaction() or DidEndBatchNotify() if
+  //     EndTransaction() succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::GetNumberOfUndoItems(int32_t *aNumItems)
 {
   *aNumItems = mUndoStack.GetSize();
   return NS_OK;
 }
@@ -465,26 +461,26 @@ nsTransactionManager::BatchTopUndo()
   RefPtr<nsTransactionItem> previousUndo;
 
   lastUndo = mUndoStack.Pop();
   MOZ_ASSERT(lastUndo, "There should be at least two transactions.");
 
   previousUndo = mUndoStack.Peek();
   MOZ_ASSERT(previousUndo, "There should be at least two transactions.");
 
-  nsresult result = previousUndo->AddChild(lastUndo);
+  nsresult rv = previousUndo->AddChild(lastUndo);
 
   // Transfer data from the transactions that is going to be
   // merged to the transaction that it is being merged with.
   nsCOMArray<nsISupports>& lastData = lastUndo->GetData();
   nsCOMArray<nsISupports>& previousData = previousUndo->GetData();
   NS_ENSURE_TRUE(previousData.AppendObjects(lastData), NS_ERROR_UNEXPECTED);
   lastData.Clear();
 
-  return result;
+  return rv;
 }
 
 nsresult
 nsTransactionManager::RemoveTopUndo()
 {
   if (mUndoStack.IsEmpty()) {
     return NS_OK;
   }
@@ -521,280 +517,265 @@ nsTransactionManager::ClearRedoStack()
 {
   mRedoStack.Clear();
   return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillDo(this, aTransaction, aInterrupt);
+    nsresult rv = listener->WillDo(this, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidDo(this, aTransaction, aDoResult);
+    nsresult rv = listener->DidDo(this, aTransaction, aDoResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillUndo(this, aTransaction, aInterrupt);
+    nsresult rv = listener->WillUndo(this, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidUndo(this, aTransaction, aUndoResult);
+    nsresult rv = listener->DidUndo(this, aTransaction, aUndoResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillRedo(this, aTransaction, aInterrupt);
+    nsresult rv = listener->WillRedo(this, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidRedo(this, aTransaction, aRedoResult);
+    nsresult rv = listener->DidRedo(this, aTransaction, aRedoResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillBeginBatchNotify(bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillBeginBatch(this, aInterrupt);
+    nsresult rv = listener->WillBeginBatch(this, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidBeginBatch(this, aResult);
+    nsresult rv = listener->DidBeginBatch(this, aResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillEndBatchNotify(bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillEndBatch(this, aInterrupt);
+    nsresult rv = listener->WillEndBatch(this, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidEndBatchNotify(nsresult aResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidEndBatch(this, aResult);
+    nsresult rv = listener->DidEndBatch(this, aResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
+    nsresult rv = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidMergeNotify(nsITransaction *aTop,
                                      nsITransaction *aTransaction,
                                      bool aDidMerge,
                                      nsresult aMergeResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
+    nsresult rv =
+      listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
                                        nsISupports *aData)
 {
-  nsresult result = NS_OK;
-
   // XXX: POSSIBLE OPTIMIZATION
   //      We could use a factory that pre-allocates/recycles transaction items.
   RefPtr<nsTransactionItem> tx = new nsTransactionItem(aTransaction);
 
   if (aData) {
     nsCOMArray<nsISupports>& data = tx->GetData();
     data.AppendObject(aData);
   }
 
   if (!tx) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   mDoStack.Push(tx);
 
-  result = tx->DoTransaction();
+  nsresult rv = tx->DoTransaction();
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     tx = mDoStack.Pop();
-    return result;
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionManager::EndTransaction(bool aAllowEmpty)
 {
-  nsresult result              = NS_OK;
-
   RefPtr<nsTransactionItem> tx = mDoStack.Pop();
 
   if (!tx) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsITransaction> tint = tx->GetTransaction();
 
@@ -802,88 +783,84 @@ nsTransactionManager::EndTransaction(boo
     int32_t nc = 0;
 
     // If we get here, the transaction must be a dummy batch transaction
     // created by BeginBatch(). If it contains no children, get rid of it!
 
     tx->GetNumberOfChildren(&nc);
 
     if (!nc) {
-      return result;
+      return NS_OK;
     }
   }
 
   // Check if the transaction is transient. If it is, there's nothing
   // more to do, just return.
 
   bool isTransient = false;
-
+  nsresult rv = NS_OK;
   if (tint) {
-    result = tint->GetIsTransient(&isTransient);
+    rv = tint->GetIsTransient(&isTransient);
   }
 
-  if (NS_FAILED(result) || isTransient || !mMaxTransactionCount) {
+  if (NS_FAILED(rv) || isTransient || !mMaxTransactionCount) {
     // XXX: Should we be clearing the redo stack if the transaction
     //      is transient and there is nothing on the do stack?
-    return result;
+    return rv;
   }
 
   // Check if there is a transaction on the do stack. If there is,
   // the current transaction is a "sub" transaction, and should
   // be added to the transaction at the top of the do stack.
 
   RefPtr<nsTransactionItem> top = mDoStack.Peek();
   if (top) {
-    result = top->AddChild(tx);
-
-    // XXX: What do we do if this fails?
-
-    return result;
+    return top->AddChild(tx); // XXX: What do we do if this fails?
   }
 
   // The transaction succeeded, so clear the redo stack.
 
-  result = ClearRedoStack();
+  rv = ClearRedoStack();
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     // XXX: What do we do if this fails?
   }
 
   // Check if we can coalesce this transaction with the one at the top
   // of the undo stack.
 
   top = mUndoStack.Peek();
 
   if (tint && top) {
     bool didMerge = false;
     nsCOMPtr<nsITransaction> topTransaction = top->GetTransaction();
 
     if (topTransaction) {
 
       bool doInterrupt = false;
 
-      result = WillMergeNotify(topTransaction, tint, &doInterrupt);
+      rv = WillMergeNotify(topTransaction, tint, &doInterrupt);
 
-      NS_ENSURE_SUCCESS(result, result);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       if (!doInterrupt) {
-        result = topTransaction->Merge(tint, &didMerge);
+        rv = topTransaction->Merge(tint, &didMerge);
 
-        nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);
+        nsresult rv2 = DidMergeNotify(topTransaction, tint, didMerge, rv);
 
-        if (NS_SUCCEEDED(result)) {
-          result = result2;
+        if (NS_SUCCEEDED(rv)) {
+          rv = rv2;
         }
 
-        if (NS_FAILED(result)) {
+        if (NS_FAILED(rv)) {
           // XXX: What do we do if this fails?
         }
 
         if (didMerge) {
-          return result;
+          return rv;
         }
       }
     }
   }
 
   // Check to see if we've hit the max level of undo. If so,
   // pop the bottom transaction off the undo stack and release it!
 
@@ -894,9 +871,8 @@ nsTransactionManager::EndTransaction(boo
   }
 
   // Push the transaction on the undo stack:
 
   mUndoStack.Push(tx.forget());
 
   return NS_OK;
 }
-
--- a/editor/txmgr/tests/TestTXMgr.cpp
+++ b/editor/txmgr/tests/TestTXMgr.cpp
@@ -601,31 +601,31 @@ public:
 
   NS_IMETHOD DoTransaction()
   {
     if (mLevel >= mMaxLevel) {
       // Only leaf nodes can throw errors!
       mFlags |= mErrorFlags;
     }
 
-    nsresult result = SimpleTransaction::DoTransaction();
-
-    if (NS_FAILED(result)) {
+    nsresult rv = SimpleTransaction::DoTransaction();
+    if (NS_FAILED(rv)) {
       // fail("QueryInterface() failed for transaction level %d. (%d)\n",
-      //      mLevel, result);
-      return result;
+      //      mLevel, rv);
+      return rv;
     }
 
-    if (mLevel >= mMaxLevel)
+    if (mLevel >= mMaxLevel) {
       return NS_OK;
+    }
 
     if (mFlags & BATCH_FLAG) {
-      result = mTXMgr->BeginBatch(nullptr);
-      if (NS_FAILED(result)) {
-        return result;
+      rv = mTXMgr->BeginBatch(nullptr);
+      if (NS_FAILED(rv)) {
+        return rv;
       }
     }
 
     int32_t cLevel = mLevel + 1;
 
     for (int i = 1; i <= mNumChildrenPerNode; i++) {
       int32_t flags = mErrorFlags & THROWS_DO_ERROR_FLAG;
 
@@ -642,57 +642,54 @@ public:
       flags |= mFlags & BATCH_FLAG;
 
       AggregateTransaction *tximpl =
               new AggregateTransaction(mTXMgr, cLevel, i, mMaxLevel,
                                        mNumChildrenPerNode, flags);
 
       if (!tximpl) {
         fail("Failed to allocate AggregateTransaction %d, level %d. (%d)\n",
-             i, mLevel, result);
+             i, mLevel, rv);
 
         if (mFlags & BATCH_FLAG) {
           mTXMgr->EndBatch(false);
         }
 
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
       nsITransaction *tx = 0;
-      result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-      if (NS_FAILED(result)) {
+      rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+      if (NS_FAILED(rv)) {
         fail("QueryInterface() failed for transaction %d, level %d. (%d)\n",
-             i, mLevel, result);
+             i, mLevel, rv);
 
         if (mFlags & BATCH_FLAG) {
           mTXMgr->EndBatch(false);
         }
-        return result;
+        return rv;
       }
 
-      result = mTXMgr->DoTransaction(tx);
-
-      if (NS_FAILED(result)) {
+      rv = mTXMgr->DoTransaction(tx);
+      if (NS_FAILED(rv)) {
         // fail("Failed to execute transaction %d, level %d. (%d)\n",
-        //      i, mLevel, result);
+        //      i, mLevel, rv);
         tx->Release();
-
         if (mFlags & BATCH_FLAG) {
           mTXMgr->EndBatch(false);
         }
-        return result;
+        return rv;
       }
-
       tx->Release();
     }
 
     if (mFlags & BATCH_FLAG) {
       mTXMgr->EndBatch(false);
     }
-    return result;
+    return rv;
   }
 };
 
 class TestTransactionFactory
 {
 public:
   virtual TestTransaction *create(nsITransactionManager *txmgr, int32_t flags) = 0;
 };
@@ -751,257 +748,246 @@ reset_globals()
 }
 
 /**
  * Test behaviors in non-batch mode.
  **/
 nsresult
 quick_test(TestTransactionFactory *factory)
 {
-  nsresult result;
-
   /*******************************************************************
    *
    * Create a transaction manager implementation:
    *
    *******************************************************************/
 
+  nsresult rv;
   nsCOMPtr<nsITransactionManager> mgr =
-    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
-  if (NS_FAILED(result) || !mgr) {
+    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
+  if (NS_FAILED(rv) || !mgr) {
     fail("Failed to create Transaction Manager instance.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   passed("Create transaction manager instance");
 
   /*******************************************************************
    *
    * Call DoTransaction() with a null transaction:
    *
    *******************************************************************/
 
-  result = mgr->DoTransaction(0);
-
-  if (result != NS_ERROR_NULL_POINTER) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = mgr->DoTransaction(0);
+  if (rv != NS_ERROR_NULL_POINTER) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call DoTransaction() with null transaction");
 
   /*******************************************************************
    *
    * Call UndoTransaction() with an empty undo stack:
    *
    *******************************************************************/
 
-  result = mgr->UndoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Undo on empty undo stack failed. (%d)\n", result);
-    return result;
+  rv = mgr->UndoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Undo on empty undo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call UndoTransaction() with empty undo stack");
 
   /*******************************************************************
    *
    * Call RedoTransaction() with an empty redo stack:
    *
    *******************************************************************/
 
-  result = mgr->RedoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Redo on empty redo stack failed. (%d)\n", result);
-    return result;
+  rv = mgr->RedoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Redo on empty redo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call RedoTransaction() with empty redo stack");
 
   /*******************************************************************
    *
    * Call SetMaxTransactionCount(-1) with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(-1) failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call SetMaxTransactionCount(-1) with empty undo and redo stacks");
 
   /*******************************************************************
    *
    * Call SetMaxTransactionCount(0) with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(0);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(0);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call SetMaxTransactionCount(0) with empty undo and redo stacks");
 
   /*******************************************************************
    *
    * Call SetMaxTransactionCount(10) with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(10);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(10) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(10);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(10) failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call SetMaxTransactionCount(10) with empty undo and redo stacks");
 
   /*******************************************************************
    *
    * Call Clear() with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear on empty undo and redo stack failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear on empty undo and redo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call Clear() with empty undo and redo stack");
 
   int32_t numitems;
 
   /*******************************************************************
    *
    * Call GetNumberOfUndoItems() with an empty undo stack:
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call GetNumberOfUndoItems() with empty undo stack");
 
   /*******************************************************************
    *
    * Call GetNumberOfRedoItems() with an empty redo stack:
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call GetNumberOfRedoItems() with empty redo stack");
 
   nsITransaction *tx;
 
   /*******************************************************************
    *
    * Call PeekUndoStack() with an empty undo stack:
    *
    *******************************************************************/
 
   tx = 0;
-  result = mgr->PeekUndoStack(&tx);
+  rv = mgr->PeekUndoStack(&tx);
 
   TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   if (tx) {
-    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", result);
+    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call PeekUndoStack() with empty undo stack");
 
   /*******************************************************************
    *
    * Call PeekRedoStack() with an empty undo stack:
    *
    *******************************************************************/
 
   tx = 0;
-  result = mgr->PeekRedoStack(&tx);
+  rv = mgr->PeekRedoStack(&tx);
 
   TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   if (tx) {
-    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", result);
+    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call PeekRedoStack() with empty undo stack");
 
   /*******************************************************************
    *
    * Call AddListener() with a null listener pointer:
    *
    *******************************************************************/
 
-  result = mgr->AddListener(0);
-
-  if (result != NS_ERROR_NULL_POINTER) {
-    fail("AddListener() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = mgr->AddListener(0);
+  if (rv != NS_ERROR_NULL_POINTER) {
+    fail("AddListener() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call AddListener() with null listener");
 
   /*******************************************************************
    *
    * Call RemoveListener() with a null listener pointer:
    *
    *******************************************************************/
 
-  result = mgr->RemoveListener(0);
-
-  if (result != NS_ERROR_NULL_POINTER) {
-    fail("RemoveListener() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = mgr->RemoveListener(0);
+  if (rv != NS_ERROR_NULL_POINTER) {
+    fail("RemoveListener() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call RemoveListener() with null listener");
 
   int32_t i;
   TestTransaction *tximpl;
   nsITransaction *u1, *u2;
   nsITransaction *r1, *r2;
@@ -1010,160 +996,155 @@ quick_test(TestTransactionFactory *facto
    *
    * Test coalescing by executing a transaction that can merge any
    * command into itself. Then execute 20 transaction. Afterwards,
    * we should still have the first transaction sitting on the undo
    * stack. Then clear the undo and redo stacks.
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(10);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(10) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(10);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(10) failed. (%d)\n", rv);
+    return rv;
   }
 
 
   tximpl = factory->create(mgr, MERGE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate initial transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
     fail("QueryInterface() failed for initial transaction. (%d)\n",
-         result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("Failed to execute initial transaction. (%d)\n", result);
-    return result;
+         rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute initial transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != tx) {
-    fail("Top of undo stack is different!. (%d)\n", result);
+    fail("Top of undo stack is different!. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r1);
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Test coalescing of transactions");
 
   /*******************************************************************
    *
    * Execute 20 transactions. Afterwards, we should have 10
    * transactions on the undo stack:
@@ -1174,257 +1155,250 @@ quick_test(TestTransactionFactory *facto
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 transactions");
 
   /*******************************************************************
    *
    * Execute 20 transient transactions. Afterwards, we should still
    * have the same 10 transactions on the undo stack:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, TRANSIENT_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 transient transactions");
 
   /*******************************************************************
    *
    * Undo 4 transactions. Afterwards, we should have 6 transactions
    * on the undo stack, and 4 on the redo stack:
    *
    *******************************************************************/
 
   for (i = 1; i <= 4; i++) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 6) {
     fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 4) {
     fail("GetNumberOfRedoItems() expected 4 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo 4 transactions");
 
   /*******************************************************************
    *
    * Redo 2 transactions. Afterwards, we should have 8 transactions
    * on the undo stack, and 2 on the redo stack:
    *
    *******************************************************************/
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->RedoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to redo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->RedoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to redo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 8 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 8) {
     fail("GetNumberOfUndoItems() expected 8 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Redo 2 transactions");
 
   /*******************************************************************
    *
    * Execute a new transaction. The redo stack should get pruned!
@@ -1435,134 +1409,127 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 9 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 9) {
     fail("GetNumberOfUndoItems() expected 9 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Check if new transactions prune the redo stack");
 
   /*******************************************************************
    *
    * Undo 4 transactions then clear the undo and redo stacks.
    *
    *******************************************************************/
 
   for (i = 1; i <= 4; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 4) {
     fail("GetNumberOfRedoItems() expected 4 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on cleared undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on cleared redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo 4 transactions then clear the undo and redo stacks");
 
   /*******************************************************************
    *
    * Execute 5 transactions.
@@ -1573,57 +1540,55 @@ quick_test(TestTransactionFactory *facto
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 5 transactions");
 
   /*******************************************************************
    *
    * Test transaction DoTransaction() error:
@@ -1634,105 +1599,102 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction DoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction UndoTransaction() error:
@@ -1743,112 +1705,107 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->UndoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("UndoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->UndoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("UndoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 6) {
     fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction UndoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction RedoTransaction() error:
@@ -1859,29 +1816,28 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
     fail("QueryInterface() failed for RedoErrorTransaction. (%d)\n",
-         result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+         rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   //
   // Execute a normal transaction to be used in a later test:
   //
 
@@ -1889,717 +1845,687 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   //
   // Undo the 2 transactions just executed.
   //
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
   //
   // The RedoErrorTransaction should now be at the top of the redo stack!
   //
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->RedoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("RedoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->RedoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("RedoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 6) {
     fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction RedoTransaction() error");
 
   /*******************************************************************
    *
    * Make sure that setting the transaction manager's max transaction
    * count to zero, clears both the undo and redo stacks, and executes
    * all new commands without pushing them on the undo stack!
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(0);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->SetMaxTransactionCount(0);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   passed("Test max transaction count of zero");
 
   /*******************************************************************
    *
    * Make sure that setting the transaction manager's max transaction
    * count to something greater than the number of transactions on
    * both the undo and redo stacks causes no pruning of the stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(-1) failed. (%d)\n", rv);
+    return rv;
   }
 
   // Push 20 transactions on the undo stack:
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
     if (numitems != i) {
       fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
-           i, numitems, result);
+           i, numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   for (i = 1; i <= 10; i++) {
-
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->SetMaxTransactionCount(25);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(25) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->SetMaxTransactionCount(25);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(25) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test SetMaxTransactionCount() greater than num stack items");
 
   /*******************************************************************
    *
    * Test undo stack pruning by setting the transaction
    * manager's max transaction count to a number lower than the
    * number of transactions on both the undo and redo stacks:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->SetMaxTransactionCount(15);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(15) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->SetMaxTransactionCount(15);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(15) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-           result);
-    return result;
+           rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test SetMaxTransactionCount() pruning undo stack");
 
   /*******************************************************************
    *
    * Test redo stack pruning by setting the transaction
    * manager's max transaction count to a number lower than the
    * number of transactions on both the undo and redo stacks:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->SetMaxTransactionCount(5);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(5) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->SetMaxTransactionCount(5);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(5) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u2) {
-    fail("Unexpected item at top of undo stack. (%d)\n", result);
+    fail("Unexpected item at top of undo stack. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 0) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfRedoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test SetMaxTransactionCount() pruning redo stack");
 
   /*******************************************************************
    *
    * Release the transaction manager. Any transactions on the undo
    * and redo stack should automatically be released:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(-1) failed. (%d)\n", rv);
+    return rv;
   }
 
   // Push 20 transactions on the undo stack:
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
     if (numitems != i) {
       fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
-           i, numitems, result);
+           i, numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   for (i = 1; i <= 10; i++) {
-
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Release the transaction manager");
 
   /*******************************************************************
    *
    * Make sure number of transactions created matches number of
    * transactions destroyed!
@@ -2680,219 +2606,206 @@ aggregation_test()
 }
 
 /**
  * Test behaviors in batch mode.
  **/
 nsresult
 quick_batch_test(TestTransactionFactory *factory)
 {
-  nsresult result;
-
   /*******************************************************************
    *
    * Create a transaction manager implementation:
    *
    *******************************************************************/
 
+  nsresult rv;
   nsCOMPtr<nsITransactionManager> mgr =
-    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
-  if (NS_FAILED(result) || !mgr) {
+    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
+  if (NS_FAILED(rv) || !mgr) {
     fail("Failed to create Transaction Manager instance.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   passed("Create transaction manager instance");
 
   int32_t numitems;
 
   /*******************************************************************
    *
    * Make sure an unbalanced call to EndBatch(false) with empty undo stack
    * throws an error!
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("EndBatch(false) returned unexpected status. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("EndBatch(false) returned unexpected status. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test unbalanced EndBatch(false) with empty undo stack");
 
   /*******************************************************************
    *
    * Make sure that an empty batch is not added to the undo stack
    * when it is closed.
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test empty batch");
 
   int32_t i;
   TestTransaction *tximpl;
   nsITransaction *tx;
 
   /*******************************************************************
    *
    * Execute 20 transactions. Afterwards, we should have 1
    * transaction on the undo stack:
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 0) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 batched transactions");
 
   nsITransaction *u1, *u2;
   nsITransaction *r1, *r2;
 
@@ -2900,706 +2813,669 @@ quick_batch_test(TestTransactionFactory 
    *
    * Execute 20 transient transactions. Afterwards, we should still
    * have the same transaction on the undo stack:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, TRANSIENT_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 batched transient transactions");
 
   /*******************************************************************
    *
    * Test nested batching. Afterwards, we should have 2 transactions
    * on the undo stack:
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test nested batched transactions");
 
   /*******************************************************************
    *
    * Undo 2 batch transactions. Afterwards, we should have 0
    * transactions on the undo stack and 2 on the redo stack.
    *
    *******************************************************************/
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo 2 batch transactions");
 
   /*******************************************************************
    *
    * Redo 2 batch transactions. Afterwards, we should have 2
    * transactions on the undo stack and 0 on the redo stack.
    *
    *******************************************************************/
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->RedoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->RedoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Redo 2 batch transactions");
 
   /*******************************************************************
    *
    * Call undo. Afterwards, we should have 1 transaction
    * on the undo stack, and 1 on the redo stack:
    *
    *******************************************************************/
 
-  result = mgr->UndoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Failed to undo transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->UndoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Failed to undo transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo a batched transaction that was redone");
 
   /*******************************************************************
    *
    * Make sure an unbalanced call to EndBatch(false) throws an error and
    * doesn't affect the undo and redo stacks!
    *
    *******************************************************************/
 
-  result = mgr->EndBatch(false);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("EndBatch(false) returned unexpected status. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("EndBatch(false) returned unexpected status. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test effect of unbalanced EndBatch(false) on undo and redo stacks");
 
   /*******************************************************************
    *
    * Make sure that an empty batch is not added to the undo stack
    * when it is closed, and that it does not affect the undo and redo
    * stacks.
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test effect of empty batch on undo and redo stacks");
 
   /*******************************************************************
    *
    * Execute a new transaction. The redo stack should get pruned!
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Check if new batched transactions prune the redo stack");
 
   /*******************************************************************
    *
    * Call undo.
    *
    *******************************************************************/
 
   // Move a transaction over to the redo stack, so that we have one
   // transaction on the undo stack, and one on the redo stack!
 
-  result = mgr->UndoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Failed to undo transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->UndoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Failed to undo transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call undo");
 
   /*******************************************************************
    *
    * Test transaction DoTransaction() error:
@@ -3610,119 +3486,113 @@ quick_batch_test(TestTransactionFactory 
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction DoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction UndoTransaction() error:
@@ -3733,126 +3603,119 @@ quick_batch_test(TestTransactionFactory 
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->UndoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("UndoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->UndoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("UndoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction UndoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction RedoTransaction() error:
@@ -3863,412 +3726,389 @@ quick_batch_test(TestTransactionFactory 
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
     fail("QueryInterface() failed for RedoErrorTransaction. (%d)\n",
-         result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+         rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
   }
 
   //
   // Execute a normal transaction to be used in a later test:
   //
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   //
   // Undo the 2 transactions just executed.
   //
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
   //
   // The RedoErrorTransaction should now be at the top of the redo stack!
   //
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->RedoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("RedoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->RedoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("RedoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction RedoTransaction() error");
 
   /*******************************************************************
    *
    * Make sure that setting the transaction manager's max transaction
    * count to zero, clears both the undo and redo stacks, and executes
    * all new commands without pushing them on the undo stack!
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(0);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->SetMaxTransactionCount(0);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->BeginBatch(nullptr);
-
-    if (NS_FAILED(result)) {
-      fail("BeginBatch(nullptr) failed. (%d)\n", result);
-      return result;
+    rv = mgr->BeginBatch(nullptr);
+    if (NS_FAILED(rv)) {
+      fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->EndBatch(false);
-
-    if (NS_FAILED(result)) {
-      fail("EndBatch(false) failed. (%d)\n", result);
-      return result;
+    rv = mgr->EndBatch(false);
+    if (NS_FAILED(rv)) {
+      fail("EndBatch(false) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   passed("Test max transaction count of zero");
 
   /*******************************************************************
    *
    * Release the transaction manager. Any transactions on the undo
    * and redo stack should automatically be released:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
   }
 
   // Push 20 transactions on the undo stack:
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->BeginBatch(nullptr);
-
-    if (NS_FAILED(result)) {
-      fail("BeginBatch(nullptr) failed. (%d)\n", result);
-      return result;
+    rv = mgr->BeginBatch(nullptr);
+    if (NS_FAILED(rv)) {
+      fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->EndBatch(false);
-
-    if (NS_FAILED(result)) {
-      fail("EndBatch(false) failed. (%d)\n", result);
-      return result;
+    rv = mgr->EndBatch(false);
+    if (NS_FAILED(rv)) {
+      fail("EndBatch(false) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
     if (numitems != i) {
       fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
-           i, numitems, result);
+           i, numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   for (i = 1; i <= 10; i++) {
-
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Release the transaction manager");
 
   /*******************************************************************
    *
    * Make sure number of transactions created matches number of
    * transactions destroyed!
@@ -4354,27 +4194,26 @@ aggregation_batch_test()
  * do/undo/redo/undo them.
  **/
 nsresult
 stress_test(TestTransactionFactory *factory, int32_t iterations)
 {
   printf("Stress test of %i iterations (may take a while) ... ", iterations);
   fflush(stdout);
 
-  nsresult result;
-
   /*******************************************************************
    *
    * Create a transaction manager:
    *
    *******************************************************************/
 
+  nsresult rv;
   nsCOMPtr<nsITransactionManager> mgr =
-    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
-  if (NS_FAILED(result) || !mgr) {
+    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
+  if (NS_FAILED(rv) || !mgr) {
     fail("Failed to create Transaction Manager instance.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   int32_t i, j;
   nsITransaction *tx;
 
   for (i = 1; i <= iterations; i++) {
@@ -4388,89 +4227,89 @@ stress_test(TestTransactionFactory *fact
       TestTransaction *tximpl = factory->create(mgr, NONE_FLAG);
 
       if (!tximpl) {
         fail("Failed to allocate transaction %d-%d.\n", i, j);
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
       tx = 0;
-      result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-      if (NS_FAILED(result)) {
+      rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+      if (NS_FAILED(rv)) {
         fail("QueryInterface() failed for transaction %d-%d. (%d)\n",
-             i, j, result);
-        return result;
+             i, j, rv);
+        return rv;
       }
 
-      result = mgr->DoTransaction(tx);
-      if (NS_FAILED(result)) {
+      rv = mgr->DoTransaction(tx);
+      if (NS_FAILED(rv)) {
         fail("Failed to execute transaction %d-%d. (%d)\n",
-             i, j, result);
-        return result;
+             i, j, rv);
+        return rv;
       }
 
       tx->Release();
     }
 
     /*******************************************************************
      *
      * Undo all the transactions:
      *
      *******************************************************************/
 
     for (j = 1; j <= i; j++) {
-      result = mgr->UndoTransaction();
-      if (NS_FAILED(result)) {
-        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, result);
-        return result;
+      rv = mgr->UndoTransaction();
+      if (NS_FAILED(rv)) {
+        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, rv);
+        return rv;
       }
     }
 
     /*******************************************************************
      *
      * Redo all the transactions:
      *
      *******************************************************************/
 
     for (j = 1; j <= i; j++) {
-      result = mgr->RedoTransaction();
-      if (NS_FAILED(result)) {
-        fail("Failed to redo transaction %d-%d. (%d)\n", i, j, result);
-        return result;
+      rv = mgr->RedoTransaction();
+      if (NS_FAILED(rv)) {
+        fail("Failed to redo transaction %d-%d. (%d)\n", i, j, rv);
+        return rv;
       }
     }
 
     /*******************************************************************
      *
      * Undo all the transactions again so that they all end up on
      * the redo stack for pruning the next time we execute a new
      * transaction
      *
      *******************************************************************/
 
     for (j = 1; j <= i; j++) {
-      result = mgr->UndoTransaction();
-      if (NS_FAILED(result)) {
-        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, result);
-        return result;
+      rv = mgr->UndoTransaction();
+      if (NS_FAILED(rv)) {
+        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, rv);
+        return rv;
       }
     }
 
     // Trivial feedback not to let the user think the test is stuck.
     if (MOZ_UNLIKELY(j % 100 == 0)) {
       printf("%i ", j);
     }
   } // for, iterations.
 
   printf("passed\n");
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   /* Disabled because the current cycle collector doesn't delete
      cycle collectable objects synchronously.
   if (sConstructorCount != sDestructorCount) {
     fail("Transaction constructor count (%d) != destructor count (%d).\n",
          sConstructorCount, sDestructorCount);
     return NS_ERROR_FAILURE;
@@ -4597,45 +4436,43 @@ aggregation_batch_stress_test()
 int
 main (int argc, char *argv[])
 {
   ScopedXPCOM xpcom("nsITransactionManager");
   if (xpcom.failed()) {
     return 1;
   }
 
-  nsresult result;
-
   //
   // quick_test() part:
   //
 
-  result = simple_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_test();
-  NS_ENSURE_SUCCESS(result, 1);
+  nsresult rv = simple_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_test();
+  NS_ENSURE_SUCCESS(rv, 1);
 
   //
   // quick_batch_test() part:
   //
 
-  result = simple_batch_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_batch_test();
-  NS_ENSURE_SUCCESS(result, 1);
+  rv = simple_batch_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_batch_test();
+  NS_ENSURE_SUCCESS(rv, 1);
 
   //
   // stress_test() part:
   //
 
-  result = simple_stress_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_stress_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_batch_stress_test();
-  NS_ENSURE_SUCCESS(result, 1);
+  rv = simple_stress_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_stress_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_batch_stress_test();
+  NS_ENSURE_SUCCESS(rv, 1);
 
   return 0;
 }
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -129,85 +129,84 @@ NS_IMPL_CYCLE_COLLECTION(nsTextServicesD
                          mPrevTextBlock,
                          mNextTextBlock,
                          mExtent,
                          mTxtSvcFilter)
 
 NS_IMETHODIMP
 nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor)
 {
-  nsresult result = NS_OK;
   nsCOMPtr<nsISelectionController> selCon;
   nsCOMPtr<nsIDOMDocument> doc;
 
   NS_ENSURE_TRUE(aEditor, NS_ERROR_NULL_POINTER);
 
   LOCK_DOC(this);
 
   // Check to see if we already have an mSelCon. If we do, it
   // better be the same one the editor uses!
 
-  result = aEditor->GetSelectionController(getter_AddRefs(selCon));
-
-  if (NS_FAILED(result)) {
+  nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!selCon || (mSelCon && selCon != mSelCon)) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   if (!mSelCon) {
     mSelCon = selCon;
   }
 
   // Check to see if we already have an mDOMDocument. If we do, it
   // better be the same one the editor uses!
 
-  result = aEditor->GetDocument(getter_AddRefs(doc));
-
-  if (NS_FAILED(result)) {
+  rv = aEditor->GetDocument(getter_AddRefs(doc));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!doc || (mDOMDocument && doc != mDOMDocument)) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   if (!mDOMDocument) {
     mDOMDocument = doc;
 
-    result = CreateDocumentContentIterator(getter_AddRefs(mIterator));
-
-    if (NS_FAILED(result)) {
+    rv = CreateDocumentContentIterator(getter_AddRefs(mIterator));
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     mIteratorStatus = nsTextServicesDocument::eIsDone;
 
-    result = FirstBlock();
-
-    if (NS_FAILED(result)) {
+    rv = FirstBlock();
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
   }
 
   mEditor = do_GetWeakReference(aEditor);
 
-  result = aEditor->AddEditActionListener(this);
+  rv = aEditor->AddEditActionListener(this);
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::GetDocument(nsIDOMDocument **aDoc)
 {
   NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
 
   *aDoc = nullptr; // init out param
@@ -229,79 +228,79 @@ nsTextServicesDocument::SetExtent(nsIDOM
 
   // We need to store a copy of aDOMRange since we don't
   // know where it came from.
 
   mExtent = static_cast<nsRange*>(aDOMRange)->CloneRange();
 
   // Create a new iterator based on our new extent range.
 
-  nsresult result = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
-
-  if (NS_FAILED(result)) {
+  nsresult rv = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   // Now position the iterator at the start of the first block
   // in the range.
 
   mIteratorStatus = nsTextServicesDocument::eIsDone;
 
-  result = FirstBlock();
+  rv = FirstBlock();
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::ExpandRangeToWordBoundaries(nsIDOMRange *aRange)
 {
   NS_ENSURE_ARG_POINTER(aRange);
   RefPtr<nsRange> range = static_cast<nsRange*>(aRange);
 
   // Get the end points of the range.
 
   nsCOMPtr<nsIDOMNode> rngStartNode, rngEndNode;
   int32_t rngStartOffset, rngEndOffset;
 
-  nsresult result =  GetRangeEndPoints(range, getter_AddRefs(rngStartNode),
-                                       &rngStartOffset,
-                                       getter_AddRefs(rngEndNode),
-                                       &rngEndOffset);
-
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = GetRangeEndPoints(range, getter_AddRefs(rngStartNode),
+                                  &rngStartOffset,
+                                  getter_AddRefs(rngEndNode),
+                                  &rngEndOffset);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Create a content iterator based on the range.
 
   nsCOMPtr<nsIContentIterator> iter;
-  result = CreateContentIterator(range, getter_AddRefs(iter));
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Find the first text node in the range.
 
   TSDIteratorStatus iterStatus;
 
-  result = FirstTextNode(iter, &iterStatus);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = FirstTextNode(iter, &iterStatus);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (iterStatus == nsTextServicesDocument::eIsDone) {
     // No text was found so there's no adjustment necessary!
     return NS_OK;
   }
 
   nsINode *firstText = iter->GetCurrentNode();
   NS_ENSURE_TRUE(firstText, NS_ERROR_FAILURE);
 
   // Find the last text node in the range.
 
-  result = LastTextNode(iter, &iterStatus);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = LastTextNode(iter, &iterStatus);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (iterStatus == nsTextServicesDocument::eIsDone) {
     // We should never get here because a first text block
     // was found above.
     NS_ASSERTION(false, "Found a first without a last!");
     return NS_ERROR_FAILURE;
   }
 
@@ -321,193 +320,190 @@ nsTextServicesDocument::ExpandRangeToWor
 
   nsCOMPtr<nsIDOMNode> lastTextNode = do_QueryInterface(lastText);
   NS_ENSURE_TRUE(lastTextNode, NS_ERROR_FAILURE);
 
   if (rngEndNode != lastTextNode) {
     // The range includes the end of the last text node!
     rngEndNode = lastTextNode;
     nsAutoString str;
-    result = lastTextNode->GetNodeValue(str);
+    lastTextNode->GetNodeValue(str);
     rngEndOffset = str.Length();
   }
 
   // Create a doc iterator so that we can scan beyond
   // the bounds of the extent range.
 
   nsCOMPtr<nsIContentIterator> docIter;
-  result = CreateDocumentContentIterator(getter_AddRefs(docIter));
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateDocumentContentIterator(getter_AddRefs(docIter));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Grab all the text in the block containing our
   // first text node.
 
-  result = docIter->PositionAt(firstText);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = docIter->PositionAt(firstText);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   iterStatus = nsTextServicesDocument::eValid;
 
   nsTArray<OffsetEntry*> offsetTable;
   nsAutoString blockStr;
 
-  result = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
-                             nullptr, &blockStr);
-  if (NS_FAILED(result)) {
+  rv = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
+                         nullptr, &blockStr);
+  if (NS_FAILED(rv)) {
     ClearOffsetTable(&offsetTable);
-    return result;
+    return rv;
   }
 
   nsCOMPtr<nsIDOMNode> wordStartNode, wordEndNode;
   int32_t wordStartOffset, wordEndOffset;
 
-  result = FindWordBounds(&offsetTable, &blockStr,
-                          rngStartNode, rngStartOffset,
-                          getter_AddRefs(wordStartNode), &wordStartOffset,
-                          getter_AddRefs(wordEndNode), &wordEndOffset);
+  rv = FindWordBounds(&offsetTable, &blockStr,
+                      rngStartNode, rngStartOffset,
+                      getter_AddRefs(wordStartNode), &wordStartOffset,
+                      getter_AddRefs(wordEndNode), &wordEndOffset);
 
   ClearOffsetTable(&offsetTable);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rngStartNode = wordStartNode;
   rngStartOffset = wordStartOffset;
 
   // Grab all the text in the block containing our
   // last text node.
 
-  result = docIter->PositionAt(lastText);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = docIter->PositionAt(lastText);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   iterStatus = nsTextServicesDocument::eValid;
 
-  result = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
-                             nullptr, &blockStr);
-  if (NS_FAILED(result)) {
+  rv = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
+                         nullptr, &blockStr);
+  if (NS_FAILED(rv)) {
     ClearOffsetTable(&offsetTable);
-    return result;
+    return rv;
   }
 
-  result = FindWordBounds(&offsetTable, &blockStr,
-                          rngEndNode, rngEndOffset,
-                          getter_AddRefs(wordStartNode), &wordStartOffset,
-                          getter_AddRefs(wordEndNode), &wordEndOffset);
+  rv = FindWordBounds(&offsetTable, &blockStr,
+                      rngEndNode, rngEndOffset,
+                      getter_AddRefs(wordStartNode), &wordStartOffset,
+                      getter_AddRefs(wordEndNode), &wordEndOffset);
 
   ClearOffsetTable(&offsetTable);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // To prevent expanding the range too much, we only change
   // rngEndNode and rngEndOffset if it isn't already at the start of the
   // word and isn't equivalent to rngStartNode and rngStartOffset.
 
   if (rngEndNode != wordStartNode ||
       rngEndOffset != wordStartOffset ||
       (rngEndNode == rngStartNode && rngEndOffset == rngStartOffset)) {
     rngEndNode = wordEndNode;
     rngEndOffset = wordEndOffset;
   }
 
   // Now adjust the range so that it uses our new
   // end points.
 
-  result = range->SetEnd(rngEndNode, rngEndOffset);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = range->SetEnd(rngEndNode, rngEndOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return range->SetStart(rngStartNode, rngStartOffset);
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::SetFilter(nsITextServicesFilter *aFilter)
 {
   // Hang on to the filter so we can set it into the filtered iterator.
   mTxtSvcFilter = aFilter;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::GetCurrentTextBlock(nsString *aStr)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aStr, NS_ERROR_NULL_POINTER);
 
   aStr->Truncate();
 
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
-  result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                             mExtent, aStr);
+  nsresult rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                                  mExtent, aStr);
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::FirstBlock()
 {
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
-  nsresult result = FirstTextNode(mIterator, &mIteratorStatus);
-
-  if (NS_FAILED(result)) {
+  nsresult rv = FirstTextNode(mIterator, &mIteratorStatus);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   // Keep track of prev and next blocks, just in case
   // the text service blows away the current block.
 
   if (mIteratorStatus == nsTextServicesDocument::eValid) {
     mPrevTextBlock  = nullptr;
-    result = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
+    rv = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
   } else {
     // There's no text block in the document!
 
     mPrevTextBlock  = nullptr;
     mNextTextBlock  = nullptr;
   }
 
   UNLOCK_DOC(this);
 
-  return result;
+  // XXX Result of FirstTextNode() or GetFirstTextNodeInNextBlock().
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus,
                                           int32_t *aSelOffset,
                                           int32_t *aSelLength)
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
 
   LOCK_DOC(this);
 
   mIteratorStatus = nsTextServicesDocument::eIsDone;
 
   *aSelStatus = nsITextServicesDocument::eBlockNotFound;
   *aSelOffset = *aSelLength = -1;
 
   if (!mSelCon || !mIterator) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsISelection> domSelection;
-  result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                                 getter_AddRefs(domSelection));
-  if (NS_FAILED(result)) {
+  nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
+                                      getter_AddRefs(domSelection));
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   RefPtr<Selection> selection = domSelection->AsSelection();
 
   bool isCollapsed = selection->IsCollapsed();
 
   nsCOMPtr<nsIContentIterator> iter;
   RefPtr<nsRange> range;
@@ -522,113 +518,115 @@ nsTextServicesDocument::LastSelectedBloc
 
     range = selection->GetRangeAt(0);
 
     if (!range) {
       UNLOCK_DOC(this);
       return NS_ERROR_FAILURE;
     }
 
-    result = range->GetStartContainer(getter_AddRefs(parent));
-
-    if (NS_FAILED(result)) {
+    rv = range->GetStartContainer(getter_AddRefs(parent));
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     if (!parent) {
       UNLOCK_DOC(this);
       return NS_ERROR_FAILURE;
     }
 
-    result = range->GetStartOffset(&offset);
-
-    if (NS_FAILED(result)) {
+    rv = range->GetStartOffset(&offset);
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     if (IsTextNode(parent)) {
       // The caret is in a text node. Find the beginning
       // of the text block containing this text node and
       // return.
 
       nsCOMPtr<nsIContent> content(do_QueryInterface(parent));
 
       if (!content) {
         UNLOCK_DOC(this);
         return NS_ERROR_FAILURE;
       }
 
-      result = mIterator->PositionAt(content);
-
-      if (NS_FAILED(result)) {
+      rv = mIterator->PositionAt(content);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = FirstTextNodeInCurrentBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      rv = FirstTextNodeInCurrentBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
 
-      result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                 mExtent, nullptr);
-
-      if (NS_FAILED(result)) {
+      rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                             mExtent, nullptr);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = GetSelection(aSelStatus, aSelOffset, aSelLength);
-
-      if (NS_FAILED(result)) {
+      rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      if (*aSelStatus == nsITextServicesDocument::eBlockContains)
-        result = SetSelectionInternal(*aSelOffset, *aSelLength, false);
+      if (*aSelStatus == nsITextServicesDocument::eBlockContains) {
+        rv = SetSelectionInternal(*aSelOffset, *aSelLength, false);
+      }
     } else {
       // The caret isn't in a text node. Create an iterator
       // based on a range that extends from the current caret
       // position to the end of the document, then walk forwards
       // till you find a text node, then find the beginning of it's block.
 
-      result = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false, getter_AddRefs(range));
-
-      if (NS_FAILED(result)) {
+      rv = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false,
+                                                      getter_AddRefs(range));
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = range->GetCollapsed(&isCollapsed);
-
-      if (NS_FAILED(result)) {
+      rv = range->GetCollapsed(&isCollapsed);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       if (isCollapsed) {
         // If we get here, the range is collapsed because there is nothing after
         // the caret! Just return NS_OK;
 
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
-      result = CreateContentIterator(range, getter_AddRefs(iter));
-
-      if (NS_FAILED(result)) {
+      rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       iter->First();
 
       nsCOMPtr<nsIContent> content;
       while (!iter->IsDone()) {
         content = do_QueryInterface(iter->GetCurrentNode());
 
@@ -641,64 +639,65 @@ nsTextServicesDocument::LastSelectedBloc
         iter->Next();
       }
 
       if (!content) {
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
-      result = mIterator->PositionAt(content);
-
-      if (NS_FAILED(result)) {
+      rv = mIterator->PositionAt(content);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = FirstTextNodeInCurrentBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      rv = FirstTextNodeInCurrentBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
 
-      result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                 mExtent, nullptr);
-
-      if (NS_FAILED(result)) {
+      rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                             mExtent, nullptr);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = GetSelection(aSelStatus, aSelOffset, aSelLength);
-
-      if (NS_FAILED(result)) {
+      rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
     }
 
     UNLOCK_DOC(this);
 
-    return result;
+    // Result of SetSelectionInternal() in the |if| block or NS_OK.
+    return rv;
   }
 
   // If we get here, we have an uncollapsed selection!
   // Look backwards through each range in the selection till you
   // find the first text node. If you find one, find the
   // beginning of its text block, and make it the current
   // block.
 
-  result = selection->GetRangeCount(&rangeCount);
-
-  if (NS_FAILED(result)) {
+  rv = selection->GetRangeCount(&rangeCount);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   NS_ASSERTION(rangeCount > 0, "Unexpected range count!");
 
   if (rangeCount <= 0) {
     UNLOCK_DOC(this);
     return NS_OK;
   }
@@ -708,68 +707,68 @@ nsTextServicesDocument::LastSelectedBloc
 
   for (int32_t i = rangeCount - 1; i >= 0; i--) {
     // Get the i'th range from the selection.
 
     range = selection->GetRangeAt(i);
 
     if (!range) {
       UNLOCK_DOC(this);
-      return result;
+      return NS_OK; // XXX Really?
     }
 
     // Create an iterator for the range.
 
-    result = CreateContentIterator(range, getter_AddRefs(iter));
-
-    if (NS_FAILED(result)) {
+    rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     iter->Last();
 
     // Now walk through the range till we find a text node.
 
     while (!iter->IsDone()) {
       if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) {
         // We found a text node, so position the document's
         // iterator at the beginning of the block, then get
         // the selection in terms of the string offset.
         nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
 
-        result = mIterator->PositionAt(content);
-
-        if (NS_FAILED(result)) {
+        rv = mIterator->PositionAt(content);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
-        result = FirstTextNodeInCurrentBlock(mIterator);
-
-        if (NS_FAILED(result)) {
+        rv = FirstTextNodeInCurrentBlock(mIterator);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
         mIteratorStatus = nsTextServicesDocument::eValid;
 
-        result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                   mExtent, nullptr);
-
-        if (NS_FAILED(result)) {
+        rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                               mExtent, nullptr);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
-        result = GetSelection(aSelStatus, aSelOffset, aSelLength);
+        rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
 
         UNLOCK_DOC(this);
 
-        return result;
+        return rv;
 
       }
 
       iter->Prev();
     }
   }
 
   // If we get here, we didn't find any text node in the selection!
@@ -779,215 +778,213 @@ nsTextServicesDocument::LastSelectedBloc
 
   range = selection->GetRangeAt(rangeCount - 1);
 
   if (!range) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
-  result = range->GetEndContainer(getter_AddRefs(parent));
-
-  if (NS_FAILED(result)) {
+  rv = range->GetEndContainer(getter_AddRefs(parent));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!parent) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
-  result = range->GetEndOffset(&offset);
-
-  if (NS_FAILED(result)) {
+  rv = range->GetEndOffset(&offset);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
-  result = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false, getter_AddRefs(range));
-
-  if (NS_FAILED(result)) {
+  rv = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false,
+                                                  getter_AddRefs(range));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
-  result = range->GetCollapsed(&isCollapsed);
-
-  if (NS_FAILED(result)) {
+  rv = range->GetCollapsed(&isCollapsed);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (isCollapsed) {
     // If we get here, the range is collapsed because there is nothing after
     // the current selection! Just return NS_OK;
 
     UNLOCK_DOC(this);
     return NS_OK;
   }
 
-  result = CreateContentIterator(range, getter_AddRefs(iter));
-
-  if (NS_FAILED(result)) {
+  rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   iter->First();
 
   while (!iter->IsDone()) {
     if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) {
       // We found a text node! Adjust the document's iterator to point
       // to the beginning of its text block, then get the current selection.
       nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
 
-      result = mIterator->PositionAt(content);
-
-      if (NS_FAILED(result)) {
+      rv = mIterator->PositionAt(content);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = FirstTextNodeInCurrentBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      rv = FirstTextNodeInCurrentBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
 
       mIteratorStatus = nsTextServicesDocument::eValid;
 
-      result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                 mExtent, nullptr);
-
-      if (NS_FAILED(result)) {
+      rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                             mExtent, nullptr);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = GetSelection(aSelStatus, aSelOffset, aSelLength);
+      rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
 
       UNLOCK_DOC(this);
 
-      return result;
+      return rv;
     }
 
     iter->Next();
   }
 
   // If we get here, we didn't find any block before or inside
   // the selection! Just return OK.
 
   UNLOCK_DOC(this);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::PrevBlock()
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone) {
     return NS_OK;
   }
 
   switch (mIteratorStatus) {
     case nsTextServicesDocument::eValid:
-    case nsTextServicesDocument::eNext:
-
-      result = FirstTextNodeInPrevBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+    case nsTextServicesDocument::eNext: {
+
+      nsresult rv = FirstTextNodeInPrevBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       if (mIterator->IsDone()) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
-
+    }
     case nsTextServicesDocument::ePrev:
 
       // The iterator already points to the previous
       // block, so don't do anything.
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
 
     default:
 
       mIteratorStatus = nsTextServicesDocument::eIsDone;
       break;
   }
 
   // Keep track of prev and next blocks, just in case
   // the text service blows away the current block.
-
+  nsresult rv = NS_OK;
   if (mIteratorStatus == nsTextServicesDocument::eValid) {
-    result = GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
-    result = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
+    GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
+    rv = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
   } else {
     // We must be done!
     mPrevTextBlock = nullptr;
     mNextTextBlock = nullptr;
   }
 
   UNLOCK_DOC(this);
 
-  return result;
+  // XXX The result of GetFirstTextNodeInNextBlock() or NS_OK.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::NextBlock()
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone) {
     return NS_OK;
   }
 
   switch (mIteratorStatus) {
-    case nsTextServicesDocument::eValid:
+    case nsTextServicesDocument::eValid: {
 
       // Advance the iterator to the next text block.
 
-      result = FirstTextNodeInNextBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      nsresult rv = FirstTextNodeInNextBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       if (mIterator->IsDone()) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
-
+    }
     case nsTextServicesDocument::eNext:
 
       // The iterator already points to the next block,
       // so don't do anything to it!
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
 
@@ -1000,29 +997,30 @@ nsTextServicesDocument::NextBlock()
     default:
 
       mIteratorStatus = nsTextServicesDocument::eIsDone;
       break;
   }
 
   // Keep track of prev and next blocks, just in case
   // the text service blows away the current block.
-
+  nsresult rv = NS_OK;
   if (mIteratorStatus == nsTextServicesDocument::eValid) {
-    result = GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
-    result = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
+    GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
+    rv = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
   } else {
     // We must be done.
     mPrevTextBlock = nullptr;
     mNextTextBlock = nullptr;
   }
 
   UNLOCK_DOC(this);
 
-  return result;
+  // The result of GetFirstTextNodeInNextBlock() or NS_OK.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::IsDone(bool *aIsDone)
 {
   NS_ENSURE_TRUE(aIsDone, NS_ERROR_NULL_POINTER);
 
   *aIsDone = false;
@@ -1036,57 +1034,54 @@ nsTextServicesDocument::IsDone(bool *aIs
   UNLOCK_DOC(this);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::SetSelection(int32_t aOffset, int32_t aLength)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
-  result = SetSelectionInternal(aOffset, aLength, true);
+  nsresult rv = SetSelectionInternal(aOffset, aLength, true);
 
   UNLOCK_DOC(this);
 
   //**** KDEBUG ****
   // printf("\n * Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   //**** KDEBUG ****
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::ScrollSelectionIntoView()
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(mSelCon, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   // After ScrollSelectionIntoView(), the pending notifications might be flushed
   // and PresShell/PresContext/Frames may be dead. See bug 418470.
-  result = mSelCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION,
-                                            nsISelectionController::SCROLL_SYNCHRONOUS);
+  nsresult rv =
+    mSelCon->ScrollSelectionIntoView(
+      nsISelectionController::SELECTION_NORMAL,
+      nsISelectionController::SELECTION_FOCUS_REGION,
+      nsISelectionController::SCROLL_SYNCHRONOUS);
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::DeleteSelection()
 {
-  nsresult result = NS_OK;
-
   // We don't allow deletion during a collapsed selection!
   nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
   NS_ASSERTION(editor, "DeleteSelection called without an editor present!");
   NS_ASSERTION(SelectionIsValid(), "DeleteSelection called without a valid selection!");
 
   if (!editor || !SelectionIsValid()) {
     return NS_ERROR_FAILURE;
   }
@@ -1105,23 +1100,24 @@ nsTextServicesDocument::DeleteSelection(
   // If we have an mExtent, save off its current set of
   // end points so we can compare them against mExtent's
   // set after the deletion of the content.
 
   nsCOMPtr<nsIDOMNode> origStartNode, origEndNode;
   int32_t origStartOffset = 0, origEndOffset = 0;
 
   if (mExtent) {
-    result = GetRangeEndPoints(mExtent,
-                               getter_AddRefs(origStartNode), &origStartOffset,
-                               getter_AddRefs(origEndNode), &origEndOffset);
-
-    if (NS_FAILED(result)) {
+    nsresult rv =
+      GetRangeEndPoints(mExtent,
+                        getter_AddRefs(origStartNode), &origStartOffset,
+                        getter_AddRefs(origEndNode), &origEndOffset);
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
   }
 
   int32_t selLength;
   OffsetEntry *entry, *newEntry;
 
   for (int32_t i = mSelStartIndex; i <= mSelEndIndex; i++) {
     entry = mOffsetTable[i];
@@ -1143,21 +1139,21 @@ nsTextServicesDocument::DeleteSelection(
       }
 
       if (selLength > 0 && mSelStartOffset > entry->mStrOffset) {
         // Selection doesn't start at the beginning of the
         // text node entry. We need to split this entry into
         // two pieces, the piece before the selection, and
         // the piece inside the selection.
 
-        result = SplitOffsetEntry(i, selLength);
-
-        if (NS_FAILED(result)) {
+        nsresult rv = SplitOffsetEntry(i, selLength);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
         // Adjust selection indexes to account for new entry:
 
         ++mSelStartIndex;
         ++mSelEndIndex;
         ++i;
 
@@ -1193,21 +1189,21 @@ nsTextServicesDocument::DeleteSelection(
 
         selLength = mSelEndOffset - entry->mStrOffset;
 
         if (selLength > 0 &&
             mSelEndOffset < entry->mStrOffset + entry->mLength) {
           // mStrOffset is guaranteed to be inside the selection, even
           // when mSelStartIndex == mSelEndIndex.
 
-          result = SplitOffsetEntry(i, entry->mLength - selLength);
-
-          if (NS_FAILED(result)) {
+          nsresult rv = SplitOffsetEntry(i, entry->mLength - selLength);
+
+          if (NS_FAILED(rv)) {
             UNLOCK_DOC(this);
-            return result;
+            return rv;
           }
 
           // Update the entry fields:
 
           newEntry = mOffsetTable[i+1];
           newEntry->mNodeOffset = entry->mNodeOffset;
         }
 
@@ -1229,38 +1225,39 @@ nsTextServicesDocument::DeleteSelection(
   }
 
   // Make sure mIterator always points to something valid!
 
   AdjustContentIterator();
 
   // Now delete the actual content!
 
-  result = editor->DeleteSelection(nsIEditor::ePrevious, nsIEditor::eStrip);
-
-  if (NS_FAILED(result)) {
+  nsresult rv =
+    editor->DeleteSelection(nsIEditor::ePrevious, nsIEditor::eStrip);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   // Now that we've actually deleted the selected content,
   // check to see if our mExtent has changed, if so, then
   // we have to create a new content iterator!
 
   if (origStartNode && origEndNode) {
     nsCOMPtr<nsIDOMNode> curStartNode, curEndNode;
     int32_t curStartOffset = 0, curEndOffset = 0;
 
-    result = GetRangeEndPoints(mExtent,
-                               getter_AddRefs(curStartNode), &curStartOffset,
-                               getter_AddRefs(curEndNode), &curEndOffset);
-
-    if (NS_FAILED(result)) {
+    rv = GetRangeEndPoints(mExtent,
+                           getter_AddRefs(curStartNode), &curStartOffset,
+                           getter_AddRefs(curEndNode), &curEndOffset);
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     if (origStartNode != curStartNode || origEndNode != curEndNode) {
       // The range has changed, so we need to create a new content
       // iterator based on the new range.
 
       nsCOMPtr<nsIContent> curContent;
 
@@ -1271,30 +1268,30 @@ nsTextServicesDocument::DeleteSelection(
 
         curContent = mIterator->GetCurrentNode()
                      ? mIterator->GetCurrentNode()->AsContent()
                      : nullptr;
       }
 
       // Create the new iterator.
 
-      result = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
-
-      if (NS_FAILED(result)) {
+      rv = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       // Now make the new iterator point to the content node
       // the old one was pointing at.
 
       if (curContent) {
-        result = mIterator->PositionAt(curContent);
-
-        if (NS_FAILED(result)) {
+        rv = mIterator->PositionAt(curContent);
+
+        if (NS_FAILED(rv)) {
           mIteratorStatus = eIsDone;
         } else {
           mIteratorStatus = eValid;
         }
       }
     }
   }
 
@@ -1325,44 +1322,42 @@ nsTextServicesDocument::DeleteSelection(
       entry = 0;
     } else {
       mSelStartIndex = mSelEndIndex = i;
       mSelStartOffset = mSelEndOffset = entry->mStrOffset;
     }
   }
 
   if (entry) {
-    result = SetSelection(mSelStartOffset, 0);
+    SetSelection(mSelStartOffset, 0);
   } else {
     // Uuughh we have no valid offset entry to place our
     // caret ... just mark the selection invalid.
     mSelStartIndex  = mSelEndIndex  = -1;
     mSelStartOffset = mSelEndOffset = -1;
   }
 
   // Now remove any invalid entries from the offset table.
 
-  result = RemoveInvalidOffsetEntries();
+  rv = RemoveInvalidOffsetEntries();
 
   //**** KDEBUG ****
   // printf("\n---- After Delete\n");
   // printf("Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   // PrintOffsetTable();
   //**** KDEBUG ****
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::InsertText(const nsString *aText)
 {
-  nsresult result = NS_OK;
-
   nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
   NS_ASSERTION(editor, "InsertText called without an editor present!");
 
   if (!editor || !SelectionIsValid()) {
     return NS_ERROR_FAILURE;
   }
 
   NS_ENSURE_TRUE(aText, NS_ERROR_NULL_POINTER);
@@ -1377,40 +1372,40 @@ nsTextServicesDocument::InsertText(const
   bool collapsedSelection = SelectionIsCollapsed();
   int32_t savedSelOffset = mSelStartOffset;
   int32_t savedSelLength = mSelEndOffset - mSelStartOffset;
 
   if (!collapsedSelection) {
     // Collapse to the start of the current selection
     // for the insert!
 
-    result = SetSelection(mSelStartOffset, 0);
-
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv = SetSelection(mSelStartOffset, 0);
+
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
 
   LOCK_DOC(this);
 
-  result = editor->BeginTransaction();
-
-  if (NS_FAILED(result)) {
+  nsresult rv = editor->BeginTransaction();
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
-  nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(editor, &result));
+  nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(editor, &rv));
   if (textEditor) {
-    result = textEditor->InsertText(*aText);
+    rv = textEditor->InsertText(*aText);
   }
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     editor->EndTransaction();
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   //**** KDEBUG ****
   // printf("\n---- Before Insert\n");
   // printf("Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   // PrintOffsetTable();
   //**** KDEBUG ****
 
@@ -1501,45 +1496,47 @@ nsTextServicesDocument::InsertText(const
     // We have a valid inserted text offset entry. Update its
     // length, adjust the selection indexes, and make sure the
     // caret is properly placed!
 
     itEntry->mLength += strLength;
 
     mSelStartIndex = mSelEndIndex = i;
 
-    result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
-
-    if (NS_FAILED(result)) {
+    rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
+                               getter_AddRefs(selection));
+
+    if (NS_FAILED(rv)) {
       editor->EndTransaction();
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
-    result = selection->Collapse(itEntry->mNode, itEntry->mNodeOffset + itEntry->mLength);
-
-    if (NS_FAILED(result)) {
+    rv = selection->Collapse(itEntry->mNode,
+                             itEntry->mNodeOffset + itEntry->mLength);
+
+    if (NS_FAILED(rv)) {
       editor->EndTransaction();
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
   } else if (entry->mStrOffset + entry->mLength > mSelStartOffset) {
     // We are inserting text into the middle of the current offset entry.
     // split the current entry into two parts, then insert an inserted text
     // entry between them!
 
     // XXX Rename this!
     uint32_t i = entry->mLength - (mSelStartOffset - entry->mStrOffset);
 
-    result = SplitOffsetEntry(mSelStartIndex, i);
-
-    if (NS_FAILED(result)) {
+    rv = SplitOffsetEntry(mSelStartIndex, i);
+
+    if (NS_FAILED(rv)) {
       editor->EndTransaction();
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     itEntry = new OffsetEntry(entry->mNode, mSelStartOffset, strLength);
 
     if (!itEntry) {
       editor->EndTransaction();
       UNLOCK_DOC(this);
       return NS_ERROR_OUT_OF_MEMORY;
@@ -1573,38 +1570,38 @@ nsTextServicesDocument::InsertText(const
 
   //**** KDEBUG ****
   // printf("\n---- After Insert\n");
   // printf("Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   // PrintOffsetTable();
   //**** KDEBUG ****
 
   if (!collapsedSelection) {
-    result = SetSelection(savedSelOffset, savedSelLength);
-
-    if (NS_FAILED(result)) {
+    rv = SetSelection(savedSelOffset, savedSelLength);
+
+    if (NS_FAILED(rv)) {
       editor->EndTransaction();
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
-    result = DeleteSelection();
-
-    if (NS_FAILED(result)) {
+    rv = DeleteSelection();
+
+    if (NS_FAILED(rv)) {
       editor->EndTransaction();
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
   }
 
-  result = editor->EndTransaction();
+  rv = editor->EndTransaction();
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::DidInsertNode(nsIDOMNode *aNode,
                                       nsIDOMNode *aParent,
                                       int32_t     aPosition,
                                       nsresult    aResult)
 {
@@ -1624,21 +1621,22 @@ nsTextServicesDocument::DidDeleteNode(ns
   //**** KDEBUG ****
 
   LOCK_DOC(this);
 
   int32_t nodeIndex = 0;
   bool hasEntry = false;
   OffsetEntry *entry;
 
-  nsresult result = NodeHasOffsetEntry(&mOffsetTable, aChild, &hasEntry, &nodeIndex);
-
-  if (NS_FAILED(result)) {
+  nsresult rv =
+    NodeHasOffsetEntry(&mOffsetTable, aChild, &hasEntry, &nodeIndex);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!hasEntry) {
     // It's okay if the node isn't in the offset table, the
     // editor could be cleaning house.
     UNLOCK_DOC(this);
     return NS_OK;
   }
@@ -1694,59 +1692,58 @@ nsTextServicesDocument::DidSplitNode(nsI
 NS_IMETHODIMP
 nsTextServicesDocument::DidJoinNodes(nsIDOMNode  *aLeftNode,
                                      nsIDOMNode  *aRightNode,
                                      nsIDOMNode  *aParent,
                                      nsresult     aResult)
 {
   NS_ENSURE_SUCCESS(aResult, NS_OK);
 
-  uint16_t type;
-  nsresult result;
-
   //**** KDEBUG ****
   // printf("** JoinNodes: 0x%.8x  0x%.8x  0x%.8x\n", aLeftNode, aRightNode, aParent);
   // fflush(stdout);
   //**** KDEBUG ****
 
   // Make sure that both nodes are text nodes -- otherwise we don't care.
 
-  result = aLeftNode->GetNodeType(&type);
-  NS_ENSURE_SUCCESS(result, NS_OK);
+  uint16_t type;
+  nsresult rv = aLeftNode->GetNodeType(&type);
+  NS_ENSURE_SUCCESS(rv, NS_OK);
   if (nsIDOMNode::TEXT_NODE != type) {
     return NS_OK;
   }
 
-  result = aRightNode->GetNodeType(&type);
-  NS_ENSURE_SUCCESS(result, NS_OK);
+  rv = aRightNode->GetNodeType(&type);
+  NS_ENSURE_SUCCESS(rv, NS_OK);
   if (nsIDOMNode::TEXT_NODE != type) {
     return NS_OK;
   }
 
   // Note: The editor merges the contents of the left node into the
   //       contents of the right.
 
   int32_t leftIndex = 0;
   int32_t rightIndex = 0;
   bool leftHasEntry = false;
   bool rightHasEntry = false;
 
-  result = NodeHasOffsetEntry(&mOffsetTable, aLeftNode, &leftHasEntry, &leftIndex);
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = NodeHasOffsetEntry(&mOffsetTable, aLeftNode, &leftHasEntry, &leftIndex);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (!leftHasEntry) {
     // It's okay if the node isn't in the offset table, the
     // editor could be cleaning house.
     return NS_OK;
   }
 
-  result = NodeHasOffsetEntry(&mOffsetTable, aRightNode, &rightHasEntry, &rightIndex);
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = NodeHasOffsetEntry(&mOffsetTable, aRightNode,
+                          &rightHasEntry, &rightIndex);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (!rightHasEntry) {
     // It's okay if the node isn't in the offset table, the
     // editor could be cleaning house.
     return NS_OK;
   }
 
   NS_ASSERTION(leftIndex < rightIndex, "Indexes out of order.");
@@ -1760,17 +1757,17 @@ nsTextServicesDocument::DidJoinNodes(nsI
 
   OffsetEntry *entry = mOffsetTable[rightIndex];
   NS_ASSERTION(entry->mNodeOffset == 0, "Unexpected offset value for rightIndex.");
 
   // Run through the table and change all entries referring to
   // the left node so that they now refer to the right node:
 
   nsAutoString str;
-  result = aLeftNode->GetNodeValue(str);
+  aLeftNode->GetNodeValue(str);
   int32_t nodeLength = str.Length();
 
   for (int32_t i = leftIndex; i < rightIndex; i++) {
     entry = mOffsetTable[i];
     if (entry->mNode != aLeftNode) {
       break;
     }
     if (entry->mIsValid) {
@@ -1799,17 +1796,17 @@ nsTextServicesDocument::DidJoinNodes(nsI
   nsCOMPtr<nsIContent> rightContent = do_QueryInterface(aRightNode);
 
   if (!leftContent || !rightContent) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   if (mIterator->GetCurrentNode() == leftContent) {
-    result = mIterator->PositionAt(rightContent);
+    mIterator->PositionAt(rightContent);
   }
 
   UNLOCK_DOC(this);
 
   return NS_OK;
 }
 
 nsresult
@@ -1820,65 +1817,63 @@ nsTextServicesDocument::CreateContentIte
 
   *aIterator = nullptr;
 
   // Create a nsFilteredContentIterator
   // This class wraps the ContentIterator in order to give itself a chance
   // to filter out certain content nodes
   RefPtr<nsFilteredContentIterator> filter = new nsFilteredContentIterator(mTxtSvcFilter);
 
-  nsresult result = filter->Init(aRange);
-  if (NS_FAILED(result)) {
-    return result;
+  nsresult rv = filter->Init(aRange);
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   filter.forget(aIterator);
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::GetDocumentContentRootNode(nsIDOMNode **aNode)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   *aNode = 0;
 
   NS_ENSURE_TRUE(mDOMDocument, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mDOMDocument);
 
   if (htmlDoc) {
     // For HTML documents, the content root node is the body.
 
     nsCOMPtr<nsIDOMHTMLElement> bodyElement;
 
-    result = htmlDoc->GetBody(getter_AddRefs(bodyElement));
-
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv = htmlDoc->GetBody(getter_AddRefs(bodyElement));
+
+    NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ENSURE_TRUE(bodyElement, NS_ERROR_FAILURE);
 
     bodyElement.forget(aNode);
   } else {
     // For non-HTML documents, the content root node will be the document element.
 
     nsCOMPtr<nsIDOMElement> docElement;
 
-    result = mDOMDocument->GetDocumentElement(getter_AddRefs(docElement));
-
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv = mDOMDocument->GetDocumentElement(getter_AddRefs(docElement));
+
+    NS_ENSURE_SUCCESS(rv, rv);
 
     NS_ENSURE_TRUE(docElement, NS_ERROR_FAILURE);
 
     docElement.forget(aNode);
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::CreateDocumentContentRange(nsRange** aRange)
 {
   *aRange = nullptr;
 
   nsCOMPtr<nsIDOMNode> node;
@@ -1943,36 +1938,30 @@ nsTextServicesDocument::CreateDocumentCo
 
   return nsRange::CreateRange(startNode, startOffset, endNode, endOffset,
                               aRange);
 }
 
 nsresult
 nsTextServicesDocument::CreateDocumentContentIterator(nsIContentIterator **aIterator)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   RefPtr<nsRange> range;
 
-  result = CreateDocumentContentRange(getter_AddRefs(range));
-
-  NS_ENSURE_SUCCESS(result, result);
-
-  result = CreateContentIterator(range, aIterator);
-
-  return result;
+  nsresult rv = CreateDocumentContentRange(getter_AddRefs(range));
+
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return CreateContentIterator(range, aIterator);
 }
 
 nsresult
 nsTextServicesDocument::AdjustContentIterator()
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mIterator->GetCurrentNode()));
 
   NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
   nsIDOMNode *nodePtr = node.get();
   int32_t tcount      = mOffsetTable.Length();
@@ -2012,46 +2001,46 @@ nsTextServicesDocument::AdjustContentIte
 
   if (prevValidNode) {
     content = do_QueryInterface(prevValidNode);
   } else if (nextValidNode) {
     content = do_QueryInterface(nextValidNode);
   }
 
   if (content) {
-    result = mIterator->PositionAt(content);
-
-    if (NS_FAILED(result)) {
+    nsresult rv = mIterator->PositionAt(content);
+
+    if (NS_FAILED(rv)) {
       mIteratorStatus = eIsDone;
     } else {
       mIteratorStatus = eValid;
     }
-    return result;
+    return rv;
   }
 
   // If we get here, there aren't any valid entries
   // in the offset table! Try to position the iterator
   // on the next text block first, then previous if
   // one doesn't exist!
 
   if (mNextTextBlock) {
-    result = mIterator->PositionAt(mNextTextBlock);
-
-    if (NS_FAILED(result)) {
+    nsresult rv = mIterator->PositionAt(mNextTextBlock);
+
+    if (NS_FAILED(rv)) {
       mIteratorStatus = eIsDone;
-      return result;
+      return rv;
     }
 
     mIteratorStatus = eNext;
   } else if (mPrevTextBlock) {
-    result = mIterator->PositionAt(mPrevTextBlock);
-
-    if (NS_FAILED(result)) {
+    nsresult rv = mIterator->PositionAt(mPrevTextBlock);
+
+    if (NS_FAILED(rv)) {
       mIteratorStatus = eIsDone;
-      return result;
+      return rv;
     }
 
     mIteratorStatus = ePrev;
   } else {
     mIteratorStatus = eIsDone;
   }
   return NS_OK;
 }
@@ -2160,18 +2149,16 @@ nsTextServicesDocument::IsTextNode(nsIDO
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   return IsTextNode(content);
 }
 
 nsresult
 nsTextServicesDocument::SetSelectionInternal(int32_t aOffset, int32_t aLength, bool aDoUpdate)
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
 
   nsIDOMNode *sNode = 0, *eNode = 0;
   int32_t sOffset = 0, eOffset = 0;
   OffsetEntry *entry;
 
   // Find start of selection in node offset terms:
 
@@ -2226,23 +2213,25 @@ nsTextServicesDocument::SetSelectionInte
   NS_ENSURE_TRUE(sNode, NS_ERROR_FAILURE);
 
   // XXX: If we ever get a SetSelection() method in nsIEditor, we should
   //      use it.
 
   nsCOMPtr<nsISelection> selection;
 
   if (aDoUpdate) {
-    result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
-
-    NS_ENSURE_SUCCESS(result, result);
-
-    result = selection->Collapse(sNode, sOffset);
-
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv =
+      mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
+                            getter_AddRefs(selection));
+
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = selection->Collapse(sNode, sOffset);
+
+    NS_ENSURE_SUCCESS(rv, rv);
    }
 
   if (aLength <= 0) {
     // We have a collapsed selection. (Caret)
 
     mSelEndIndex  = mSelStartIndex;
     mSelEndOffset = mSelStartOffset;
 
@@ -2276,82 +2265,82 @@ nsTextServicesDocument::SetSelectionInte
       if (eNode) {
         mSelEndIndex = i;
         mSelEndOffset = endOffset;
       }
     }
   }
 
   if (aDoUpdate && eNode) {
-    result = selection->Extend(eNode, eOffset);
-
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv = selection->Extend(eNode, eOffset);
+
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   //**** KDEBUG ****
   // printf("\n * Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   //**** KDEBUG ****
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::GetSelection(nsITextServicesDocument::TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
 
   *aSelStatus = nsITextServicesDocument::eBlockNotFound;
   *aSelOffset = -1;
   *aSelLength = -1;
 
   NS_ENSURE_TRUE(mDOMDocument && mSelCon, NS_ERROR_FAILURE);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone) {
     return NS_OK;
   }
 
   nsCOMPtr<nsISelection> selection;
   bool isCollapsed;
 
-  result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
-
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
+                                      getter_AddRefs(selection));
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
-  result = selection->GetIsCollapsed(&isCollapsed);
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = selection->GetIsCollapsed(&isCollapsed);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // XXX: If we expose this method publicly, we need to
   //      add LOCK_DOC/UNLOCK_DOC calls!
 
   // LOCK_DOC(this);
 
   if (isCollapsed) {
-    result = GetCollapsedSelection(aSelStatus, aSelOffset, aSelLength);
+    rv = GetCollapsedSelection(aSelStatus, aSelOffset, aSelLength);
   } else {
-    result = GetUncollapsedSelection(aSelStatus, aSelOffset, aSelLength);
+    rv = GetUncollapsedSelection(aSelStatus, aSelOffset, aSelLength);
   }
 
   // UNLOCK_DOC(this);
 
-  return result;
+  // XXX The result of GetCollapsedSelection() or GetUncollapsedSelection().
+  return rv;
 }
 
 nsresult
 nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength)
 {
   nsCOMPtr<nsISelection> domSelection;
-  nsresult result =
+  nsresult rv =
     mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
                           getter_AddRefs(domSelection));
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(domSelection, NS_ERROR_FAILURE);
 
   RefPtr<Selection> selection = domSelection->AsSelection();
 
   // The calling function should have done the GetIsCollapsed()
   // check already. Just assume it's collapsed!
   *aSelStatus = nsITextServicesDocument::eBlockOutside;
   *aSelOffset = *aSelLength = -1;
@@ -2375,25 +2364,25 @@ nsTextServicesDocument::GetCollapsedSele
 
   int32_t eStartOffset = eStart->mNodeOffset;
   int32_t eEndOffset   = eEnd->mNodeOffset + eEnd->mLength;
 
   RefPtr<nsRange> range = selection->GetRangeAt(0);
   NS_ENSURE_STATE(range);
 
   nsCOMPtr<nsIDOMNode> domParent;
-  result = range->GetStartContainer(getter_AddRefs(domParent));
-  NS_ENSURE_SUCCESS(result, result);
+  rv = range->GetStartContainer(getter_AddRefs(domParent));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsINode> parent = do_QueryInterface(domParent);
   MOZ_ASSERT(parent);
 
   int32_t offset;
-  result = range->GetStartOffset(&offset);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = range->GetStartOffset(&offset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   int32_t e1s1 = nsContentUtils::ComparePoints(eStart->mNode, eStartOffset,
                                                domParent, offset);
   int32_t e2s1 = nsContentUtils::ComparePoints(eEnd->mNode, eEndOffset,
                                                domParent, offset);
 
   if (e1s1 > 0 || e2s1 < 0) {
     // We're done if the caret is outside the current text block.
@@ -2428,22 +2417,23 @@ nsTextServicesDocument::GetCollapsedSele
 
   // The caret is in our text block, but it's positioned in some
   // non-text node (ex. <b>). Create a range based on the start
   // and end of the text block, then create an iterator based on
   // this range, with its initial position set to the closest
   // child of this non-text node. Then look for the closest text
   // node.
 
-  result = CreateRange(eStart->mNode, eStartOffset, eEnd->mNode, eEndOffset, getter_AddRefs(range));
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateRange(eStart->mNode, eStartOffset, eEnd->mNode, eEndOffset,
+                   getter_AddRefs(range));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIContentIterator> iter;
-  result = CreateContentIterator(range, getter_AddRefs(iter));
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateContentIterator(range, getter_AddRefs(iter));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsIContent* saveNode;
   if (parent->HasChildren()) {
     // XXX: We need to make sure that all of parent's
     //      children are in the text block.
 
     // If the parent has children, position the iterator
     // on the child that is to the left of the offset.
@@ -2459,28 +2449,28 @@ nsTextServicesDocument::GetCollapsedSele
       }
 
       childIndex -= 1;
     }
 
     nsIContent* content = parent->GetChildAt(childIndex);
     NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
-    result = iter->PositionAt(content);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = iter->PositionAt(content);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     saveNode = content;
   } else {
     // The parent has no children, so position the iterator
     // on the parent.
     NS_ENSURE_TRUE(parent->IsContent(), NS_ERROR_FAILURE);
     nsCOMPtr<nsIContent> content = parent->AsContent();
 
-    result = iter->PositionAt(content);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = iter->PositionAt(content);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     saveNode = content;
   }
 
   // Now iterate to the left, towards the beginning of
   // the text block, to find the first text node you
   // come across.
 
@@ -2501,18 +2491,18 @@ nsTextServicesDocument::GetCollapsedSele
     offset = node->TextLength();
   } else {
     // We should never really get here, but I'm paranoid.
 
     // We didn't find a text node above, so iterate to
     // the right, towards the end of the text block, looking
     // for a text node.
 
-    result = iter->PositionAt(saveNode);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = iter->PositionAt(saveNode);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     node = nullptr;
     while (!iter->IsDone()) {
       nsINode* current = iter->GetCurrentNode();
 
       if (current->NodeType() == nsIDOMNode::TEXT_NODE) {
         node = static_cast<nsIContent*>(current);
         break;
@@ -2541,37 +2531,33 @@ nsTextServicesDocument::GetCollapsedSele
       *aSelLength = 0;
 
       // Now move the caret so that it is actually in the text node.
       // We do this to keep things in sync.
       //
       // In most cases, the user shouldn't see any movement in the caret
       // on screen.
 
-      result = SetSelectionInternal(*aSelOffset, *aSelLength, true);
-
-      return result;
+      return SetSelectionInternal(*aSelOffset, *aSelLength, true);
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
 nsresult
 nsTextServicesDocument::GetUncollapsedSelection(nsITextServicesDocument::TSDBlockSelectionStatus *aSelStatus, int32_t *aSelOffset, int32_t *aSelLength)
 {
-  nsresult result;
-
   RefPtr<nsRange> range;
   OffsetEntry *entry;
 
   nsCOMPtr<nsISelection> domSelection;
-  result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                                 getter_AddRefs(domSelection));
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
+                                      getter_AddRefs(domSelection));
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(domSelection, NS_ERROR_FAILURE);
 
   RefPtr<Selection> selection = domSelection->AsSelection();
 
   // It is assumed that the calling function has made sure that the
   // selection is not collapsed, and that the input params to this
   // method are initialized to some defaults.
 
@@ -2594,32 +2580,32 @@ nsTextServicesDocument::GetUncollapsedSe
     eEnd = mOffsetTable[tableCount - 1];
   } else {
     eEnd = eStart;
   }
 
   eStartOffset = eStart->mNodeOffset;
   eEndOffset   = eEnd->mNodeOffset + eEnd->mLength;
 
-  result = selection->GetRangeCount(&rangeCount);
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = selection->GetRangeCount(&rangeCount);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Find the first range in the selection that intersects
   // the current text block.
 
   for (int32_t i = 0; i < rangeCount; i++) {
     range = selection->GetRangeAt(i);
     NS_ENSURE_STATE(range);
 
-    result = GetRangeEndPoints(range,
-                               getter_AddRefs(startParent), &startOffset,
-                               getter_AddRefs(endParent), &endOffset);
-
-    NS_ENSURE_SUCCESS(result, result);
+    rv = GetRangeEndPoints(range,
+                           getter_AddRefs(startParent), &startOffset,
+                           getter_AddRefs(endParent), &endOffset);
+
+    NS_ENSURE_SUCCESS(rv, rv);
 
     e1s2 = nsContentUtils::ComparePoints(eStart->mNode, eStartOffset,
                                          endParent, endOffset);
     e2s1 = nsContentUtils::ComparePoints(eEnd->mNode, eEndOffset,
                                          startParent, startOffset);
 
     // Break out of the loop if the text block intersects the current range.
 
@@ -2684,28 +2670,28 @@ nsTextServicesDocument::GetUncollapsedSe
   if (e2s2 <= 0) {
     p2 = do_QueryInterface(eEnd->mNode);
     o2 = eEndOffset;
   } else {
     p2 = endParent;
     o2 = endOffset;
   }
 
-  result = CreateRange(p1, o1, p2, o2, getter_AddRefs(range));
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateRange(p1, o1, p2, o2, getter_AddRefs(range));
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Now iterate over this range to figure out the selection's
   // block offset and length.
 
   nsCOMPtr<nsIContentIterator> iter;
 
-  result = CreateContentIterator(range, getter_AddRefs(iter));
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Find the first text node in the range.
 
   bool found;
   nsCOMPtr<nsIContent> content;
 
   iter->First();
 
@@ -2742,19 +2728,19 @@ nsTextServicesDocument::GetUncollapsedSe
       content = do_QueryInterface(iter->GetCurrentNode());
       if (IsTextNode(content)) {
         p2 = do_QueryInterface(content);
 
         NS_ENSURE_TRUE(p2, NS_ERROR_FAILURE);
 
         nsString str;
 
-        result = p2->GetNodeValue(str);
-
-        NS_ENSURE_SUCCESS(result, result);
+        rv = p2->GetNodeValue(str);
+
+        NS_ENSURE_SUCCESS(rv, rv);
 
         o2 = str.Length();
         found = true;
 
         break;
       }
 
       iter->Prev();
@@ -2796,17 +2782,17 @@ nsTextServicesDocument::GetUncollapsedSe
         *aSelLength += o2 - entry->mNodeOffset;
         break;
       }
       // The entire entry must be in the range.
       *aSelLength += entry->mLength;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 bool
 nsTextServicesDocument::SelectionIsCollapsed()
 {
   return(mSelStartIndex == mSelEndIndex && mSelStartOffset == mSelEndOffset);
 }
 
@@ -2816,42 +2802,37 @@ nsTextServicesDocument::SelectionIsValid
   return(mSelStartIndex >= 0);
 }
 
 nsresult
 nsTextServicesDocument::GetRangeEndPoints(nsRange* aRange,
                                           nsIDOMNode **aStartParent, int32_t *aStartOffset,
                                           nsIDOMNode **aEndParent, int32_t *aEndOffset)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aRange && aStartParent && aStartOffset && aEndParent && aEndOffset, NS_ERROR_NULL_POINTER);
 
-  result = aRange->GetStartContainer(aStartParent);
-
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = aRange->GetStartContainer(aStartParent);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_TRUE(aStartParent, NS_ERROR_FAILURE);
 
-  result = aRange->GetStartOffset(aStartOffset);
-
-  NS_ENSURE_SUCCESS(result, result);
-
-  result = aRange->GetEndContainer(aEndParent);
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = aRange->GetStartOffset(aStartOffset);
+
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = aRange->GetEndContainer(aEndParent);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_TRUE(aEndParent, NS_ERROR_FAILURE);
 
-  result = aRange->GetEndOffset(aEndOffset);
-
-  return result;
+  return aRange->GetEndOffset(aEndOffset);
 }
 
-
 nsresult
 nsTextServicesDocument::CreateRange(nsIDOMNode *aStartParent, int32_t aStartOffset,
                                     nsIDOMNode *aEndParent, int32_t aEndOffset,
                                     nsRange** aRange)
 {
   return nsRange::CreateRange(aStartParent, aStartOffset, aEndParent,
                               aEndOffset, aRange);
 }
@@ -2944,28 +2925,26 @@ nsTextServicesDocument::FirstTextNodeInC
   // XXX: What should we return if last is null?
 
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::FirstTextNodeInPrevBlock(nsIContentIterator *aIterator)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   // XXX: What if mIterator is not currently on a text node?
 
   // Make sure mIterator is pointing to the first text node in the
   // current block:
 
-  result = FirstTextNodeInCurrentBlock(aIterator);
-
-  NS_ENSURE_SUCCESS(result, NS_ERROR_FAILURE);
+  nsresult rv = FirstTextNodeInCurrentBlock(aIterator);
+
+  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
   // Point mIterator to the first node before the first text node:
 
   aIterator->Prev();
 
   if (aIterator->IsDone()) {
     return NS_ERROR_FAILURE;
   }
@@ -3008,33 +2987,31 @@ nsTextServicesDocument::FirstTextNodeInN
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::GetFirstTextNodeInPrevBlock(nsIContent **aContent)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aContent, NS_ERROR_NULL_POINTER);
 
   *aContent = 0;
 
   // Save the iterator's current content node so we can restore
   // it when we are done:
 
   nsINode* node = mIterator->GetCurrentNode();
 
-  result = FirstTextNodeInPrevBlock(mIterator);
-
-  if (NS_FAILED(result)) {
+  nsresult rv = FirstTextNodeInPrevBlock(mIterator);
+
+  if (NS_FAILED(rv)) {
     // Try to restore the iterator before returning.
     mIterator->PositionAt(node);
-    return result;
+    return rv;
   }
 
   if (!mIterator->IsDone()) {
     nsCOMPtr<nsIContent> current = mIterator->GetCurrentNode()->IsContent()
                                    ? mIterator->GetCurrentNode()->AsContent()
                                    : nullptr;
     current.forget(aContent);
   }
@@ -3042,33 +3019,31 @@ nsTextServicesDocument::GetFirstTextNode
   // Restore the iterator:
 
   return mIterator->PositionAt(node);
 }
 
 nsresult
 nsTextServicesDocument::GetFirstTextNodeInNextBlock(nsIContent **aContent)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aContent, NS_ERROR_NULL_POINTER);
 
   *aContent = 0;
 
   // Save the iterator's current content node so we can restore
   // it when we are done:
 
   nsINode* node = mIterator->GetCurrentNode();
 
-  result = FirstTextNodeInNextBlock(mIterator);
-
-  if (NS_FAILED(result)) {
+  nsresult rv = FirstTextNodeInNextBlock(mIterator);
+
+  if (NS_FAILED(rv)) {
     // Try to restore the iterator before returning.
     mIterator->PositionAt(node);
-    return result;
+    return rv;
   }
 
   if (!mIterator->IsDone()) {
     nsCOMPtr<nsIContent> current = mIterator->GetCurrentNode()->IsContent()
                                    ? mIterator->GetCurrentNode()->AsContent()
                                    : nullptr;
     current.forget(aContent);
   }
@@ -3078,18 +3053,16 @@ nsTextServicesDocument::GetFirstTextNode
 }
 
 nsresult
 nsTextServicesDocument::CreateOffsetTable(nsTArray<OffsetEntry*> *aOffsetTable,
                                           nsIContentIterator *aIterator,
                                           TSDIteratorStatus *aIteratorStatus,
                                           nsRange* aIterRange, nsString* aStr)
 {
-  nsresult result = NS_OK;
-
   nsCOMPtr<nsIContent> first;
   nsCOMPtr<nsIContent> prev;
 
   NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   ClearOffsetTable(aOffsetTable);
 
   if (aStr) {
@@ -3103,30 +3076,31 @@ nsTextServicesDocument::CreateOffsetTabl
   // If we have an aIterRange, retrieve the endpoints so
   // they can be used in the while loop below to trim entries
   // for text nodes that are partially selected by aIterRange.
 
   nsCOMPtr<nsIDOMNode> rngStartNode, rngEndNode;
   int32_t rngStartOffset = 0, rngEndOffset = 0;
 
   if (aIterRange) {
-    result = GetRangeEndPoints(aIterRange,
-                               getter_AddRefs(rngStartNode), &rngStartOffset,
-                               getter_AddRefs(rngEndNode), &rngEndOffset);
-
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv =
+      GetRangeEndPoints(aIterRange,
+                        getter_AddRefs(rngStartNode), &rngStartOffset,
+                        getter_AddRefs(rngEndNode), &rngEndOffset);
+
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // The text service could have added text nodes to the beginning
   // of the current block and called this method again. Make sure
   // we really are at the beginning of the current block:
 
-  result = FirstTextNodeInCurrentBlock(aIterator);
-
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = FirstTextNodeInCurrentBlock(aIterator);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   int32_t offset = 0;
 
   ClearDidSkip(aIterator);
 
   while (!aIterator->IsDone()) {
     nsCOMPtr<nsIContent> content = aIterator->GetCurrentNode()->IsContent()
                                    ? aIterator->GetCurrentNode()->AsContent()
@@ -3135,19 +3109,19 @@ nsTextServicesDocument::CreateOffsetTabl
       if (prev && !HasSameBlockNodeParent(prev, content)) {
         break;
       }
 
       nsCOMPtr<nsIDOMNode> node = do_QueryInterface(content);
       if (node) {
         nsString str;
 
-        result = node->GetNodeValue(str);
-
-        NS_ENSURE_SUCCESS(result, result);
+        rv = node->GetNodeValue(str);
+
+        NS_ENSURE_SUCCESS(rv, rv);
 
         // Add an entry for this text node into the offset table:
 
         OffsetEntry *entry = new OffsetEntry(node, offset, str.Length());
         aOffsetTable->AppendElement(entry);
 
         // If one or both of the endpoints of the iteration range
         // are in the text node for this entry, make sure the entry
@@ -3210,17 +3184,17 @@ nsTextServicesDocument::CreateOffsetTabl
     aIterator->PositionAt(first);
   } else {
     // If we never ran across a text node, the iterator
     // might have been pointing to something invalid to
     // begin with.
     *aIteratorStatus = nsTextServicesDocument::eIsDone;
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::RemoveInvalidOffsetEntries()
 {
   for (size_t i = 0; i < mOffsetTable.Length(); ) {
     OffsetEntry* entry = mOffsetTable[i];
     if (!entry->mIsValid) {
@@ -3339,18 +3313,18 @@ nsTextServicesDocument::FindWordBounds(n
 
   int32_t entryIndex = 0;
   bool hasEntry = false;
 
   // It's assumed that aNode is a text node. The first thing
   // we do is get its index in the offset table so we can
   // calculate the dom point's string offset.
 
-  nsresult result = NodeHasOffsetEntry(aOffsetTable, aNode, &hasEntry, &entryIndex);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = NodeHasOffsetEntry(aOffsetTable, aNode, &hasEntry, &entryIndex);
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(hasEntry, NS_ERROR_FAILURE);
 
   // Next we map aNodeOffset into a string offset.
 
   OffsetEntry *entry = (*aOffsetTable)[entryIndex];
   uint32_t strOffset = entry->mStrOffset + aNodeOffset - entry->mNodeOffset;
 
   // Now we use the word breaker to find the beginning and end