Bug 572618 - Make debugging the editor easier - Part 4: multiline version of part 1; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 17 Jun 2010 16:44:35 -0400
changeset 43808 45dd348924483d9270832a881b0beb481f9797ed
parent 43807 bebdf341352258d8aa5967b9325188e31731e1ad
child 43809 f3195dc021d16d7407e55bd8a0df0cd6d4e6e369
push id13904
push usereakhgari@mozilla.com
push dateFri, 18 Jun 2010 17:14:53 +0000
treeherdermozilla-central@45dd34892448 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs572618
milestone1.9.3a6pre
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 572618 - Make debugging the editor easier - Part 4: multiline version of part 1; r=roc
editor/composer/src/nsComposerCommands.cpp
editor/composer/src/nsComposerDocumentCommands.cpp
editor/composer/src/nsEditingSession.cpp
editor/composer/src/nsEditorSpellCheck.cpp
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditorCommands.cpp
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/html/nsHTMLEditorLog.cpp
editor/libeditor/html/nsHTMLEditorStyle.cpp
editor/libeditor/html/nsHTMLURIRefObject.cpp
editor/libeditor/text/nsPlaintextDataTransfer.cpp
editor/libeditor/text/nsPlaintextEditor.cpp
editor/libeditor/text/nsTextEditRules.cpp
editor/libeditor/text/nsTextEditRulesBidi.cpp
editor/txmgr/src/nsTransactionItem.cpp
editor/txmgr/src/nsTransactionList.cpp
editor/txmgr/src/nsTransactionManager.cpp
editor/txmgr/src/nsTransactionStack.cpp
editor/txtsvc/src/nsTextServicesDocument.cpp
--- a/editor/composer/src/nsComposerCommands.cpp
+++ b/editor/composer/src/nsComposerCommands.cpp
@@ -257,21 +257,19 @@ nsStyleUpdatingCommand::ToggleState(nsIE
   PRBool doTagRemoval;
   if (tagName.EqualsLiteral("href") ||
       tagName.EqualsLiteral("name"))
     doTagRemoval = PR_TRUE;
   else
   {
     // check current selection; set doTagRemoval if formatting should be removed
     rv = GetCurrentState(aEditor, aTagName, params);
-    if (NS_FAILED(rv)) 
-      return rv;
+    NS_ENSURE_SUCCESS(rv, rv);
     rv = params->GetBooleanValue(STATE_ALL, &doTagRemoval);
-    if (NS_FAILED(rv)) 
-      return rv;
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (doTagRemoval)
     rv = RemoveTextProperty(aEditor, tagName.get(), nsnull);
   else
   {
     // Superscript and Subscript styles are mutually exclusive
     nsAutoString removeName; 
@@ -335,18 +333,17 @@ nsListCommand::ToggleState(nsIEditor *aE
   nsresult rv;
   nsCOMPtr<nsICommandParams> params =
       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
   if (NS_FAILED(rv) || !params)
     return rv;
 
   rv = GetCurrentState(aEditor, mTagName, params);
   rv = params->GetBooleanValue(STATE_ALL,&inList);
-  if (NS_FAILED(rv)) 
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString listType; listType.AssignWithConversion(mTagName);
   if (inList)
     rv = editor->RemoveList(listType);    
   else
   {
     rv = editor->MakeOrChangeList(listType, PR_FALSE, EmptyString());
   }
@@ -401,18 +398,17 @@ nsListItemCommand::ToggleState(nsIEditor
   // Need to use mTagName????
   nsresult rv;
   nsCOMPtr<nsICommandParams> params =
       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
   if (NS_FAILED(rv) || !params)
     return rv;
   rv = GetCurrentState(aEditor, mTagName, params);
   rv = params->GetBooleanValue(STATE_ALL,&inList);
-  if (NS_FAILED(rv)) 
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_SUCCESS(rv, rv);
   
   if (inList)
   {
     // To remove a list, first get what kind of list we're in
     PRBool bMixed;
     PRUnichar *tagStr;
     rv = GetListState(aEditor,&bMixed, &tagStr);
@@ -1033,18 +1029,17 @@ nsAlignCommand::GetCurrentState(nsIEdito
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
  
   nsIHTMLEditor::EAlignment firstAlign;
   PRBool outMixed;
   nsresult rv = htmlEditor->GetAlignment(&outMixed, &firstAlign);
   
-  if (NS_FAILED(rv)) 
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   
   nsAutoString outStateString;
   switch (firstAlign)
   {
     default:
     case nsIHTMLEditor::eLeft:
       outStateString.AssignLiteral("left");
       break;
@@ -1117,18 +1112,17 @@ nsAbsolutePositioningCommand::GetCurrent
   if (!isEnabled) {
     aParams->SetBooleanValue(STATE_MIXED,PR_FALSE);
     aParams->SetCStringValue(STATE_ATTRIBUTE, "");
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMElement>  elt;
   nsresult rv = htmlEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt));
-  if (NS_FAILED(rv)) 
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString outStateString;
   if (elt)
     outStateString.AssignLiteral("absolute");
 
   aParams->SetBooleanValue(STATE_MIXED,PR_FALSE);
   aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
   return NS_OK;
@@ -1514,18 +1508,17 @@ nsInsertTagCommand::DoCommand(const char
   {
     nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
 
     nsCOMPtr<nsIDOMElement> domElem;
     nsresult rv;
     rv = editor->CreateElementWithDefaults(NS_ConvertASCIItoUTF16(mTagName),
                                            getter_AddRefs(domElem));
-    if (NS_FAILED(rv))
-      return rv;
+    NS_ENSURE_SUCCESS(rv, rv);
 
     return editor->InsertElementAtSelection(domElem, PR_TRUE);
   }
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
@@ -1561,22 +1554,20 @@ nsInsertTagCommand::DoCommandParams(cons
     attributeType.AssignLiteral("src");
   } else {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   nsCOMPtr<nsIDOMElement> domElem;
   rv = editor->CreateElementWithDefaults(NS_ConvertASCIItoUTF16(mTagName),
                                          getter_AddRefs(domElem));
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rv = domElem->SetAttribute(attributeType, attrib);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // do actual insertion
   if (0 == nsCRT::strcmp(mTagName, "a"))
     return editor->InsertLinkAroundSelection(domElem);
 
   return editor->InsertElementAtSelection(domElem, PR_TRUE);
 }
 
--- a/editor/composer/src/nsComposerDocumentCommands.cpp
+++ b/editor/composer/src/nsComposerDocumentCommands.cpp
@@ -241,32 +241,30 @@ nsSetDocumentStateCommand::DoCommandPara
   {
     NS_ENSURE_ARG_POINTER(aParams);
 
     PRBool modified; 
     nsresult rv = aParams->GetBooleanValue(STATE_ATTRIBUTE, &modified);
 
     // Should we fail if this param wasn't set?
     // I'm not sure we should be that strict
-    if (NS_FAILED(rv))
-      return rv;
+    NS_ENSURE_SUCCESS(rv, rv);
 
     if (modified)
       return editor->IncrementModificationCount(1);
 
     return editor->ResetModificationCount();
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     PRBool isReadOnly; 
     nsresult rvRO = aParams->GetBooleanValue(STATE_ATTRIBUTE, &isReadOnly);
-    if (NS_FAILED(rvRO))
-      return rvRO;
+    NS_ENSURE_SUCCESS(rvRO, rvRO);
 
     PRUint32 flags;
     editor->GetFlags(&flags);
     if (isReadOnly)
       flags |= nsIPlaintextEditor::eEditorReadonlyMask;
     else
       flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
 
@@ -276,61 +274,57 @@ nsSetDocumentStateCommand::DoCommandPara
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     PRBool desireCSS;
     nsresult rvCSS = aParams->GetBooleanValue(STATE_ATTRIBUTE, &desireCSS);
-    if (NS_FAILED(rvCSS))
-      return rvCSS;
+    NS_ENSURE_SUCCESS(rvCSS, rvCSS);
 
     return htmleditor->SetIsCSSEnabled(desireCSS);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     PRBool insertBrOnReturn;
     nsresult rvBR = aParams->GetBooleanValue(STATE_ATTRIBUTE,
                                               &insertBrOnReturn);
-    if (NS_FAILED(rvBR))
-      return rvBR;
+    NS_ENSURE_SUCCESS(rvBR, rvBR);
 
     return htmleditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
 
     PRBool enabled;
     nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
-    if (NS_FAILED(rvOR))
-      return rvOR;
+    NS_ENSURE_SUCCESS(rvOR, rvOR);
 
     return resizer->SetObjectResizingEnabled(enabled);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
     NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
     PRBool enabled;
     nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
-    if (NS_FAILED(rvOR))
-      return rvOR;
+    NS_ENSURE_SUCCESS(rvOR, rvOR);
 
     return editor->SetInlineTableEditingEnabled(enabled);
   }
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
--- a/editor/composer/src/nsEditingSession.cpp
+++ b/editor/composer/src/nsEditingSession.cpp
@@ -1024,18 +1024,17 @@ nsEditingSession::EndDocumentLoad(nsIWeb
       // mMakeWholeDocumentEditable.
       PRBool needsSetup;
       if (mMakeWholeDocumentEditable) {
         needsSetup = PR_TRUE;
       } else {
         // do we already have an editor here?
         nsCOMPtr<nsIEditor> editor;
         rv = editorDocShell->GetEditor(getter_AddRefs(editor));
-        if (NS_FAILED(rv))
-           return rv;
+        NS_ENSURE_SUCCESS(rv, rv);
 
         needsSetup = !editor;
       }
 
       if (needsSetup)
       {
         mCanCreateEditor = PR_FALSE;
         rv = SetupEditorOnWindow(domWindow);
--- a/editor/composer/src/nsEditorSpellCheck.cpp
+++ b/editor/composer/src/nsEditorSpellCheck.cpp
@@ -376,18 +376,17 @@ nsEditorSpellCheck::GetDictionaryList(PR
 
   *aDictionaryList = 0;
   *aCount          = 0;
 
   nsTArray<nsString> dictList;
 
   nsresult rv = mSpellChecker->GetDictionaryList(&dictList);
 
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   PRUnichar **tmpPtr = 0;
 
   if (dictList.Length() < 1)
   {
     // If there are no dictionaries, return an array containing
     // one element and a count of one.
 
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -984,18 +984,17 @@ NS_IMETHODIMP nsEditor::SelectAll()
 
 NS_IMETHODIMP nsEditor::BeginningOfDocument()
 {
   if (!mDocWeak || !mPresShellWeak) { return NS_ERROR_NOT_INITIALIZED; }
 
   // get the selection
   nsCOMPtr<nsISelection> selection;
   nsresult result = GetSelection(getter_AddRefs(selection));
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
   NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
     
   // get the root element 
   nsIDOMElement *rootElement = GetRoot(); 
   NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); 
   
   // find first editable thingy
   nsCOMPtr<nsIDOMNode> firstNode;
@@ -1951,18 +1950,17 @@ GetEditorContentWindow(nsIDOMElement *aR
 nsresult
 nsEditor::GetWidget(nsIWidget **aWidget)
 {
   NS_ENSURE_TRUE(aWidget, NS_ERROR_NULL_POINTER);
   *aWidget = nsnull;
 
   nsCOMPtr<nsIWidget> widget;
   nsresult res = GetEditorContentWindow(GetRoot(), getter_AddRefs(widget));
-  if (NS_FAILED(res))
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(widget, NS_ERROR_NOT_AVAILABLE);
 
   NS_ADDREF(*aWidget = widget);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1983,23 +1981,21 @@ nsEditor::ForceCompositionEnd()
   // Linux.  Currently, nsGtkIMModule can know the timing of the cursor move,
   // so, the latter meaning should be gone and we should remove this #if.
   if(! mInIMEMode)
     return NS_OK;
 #endif
 
   nsCOMPtr<nsIWidget> widget;
   nsresult res = GetWidget(getter_AddRefs(widget));
-  if (NS_FAILED(res))
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
 
   if (widget) {
     res = widget->ResetInputState();
-    if (NS_FAILED(res)) 
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::GetPreferredIMEState(PRUint32 *aState)
 {
@@ -2096,18 +2092,17 @@ nsEditor::CloneAttribute(const nsAString
   NS_ENSURE_TRUE(destElement && sourceElement, NS_ERROR_NO_INTERFACE);
 
   nsAutoString attrValue;
   PRBool isAttrSet;
   nsresult rv = GetAttributeValue(sourceElement,
                                   aAttribute,
                                   attrValue,
                                   &isAttrSet);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   if (isAttrSet)
     rv = SetAttribute(destElement, aAttribute, attrValue);
   else
     rv = RemoveAttribute(destElement, aAttribute);
 
   return rv;
 }
 
@@ -4195,18 +4190,17 @@ nsEditor::DeleteSelectionImpl(nsIEditor:
 NS_IMETHODIMP
 nsEditor::DeleteSelectionAndCreateNode(const nsAString& aTag,
                                            nsIDOMNode ** aNewNode)
 {
   nsCOMPtr<nsIDOMNode> parentSelectedNode;
   PRInt32 offsetOfNewNode;
   nsresult result = DeleteSelectionAndPrepareToCreateNode(parentSelectedNode,
                                                           offsetOfNewNode);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   nsCOMPtr<nsIDOMNode> newNode;
   result = CreateNode(aTag, parentSelectedNode, offsetOfNewNode,
                       getter_AddRefs(newNode));
   // XXX: ERROR_HANDLING  check result, and make sure aNewNode is set correctly in success/failure cases
   *aNewNode = newNode;
   NS_IF_ADDREF(*aNewNode);
 
@@ -4356,18 +4350,17 @@ nsEditor::DeleteSelectionAndPrepareToCre
 
 NS_IMETHODIMP 
 nsEditor::DoAfterDoTransaction(nsITransaction *aTxn)
 {
   nsresult rv = NS_OK;
   
   PRBool  isTransientTransaction;
   rv = aTxn->GetIsTransient(&isTransientTransaction);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   
   if (!isTransientTransaction)
   {
     // we need to deal here with the case where the user saved after some
     // edits, then undid one or more times. Then, the undo count is -ve,
     // but we can't let a do take it back to zero. So we flip it up to
     // a +ve number.
     PRInt32 modCount;
@@ -4621,23 +4614,21 @@ nsEditor::CreateTxnForDeleteInsertionPoi
                                            PRInt32              *aOffset,
                                            PRInt32              *aLength)
 {
   NS_ASSERTION(aAction == eNext || aAction == ePrevious, "invalid action");
 
   // get the node and offset of the insertion point
   nsCOMPtr<nsIDOMNode> node;
   nsresult result = aRange->GetStartContainer(getter_AddRefs(node));
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   PRInt32 offset;
   result = aRange->GetStartOffset(&offset);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   // determine if the insertion point is at the beginning, middle, or end of the node
   nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(node);
 
   PRUint32 count=0;
 
   if (nodeAsText)
     nodeAsText->GetLength(&count);
@@ -4809,18 +4800,17 @@ nsEditor::CreateTxnForDeleteInsertionPoi
 
 nsresult 
 nsEditor::CreateRange(nsIDOMNode *aStartParent, PRInt32 aStartOffset,
                       nsIDOMNode *aEndParent, PRInt32 aEndOffset,
                       nsIDOMRange **aRange)
 {
   nsresult result;
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SetStart(aStartParent, aStartOffset);
 
   if (NS_SUCCEEDED(result))
     result = (*aRange)->SetEnd(aEndParent, aEndOffset);
 
@@ -5071,18 +5061,17 @@ nsEditor::GetRoot()
 NS_IMETHODIMP
 nsEditor::SwitchTextDirection()
 {
   // Get the current root direction from its frame
   nsIDOMElement *rootElement = GetRoot();
 
   nsresult rv;
   nsCOMPtr<nsIContent> content = do_QueryInterface(rootElement, &rv);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsIFrame *frame = content->GetPrimaryFrame();
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); 
 
   // Apply the opposite direction
   if (frame->GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL)
     rv = rootElement->SetAttribute(NS_LITERAL_STRING("dir"), NS_LITERAL_STRING("ltr"));
   else
--- a/editor/libeditor/base/nsEditorCommands.cpp
+++ b/editor/libeditor/base/nsEditorCommands.cpp
@@ -674,18 +674,17 @@ NS_IMETHODIMP
 nsSelectionMoveCommands::DoCommand(const char *aCommandName,
                                    nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsISelectionController> selCont;
   nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont)); 
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(selCont, NS_ERROR_FAILURE);
 
   // complete scroll commands
   if (!nsCRT::strcmp(aCommandName,"cmd_scrollTop"))
     return selCont->CompleteScroll(PR_FALSE);
   else if (!nsCRT::strcmp(aCommandName,"cmd_scrollBottom"))
     return selCont->CompleteScroll(PR_TRUE);
 
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -1082,18 +1082,17 @@ NS_IMETHODIMP nsHTMLEditor::PrepareTrans
   return NS_OK;
 }
 
 NS_IMETHODIMP nsHTMLEditor::PrepareHTMLTransferable(nsITransferable **aTransferable, 
                                                     PRBool aHavePrivFlavor)
 {
   // Create generic Transferable for getting the data
   nsresult rv = CallCreateInstance("@mozilla.org/widget/transferable;1", aTransferable);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the nsITransferable interface for getting the data from the clipboard
   if (aTransferable)
   {
     // Create the desired DataFlavor for the type of data
     // we want to get out of the transferable
     // This should only happen in html editors, not plaintext
     if (!IsPlaintextEditor())
@@ -1342,18 +1341,17 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTr
     else if (0 == nsCRT::strcmp(bestFlavor, kFileMime))
     {
       nsCOMPtr<nsIFile> fileObj(do_QueryInterface(genericDataObj));
       if (fileObj && len > 0)
       {
         
         nsCOMPtr<nsIURI> uri;
         rv = NS_NewFileURI(getter_AddRefs(uri), fileObj);
-        if (NS_FAILED(rv))
-          return rv;
+        NS_ENSURE_SUCCESS(rv, rv);
         
         nsCOMPtr<nsIURL> fileURL(do_QueryInterface(uri));
         if (fileURL)
         {
           PRBool insertAsImage = PR_FALSE;
           nsCAutoString fileextension;
           rv = fileURL->GetFileExtension(fileextension);
           if (NS_SUCCEEDED(rv) && !fileextension.IsEmpty())
@@ -1631,18 +1629,17 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDr
       // We never have to delete if selection is already collapsed
       PRBool cursorIsInSelection = PR_FALSE;
 
       // Check if mouse is in the selection
       if (!isCollapsed)
       {
         PRInt32 rangeCount;
         rv = selection->GetRangeCount(&rangeCount);
-        if (NS_FAILED(rv)) 
-          return rv;
+        NS_ENSURE_SUCCESS(rv, rv);
 
         for (PRInt32 j = 0; j < rangeCount; j++)
         {
           nsCOMPtr<nsIDOMRange> range;
 
           rv = selection->GetRangeAt(j, getter_AddRefs(range));
           if (NS_FAILED(rv) || !range) 
             continue;//don't bail yet, iterate through them all
@@ -1836,18 +1833,17 @@ PRBool nsHTMLEditor::HavePrivateHTMLFlav
 NS_IMETHODIMP nsHTMLEditor::Paste(PRInt32 aSelectionType)
 {
   if (!FireClipboardEvent(NS_PASTE))
     return NS_OK;
 
   // Get Clipboard Service
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   
   // find out if we have our internal html flavor on the clipboard.  We don't want to mess
   // around with cfhtml if we do.
   PRBool bHavePrivateHTMLFlavor = HavePrivateHTMLFlavor(clipboard);
 
   // Get the nsITransferable interface for getting the data from the clipboard
   nsCOMPtr<nsITransferable> trans;
   rv = PrepareHTMLTransferable(getter_AddRefs(trans), bHavePrivateHTMLFlavor);
@@ -1938,18 +1934,17 @@ NS_IMETHODIMP nsHTMLEditor::PasteTransfe
 //
 NS_IMETHODIMP nsHTMLEditor::PasteNoFormatting(PRInt32 aSelectionType)
 {
   ForceCompositionEnd();
 
   // Get Clipboard Service
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
     
   // Get the nsITransferable interface for getting the data from the clipboard.
   // use nsPlaintextEditor::PrepareTransferable() to force unicode plaintext data.
   nsCOMPtr<nsITransferable> trans;
   rv = nsPlaintextEditor::PrepareTransferable(getter_AddRefs(trans));
   if (NS_SUCCEEDED(rv) && trans)
   {
     // Get the Data from the clipboard  
@@ -2566,18 +2561,17 @@ nsresult FindTargetNode(nsIDOMNode *aSta
         return NS_FOUND_TARGET;
       }
     }
 
     // Note: Don't use NS_ENSURE_* here since we return a failure result to
     // inicate that we found the magical cookie and we don't want to spam the
     // console.
     rv = FindTargetNode(child, aResult);
-    if (NS_FAILED(rv))
-      return rv;
+    NS_ENSURE_SUCCESS(rv, rv);
 
     rv = child->GetNextSibling(getter_AddRefs(tmp));
     NS_ENSURE_SUCCESS(rv, rv);
 
     child = tmp;
   } while (child);
 
   return NS_OK;
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -557,25 +557,23 @@ nsHTMLEditRules::AfterEditInner(PRInt32 
       NS_ENSURE_SUCCESS(res, res);
     }    
   }
 
   res = mHTMLEditor->HandleInlineSpellCheck(action, selection, 
                                             mRangeItem.startNode, mRangeItem.startOffset,
                                             rangeStartParent, rangeStartOffset,
                                             rangeEndParent, rangeEndOffset);
-  if (NS_FAILED(res)) 
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
 
   // detect empty doc
   res = CreateBogusNodeIfNeeded(selection);
   
   // adjust selection HINT if needed
-  if (NS_FAILED(res)) 
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
   
   if (!mDidExplicitlySetInterline)
   {
     res = CheckInterlinePosition(selection);
   }
   
   return res;
 }
@@ -2741,18 +2739,17 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsI
       nsCOMPtr<nsIContent> parent(do_QueryInterface(rightList));
       NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
 
       nsIContent *child = parent->GetChildAt(theOffset);
       while (child)
       {
         childToMove = do_QueryInterface(child);
         res = mHTMLEditor->MoveNode(childToMove, leftList, -1);
-        if (NS_FAILED(res))
-          return res;
+        NS_ENSURE_SUCCESS(res, res);
 
         child = parent->GetChildAt(rightOffset);
       }
     }
     else
     {
       res = MoveBlock(*aLeftBlock, *aRightBlock, leftOffset, rightOffset);
     }
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -530,18 +530,17 @@ nsHTMLEditor::InitRules()
 NS_IMETHODIMP
 nsHTMLEditor::BeginningOfDocument()
 {
   if (!mDocWeak || !mPresShellWeak) { return NS_ERROR_NOT_INITIALIZED; }
 
   // get the selection
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
-  if (NS_FAILED(res))
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
     
   // get the root element 
   nsIDOMElement *rootElement = GetRoot(); 
   NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); 
   
   // find first editable thingy
   PRBool done = PR_FALSE;
@@ -920,18 +919,17 @@ nsHTMLEditor::IsBlockNode(nsIDOMNode *aN
 // Non-static version for the nsIEditor interface and JavaScript
 NS_IMETHODIMP 
 nsHTMLEditor::SetDocumentTitle(const nsAString &aTitle)
 {
   nsRefPtr<SetDocTitleTxn> txn = new SetDocTitleTxn();
   NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
 
   nsresult result = txn->Init(this, &aTitle);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   //Don't let Rules System change the selection
   nsAutoTxnsConserveSelection dontChangeSelection(this);
   return nsEditor::DoTransaction(txn);  
 }
 
 /* ------------ Block methods moved from nsEditor -------------- */
 ///////////////////////////////////////////////////////////////////////////
@@ -1126,18 +1124,17 @@ nsHTMLEditor::NextNodeInBlock(nsIDOMNode
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIDOMNode> blockParent;
   
   NS_ENSURE_TRUE(aNode, nullNode);
 
   nsresult rv;
   nsCOMPtr<nsIContentIterator> iter =
        do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &rv);
-  if (NS_FAILED(rv))
-    return nullNode;
+  NS_ENSURE_SUCCESS(rv, nullNode);
 
   // much gnashing of teeth as we twit back and forth between content and domnode types
   content = do_QueryInterface(aNode);
   PRBool isBlock;
   if (NS_SUCCEEDED(NodeIsBlockStatic(aNode, &isBlock)) && isBlock)
   {
     blockParent = aNode;
   }
@@ -1743,18 +1740,17 @@ nsHTMLEditor::ReplaceHeadContentsWithHTM
 
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // Get the first range in the selection, for context:
   nsCOMPtr<nsIDOMRange> range;
   res = selection->GetRangeAt(0, getter_AddRefs(range));
-  if (NS_FAILED(res))
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range));
   NS_ENSURE_TRUE(nsrange, NS_ERROR_NO_INTERFACE);
   nsCOMPtr<nsIDOMDocumentFragment> docfrag;
   res = nsrange->CreateContextualFragment(inputString,
                                           getter_AddRefs(docfrag));
 
   //XXXX BUG 50965: This is not returning the text between <title> ... </title>
@@ -1877,27 +1873,24 @@ nsHTMLEditor::RebuildDocumentFromSource(
     // XXX Without recourse to some parser/content sink/docshell hackery
     // we don't really know where the head ends and the body begins
     if (foundclosehead) // assume body starts after the head ends
       res = LoadHTML(body + Substring(endclosehead, endtotal));
     else if (foundhead) // assume there is no body
       res = LoadHTML(body);
     else // assume there is no head, the entire source is body
       res = LoadHTML(body + aSourceString);
-    if (NS_FAILED(res))
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
 
     nsCOMPtr<nsIDOMElement> divElement;
     res = CreateElementWithDefaults(NS_LITERAL_STRING("div"), getter_AddRefs(divElement));
-    if (NS_FAILED(res))
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
 
     res = CloneAttributes(bodyElement, divElement);
-    if (NS_FAILED(res))
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
 
     return BeginningOfDocument();
   }
 
   res = LoadHTML(Substring(beginbody, endtotal));
   NS_ENSURE_SUCCESS(res, res);
 
   // Now we must copy attributes user might have edited on the <body> tag
@@ -2046,18 +2039,17 @@ nsHTMLEditor::InsertElementAtSelection(n
 
   if (!handled)
   {
     if (aDeleteSelection)
     {
       nsCOMPtr<nsIDOMNode> tempNode;
       PRInt32 tempOffset;
       nsresult result = DeleteSelectionAndPrepareToCreateNode(tempNode,tempOffset);
-      if (NS_FAILED(result))
-        return result;
+      NS_ENSURE_SUCCESS(result, result);
     }
 
     // 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
@@ -2164,18 +2156,17 @@ nsHTMLEditor::InsertNodeAtPoint(nsIDOMNo
     NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     topChild = parent;
     parent = tmp;
   }
   if (parent != topChild)
   {
     // we need to split some levels above the original selection parent
     res = SplitNodeDeep(topChild, *ioParent, *ioOffset, &offsetOfInsert, aNoEmptyNodes);
-    if (NS_FAILED(res))
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
     *ioParent = parent;
     *ioOffset = offsetOfInsert;
   }
   // Now we can insert the new node
   res = InsertNode(aNode, parent, offsetOfInsert);
   return res;
 }
 
@@ -3643,18 +3634,17 @@ nsHTMLEditor::EnableStyleSheet(const nsA
   return sheet->SetDisabled(!aEnable);
 }
 
 PRBool
 nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL)
 {
   nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
-  if (NS_FAILED(rv))
-    return PR_FALSE;
+  NS_ENSURE_SUCCESS(rv, PR_FALSE);
 
   // Enable sheet if already loaded.
   if (sheet)
   {
     // Ensure the style sheet is owned by our document.
     nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
     sheet->SetOwningDocument(doc);
 
--- a/editor/libeditor/html/nsHTMLEditorLog.cpp
+++ b/editor/libeditor/html/nsHTMLEditorLog.cpp
@@ -828,18 +828,17 @@ nsHTMLEditorLog::StartLogging(nsIFile *a
   nsresult result = NS_ERROR_FAILURE;
 
   NS_ENSURE_TRUE(aLogFile, NS_ERROR_NULL_POINTER);
 
   if (mFileStream)
   {
     result = StopLogging();
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
   result = NS_NewLocalFileOutputStream(getter_AddRefs(mFileStream), aLogFile);
   NS_ENSURE_SUCCESS(result, result);
 
   if (mTxnMgr)
   {
     mEditorTxnLog = new nsEditorTxnLog(this);
@@ -888,25 +887,23 @@ nsHTMLEditorLog::Write(const char *aBuff
   PRInt32 len = strlen(aBuffer);
 
   if (mFileStream)
   {
     PRUint32 retval;
 
     result = mFileStream->Write(aBuffer, len, &retval);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
 #ifdef VERY_SLOW
 
     result = mFileStream->Flush();
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
 #endif // VERY_SLOW
   }
   else
     fwrite(aBuffer, 1, len, stdout);
 
   return NS_OK;
 }
@@ -946,87 +943,78 @@ nsHTMLEditorLog::PrintUnicode(const nsAS
   {
     if (nsCRT::IsAsciiAlpha(*beginIter) || nsCRT::IsAsciiDigit(*beginIter) || *beginIter == ' ')
       PR_snprintf(buf, sizeof(buf), "%c", *beginIter);
     else
       PR_snprintf(buf, sizeof(buf), "\\u%.4x", *beginIter);
 
     nsresult result = Write(buf);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
     ++beginIter;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsHTMLEditorLog::PrintSelection()
 {
   nsCOMPtr<nsISelection> selection;
   nsresult result;
   PRInt32 rangeCount;
 
   result = GetSelection(getter_AddRefs(selection));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = selection->GetRangeCount(&rangeCount);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   Write("selRanges = [ ");
 
   PRInt32 i, j;
   nsCOMPtr<nsIDOMRange> range;
   nsCOMPtr<nsIDOMNode> startNode;
   nsCOMPtr<nsIDOMNode> endNode;
   PRInt32 startOffset, endOffset;
 
   for (i = 0; i < rangeCount; i++)
   {
     result = selection->GetRangeAt(i, getter_AddRefs(range));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
     
     result = range->GetStartContainer(getter_AddRefs(startNode));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     NS_ENSURE_TRUE(startNode, NS_ERROR_NULL_POINTER);
 
     result = range->GetStartOffset(&startOffset);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     result = range->GetEndContainer(getter_AddRefs(endNode));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     NS_ENSURE_TRUE(endNode, NS_ERROR_NULL_POINTER);
 
     result = range->GetEndOffset(&endOffset);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     PRInt32 *offsetArray = 0;
     PRInt32 arrayLength = 0;
 
     result = GetNodeTreeOffsets(startNode, &offsetArray, &arrayLength);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     if (i != 0)
       Write(",\n              ");
 
     Write("[ [[");
 
     for (j = 0; j < arrayLength; j++)
     {
@@ -1042,18 +1030,17 @@ nsHTMLEditorLog::PrintSelection()
     if (startNode != endNode)
     {
       delete []offsetArray;
       offsetArray = 0;
       arrayLength = 0;
 
       result = GetNodeTreeOffsets(endNode, &offsetArray, &arrayLength);
 
-      if (NS_FAILED(result))
-        return result;
+      NS_ENSURE_SUCCESS(result, result);
     }
 
     Write("[[");
 
     for (j = 0; j < arrayLength; j++)
     {
       if (j != 0)
         Write(", ");
@@ -1081,53 +1068,48 @@ nsHTMLEditorLog::PrintElementNode(nsIDOM
   nsAutoString tag, name, value;
   nsCOMPtr<nsIDOMElement> ele = do_QueryInterface(aNode);
   nsCOMPtr<nsIDOMNamedNodeMap> map;
 
   NS_ENSURE_TRUE(ele, NS_ERROR_NULL_POINTER);
 
   result = ele->GetTagName(tag);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   Write("n");
   WriteInt(aDepth);
   Write(" = GetCurrentEditor().editorDocument.createElement(\"");
   PrintUnicode(tag);
   Write("\");\n");
 
   result = aNode->GetAttributes(getter_AddRefs(map));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(map, NS_ERROR_NULL_POINTER);
 
   PRUint32 i, len;
   nsCOMPtr<nsIDOMNode> attr;
 
   result = map->GetLength(&len);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   for (i = 0; i < len; i++)
   {
     result = map->Item(i, getter_AddRefs(attr));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     NS_ENSURE_TRUE(attr, NS_ERROR_NULL_POINTER);
 
     result = PrintAttributeNode(attr, aDepth);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
   result = PrintNodeChildren(aNode, aDepth);
 
   return result;
 }
 
 nsresult
@@ -1137,29 +1119,27 @@ nsHTMLEditorLog::PrintAttributeNode(nsID
   nsCOMPtr<nsIDOMAttr> attr = do_QueryInterface(aNode);
 
   NS_ENSURE_TRUE(attr, NS_ERROR_NULL_POINTER);
 
   nsAutoString str;
 
   result = attr->GetName(str);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   Write("a");
   WriteInt(aDepth);
   Write(" = GetCurrentEditor().editorDocument.createAttribute(\"");
   PrintUnicode(str);
   Write("\");\n");
 
   result = attr->GetValue(str);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   Write("a");
   WriteInt(aDepth);
   Write(".value = \"");
   PrintUnicode(str);
   Write("\";\n");
   
   Write("n");
@@ -1177,44 +1157,40 @@ nsHTMLEditorLog::PrintNodeChildren(nsIDO
   nsresult result;
 
   NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNodeList> list;
 
   result = aNode->GetChildNodes(getter_AddRefs(list));
   
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   if (!list)
   {
     // Must not have any children!
     return NS_OK;
   }
 
   PRUint32 i, len;
   nsCOMPtr<nsIDOMNode> node;
 
   result = list->GetLength(&len);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   for (i = 0; i < len; i++)
   {
     result = list->Item(i, getter_AddRefs(node));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     result = PrintNode(node, aDepth + 1);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     Write("n");
     WriteInt(aDepth);
     Write(".appendChild(n");
     WriteInt(aDepth+1);
     Write(");\n");
   }
 
@@ -1229,18 +1205,17 @@ nsHTMLEditorLog::PrintTextNode(nsIDOMNod
   nsCOMPtr<nsIDOMCharacterData> cd = do_QueryInterface(aNode);
 
   NS_ENSURE_TRUE(cd, NS_ERROR_NULL_POINTER);
 
   nsAutoString str;
 
   result = cd->GetData(str);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   Write("n");
   WriteInt(aDepth);
   Write(" = GetCurrentEditor().editorDocument.createTextNode(\"");
   PrintUnicode(str);
   Write("\");\n");
 
   return NS_OK;
@@ -1300,18 +1275,17 @@ nsHTMLEditorLog::GetNodeTreeOffsets(nsID
   PRInt32 i = 0;
 
   // Count the number of parent nodes above aNode.
 
   while (parent)
   {
     result = parent->GetParentNode(&parent);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     if (parent)
       ++i;
   }
 
   // Allocate an array big enough to hold all the offsets.
 
   *aResult = new PRInt32[i];
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -686,24 +686,21 @@ nsresult nsHTMLEditor::RemoveStyleInside
           (hasStyleAttr || hasClassAtrr)) {
         // aNode carries inline styles or a class attribute so we can't
         // just remove the element... We need to create above the element
         // a span that will carry those styles or class, then we can delete
         // the node.
         nsCOMPtr<nsIDOMNode> spanNode;
         res = InsertContainerAbove(aNode, address_of(spanNode),
                                    NS_LITERAL_STRING("span"));
-        if (NS_FAILED(res))
-          return res;
+        NS_ENSURE_SUCCESS(res, res);
         res = CloneAttribute(styleAttr, spanNode, aNode);
-        if (NS_FAILED(res))
-          return res;
+        NS_ENSURE_SUCCESS(res, res);
         res = CloneAttribute(classAttr, spanNode, aNode);
-        if (NS_FAILED(res))
-          return res;
+        NS_ENSURE_SUCCESS(res, res);
         if (hasStyleAttr)
         {
           // we need to remove the styles property corresponding to
           // aProperty (bug 215406)
           nsAutoString propertyValue;
           mHTMLCSSUtils->RemoveCSSEquivalentToHTMLStyle(spanNode,
                                                         aProperty,
                                                         aAttribute,
--- a/editor/libeditor/html/nsHTMLURIRefObject.cpp
+++ b/editor/libeditor/html/nsHTMLURIRefObject.cpp
@@ -129,18 +129,17 @@ nsHTMLURIRefObject::Reset()
 
 NS_IMETHODIMP
 nsHTMLURIRefObject::GetNextURI(nsAString & aURI)
 {
   NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
 
   nsAutoString tagName;
   nsresult rv = mNode->GetNodeName(tagName);
-  if (NS_FAILED(rv))
-  return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Loop over attribute list:
   if (!mAttributes)
   {
     nsCOMPtr<nsIDOMElement> element (do_QueryInterface(mNode));
     NS_ENSURE_TRUE(element, NS_ERROR_INVALID_ARG);
 
     mCurAttrIndex = 0;
--- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp
@@ -68,18 +68,17 @@
 #include "nsISelectionPrivate.h"
 #include "nsFrameSelection.h"
 #include "nsEventDispatcher.h"
 
 NS_IMETHODIMP nsPlaintextEditor::PrepareTransferable(nsITransferable **transferable)
 {
   // Create generic Transferable for getting the data
   nsresult rv = CallCreateInstance("@mozilla.org/widget/transferable;1", transferable);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the nsITransferable interface for getting the data from the clipboard
   if (transferable) {
     (*transferable)->AddDataFlavor(kUnicodeMime);
     (*transferable)->AddDataFlavor(kMozTextInternal);
   };
   return NS_OK;
 }
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -295,18 +295,17 @@ nsPlaintextEditor::SetDocumentCharacterS
         result = domdoc->GetElementsByTagName(NS_LITERAL_STRING("head"),getter_AddRefs(headList)); 
         if (NS_SUCCEEDED(result) && headList) { 
           nsCOMPtr<nsIDOMNode>headNode; 
           headList->Item(0, getter_AddRefs(headNode)); 
           if (headNode) { 
             nsCOMPtr<nsIDOMNode>resultNode; 
             // Create a new meta charset tag 
             result = CreateNode(NS_LITERAL_STRING("meta"), headNode, 0, getter_AddRefs(resultNode)); 
-            if (NS_FAILED(result)) 
-              return NS_ERROR_FAILURE; 
+            NS_ENSURE_SUCCESS(result, NS_ERROR_FAILURE); 
 
             // Set attributes to the created element 
             if (resultNode && !characterSet.IsEmpty()) { 
               metaElement = do_QueryInterface(resultNode); 
               if (metaElement) { 
                 // not undoable, undo should undo CreateNode 
                 result = metaElement->SetAttribute(NS_LITERAL_STRING("http-equiv"), NS_LITERAL_STRING("Content-Type")); 
                 if (NS_SUCCEEDED(result)) { 
@@ -1353,18 +1352,17 @@ nsPlaintextEditor::OutputToString(const 
 
   nsCAutoString charsetStr;
   rv = GetDocumentCharacterSet(charsetStr);
   if(NS_FAILED(rv) || charsetStr.IsEmpty())
     charsetStr.AssignLiteral("ISO-8859-1");
 
   nsCOMPtr<nsIDocumentEncoder> encoder;
   rv = GetAndInitDocEncoder(aFormatType, aFlags, charsetStr, getter_AddRefs(encoder));
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
   return encoder->EncodeToString(aOutputString);
 }
 
 NS_IMETHODIMP
 nsPlaintextEditor::OutputToStream(nsIOutputStream* aOutputStream,
                              const nsAString& aFormatType,
                              const nsACString& aCharset,
                              PRUint32 aFlags)
@@ -1383,18 +1381,17 @@ nsPlaintextEditor::OutputToStream(nsIOut
     if (docEmpty)
        return NS_OK;    // output nothing
   }
 
   nsCOMPtr<nsIDocumentEncoder> encoder;
   rv = GetAndInitDocEncoder(aFormatType, aFlags, aCharset,
                             getter_AddRefs(encoder));
 
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return encoder->EncodeToStream(aOutputStream);
 }
 
 
 #ifdef XP_MAC
 #pragma mark -
 #pragma mark  nsIEditorMailSupport overrides 
@@ -1468,18 +1465,17 @@ nsPlaintextEditor::InsertAsQuotation(con
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   // We have the text.  Cite it appropriately:
   nsCOMPtr<nsICiter> citer = new nsInternetCiter();
 
   // Let the citer quote it for us:
   nsString quotedStuff;
   nsresult rv = citer->GetCiteString(aQuotedText, quotedStuff);
-  if (NS_FAILED(rv))
-    return rv;
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // It's best to put a blank line after the quoted text so that mails
   // written without thinking won't be so ugly.
   if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != PRUnichar('\n')))
     quotedStuff.Append(PRUnichar('\n'));
 
   // get selection
   nsCOMPtr<nsISelection> selection;
@@ -1546,18 +1542,17 @@ nsPlaintextEditor::SharedOutputString(PR
   return OutputToString(NS_LITERAL_STRING("text/plain"), aFlags, aResult);
 }
 
 NS_IMETHODIMP
 nsPlaintextEditor::Rewrap(PRBool aRespectNewlines)
 {
   PRInt32 wrapCol;
   nsresult rv = GetWrapWidth(&wrapCol);
-  if (NS_FAILED(rv))
-    return NS_OK;
+  NS_ENSURE_SUCCESS(rv, NS_OK);
 
   // Rewrap makes no sense if there's no wrap column; default to 72.
   if (wrapCol <= 0)
     wrapCol = 72;
 
 #ifdef DEBUG_akkana
   printf("nsPlaintextEditor::Rewrap to %ld columns\n", (long)wrapCol);
 #endif
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -220,18 +220,17 @@ nsTextEditRules::BeforeEdit(PRInt32 acti
   if (mLockRulesSniffing) return NS_OK;
   
   nsAutoLockRulesSniffing lockIt(this);
   mDidExplicitlySetInterline = PR_FALSE;
   
   // get the selection and cache the position before editing
   nsCOMPtr<nsISelection> selection;
   nsresult res = mEditor->GetSelection(getter_AddRefs(selection));
-  if (NS_FAILED(res)) 
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
 
   selection->GetAnchorNode(getter_AddRefs(mCachedSelectionNode));
   selection->GetAnchorOffset(&mCachedSelectionOffset);
 
   if (!mActionNesting)
   {
     // let rules remember the top level action
     mTheAction = action;
@@ -254,28 +253,25 @@ nsTextEditRules::AfterEdit(PRInt32 actio
   {
     nsCOMPtr<nsISelection>selection;
     res = mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
   
     res = mEditor->HandleInlineSpellCheck(action, selection,
                                           mCachedSelectionNode, mCachedSelectionOffset,
                                           nsnull, 0, nsnull, 0);
-    if (NS_FAILED(res)) 
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
 
     // detect empty doc
     res = CreateBogusNodeIfNeeded(selection);
-    if (NS_FAILED(res)) 
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
     
     // insure trailing br node
     res = CreateTrailingBRIfNeeded();
-    if (NS_FAILED(res)) 
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
     
     /* After inserting text the cursor Bidi level must be set to the level of the inserted text.
      * This is difficult, because we cannot know what the level is until after the Bidi algorithm
      * is applied to the whole paragraph.
      *
      * So we set the cursor Bidi level to UNDEFINED here, and the caret code will set it correctly later
      */
     if (action == nsEditor::kOpInsertText
--- a/editor/libeditor/text/nsTextEditRulesBidi.cpp
+++ b/editor/libeditor/text/nsTextEditRulesBidi.cpp
@@ -53,18 +53,17 @@ nsTextEditRules::CheckBidiLevelForDeleti
                                            nsIEditor::EDirection aAction,
                                            PRBool               *aCancel)
 {
   NS_ENSURE_ARG_POINTER(aCancel);
   *aCancel = PR_FALSE;
 
   nsCOMPtr<nsIPresShell> shell;
   nsresult res = mEditor->GetPresShell(getter_AddRefs(shell));
-  if (NS_FAILED(res))
-    return res;
+  NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(shell, NS_ERROR_NULL_POINTER);
   
   nsPresContext *context = shell->GetPresContext();
   NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
   
   if (!context->BidiEnabled())
     return NS_OK;
   
--- a/editor/txmgr/src/nsTransactionItem.cpp
+++ b/editor/txmgr/src/nsTransactionItem.cpp
@@ -146,69 +146,64 @@ nsTransactionItem::GetNumberOfChildren(P
 
   *aNumChildren = 0;
 
   PRInt32 ui = 0;
   PRInt32 ri = 0;
 
   result = GetNumberOfUndoItems(&ui);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = GetNumberOfRedoItems(&ri);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   *aNumChildren = ui + ri;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetChild(PRInt32 aIndex, nsTransactionItem **aChild)
 {
   NS_ENSURE_TRUE(aChild, NS_ERROR_NULL_POINTER);
 
   *aChild = 0;
 
   PRInt32 numItems = 0;
   nsresult result = GetNumberOfChildren(&numItems);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   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);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   if (numItems > 0 && aIndex < numItems) {
     NS_ENSURE_TRUE(mUndoStack, NS_ERROR_FAILURE);
 
     return mUndoStack->GetItem(aIndex, aChild);
   }
 
   // Adjust the index for the redo stack:
 
   aIndex -=  numItems;
 
   result = GetNumberOfRedoItems(&numItems);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(mRedoStack && numItems != 0 && aIndex < numItems, NS_ERROR_FAILURE);
 
   return mRedoStack->GetItem(numItems - aIndex - 1, aChild);
 }
 
 nsresult
 nsTransactionItem::DoTransaction()
@@ -251,18 +246,17 @@ nsTransactionItem::UndoChildren(nsTransa
     if (!mRedoStack && mUndoStack) {
       mRedoStack = new nsTransactionRedoStack();
       NS_ENSURE_TRUE(mRedoStack, NS_ERROR_OUT_OF_MEMORY);
     }
 
     /* Undo all of the transaction items children! */
     result = mUndoStack->GetSize(&sz);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     while (sz-- > 0) {
       result = mUndoStack->Peek(getter_AddRefs(item));
 
       if (NS_FAILED(result) || !item) {
         return result;
       }
 
@@ -315,18 +309,17 @@ nsresult
 nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
 {
   nsresult result;
 
   nsCOMPtr<nsITransaction> kungfuDeathGrip(mTransaction);
   if (mTransaction) {
     result = mTransaction->RedoTransaction();
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
   result = RedoChildren(aTxMgr);
 
   if (NS_FAILED(result)) {
     RecoverFromRedoError(aTxMgr);
     return result;
   }
@@ -341,18 +334,17 @@ nsTransactionItem::RedoChildren(nsTransa
   nsresult result = NS_OK;
   PRInt32 sz = 0;
 
   NS_ENSURE_TRUE(mRedoStack, NS_OK);
 
   /* Redo all of the transaction items children! */
   result = mRedoStack->GetSize(&sz);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
 
   while (sz-- > 0) {
     result = mRedoStack->Peek(getter_AddRefs(item));
 
     if (NS_FAILED(result) || !item) {
       return result;
     }
--- a/editor/txmgr/src/nsTransactionList.cpp
+++ b/editor/txmgr/src/nsTransactionList.cpp
@@ -100,18 +100,17 @@ NS_IMETHODIMP nsTransactionList::ItemIsB
 
   nsresult result = NS_ERROR_FAILURE;
 
   if (mTxnStack)
     result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
   else if (mTxnItem)
     result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetIsBatch(aIsBatch);
 }
 
 /* nsITransaction getItem (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::GetItem(PRInt32 aIndex, nsITransaction **aItem)
@@ -128,18 +127,17 @@ NS_IMETHODIMP nsTransactionList::GetItem
 
   nsresult result = NS_ERROR_FAILURE;
 
   if (mTxnStack)
     result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
   else if (mTxnItem)
     result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetTransaction(aItem);
 }
 
 /* long getNumChildrenForItem (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(PRInt32 aIndex, PRInt32 *aNumChildren)
@@ -156,18 +154,17 @@ NS_IMETHODIMP nsTransactionList::GetNumC
 
   nsresult result = NS_ERROR_FAILURE;
 
   if (mTxnStack)
     result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
   else if (mTxnItem)
     result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetNumberOfChildren(aNumChildren);
 }
 
 /* nsITransactionList getChildListForItem (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::GetChildListForItem(PRInt32 aIndex, nsITransactionList **aTxnList)
@@ -184,18 +181,17 @@ NS_IMETHODIMP nsTransactionList::GetChil
 
   nsresult result = NS_ERROR_FAILURE;
 
   if (mTxnStack)
     result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
   else if (mTxnItem)
     result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   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);
--- a/editor/txmgr/src/nsTransactionManager.cpp
+++ b/editor/txmgr/src/nsTransactionManager.cpp
@@ -1026,18 +1026,17 @@ nsTransactionManager::EndTransaction()
     result = top->GetTransaction(getter_AddRefs(topTransaction));
 
     if (topTransaction) {
 
       PRBool doInterrupt = PR_FALSE;
 
       result = WillMergeNotify(topTransaction, tint, &doInterrupt);
 
-      if (NS_FAILED(result))
-        return result;
+      NS_ENSURE_SUCCESS(result, result);
 
       if (!doInterrupt) {
         result = topTransaction->Merge(tint, &didMerge);
 
         nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);
 
         if (NS_SUCCEEDED(result))
           result = result2;
--- a/editor/txmgr/src/nsTransactionStack.cpp
+++ b/editor/txmgr/src/nsTransactionStack.cpp
@@ -126,24 +126,22 @@ nsTransactionStack::Clear(void)
 {
   nsRefPtr<nsTransactionItem> tx;
   nsresult result    = NS_OK;
 
   /* Pop all transactions off the stack and release them. */
 
   result = Pop(getter_AddRefs(tx));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   while (tx) {
     result = Pop(getter_AddRefs(tx));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionStack::GetSize(PRInt32 *aStackSize)
 {
@@ -179,21 +177,19 @@ nsTransactionRedoStack::Clear(void)
   nsresult result       = NS_OK;
 
   /* When clearing a Redo stack, we have to clear from the
    * bottom of the stack towards the top!
    */
 
   result = PopBottom(getter_AddRefs(tx));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   while (tx) {
     result = PopBottom(getter_AddRefs(tx));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
   return NS_OK;
 }
 
--- a/editor/txtsvc/src/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/src/nsTextServicesDocument.cpp
@@ -1537,18 +1537,17 @@ nsTextServicesDocument::InsertText(const
 
   if (!collapsedSelection)
   {
     // Collapse to the start of the current selection
     // for the insert!
 
     result = SetSelection(mSelStartOffset, 0);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
 
   LOCK_DOC(this);
 
   result = editor->BeginTransaction();
 
   if (NS_FAILED(result))
@@ -1793,18 +1792,17 @@ nsTextServicesDocument::DidInsertNode(ns
                                       nsresult    aResult)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult)
 {
-  if (NS_FAILED(aResult))
-    return NS_OK;
+  NS_ENSURE_SUCCESS(aResult, NS_OK);
 
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   //**** KDEBUG ****
   // printf("** DeleteNode: 0x%.8x\n", aChild);
   // fflush(stdout);
   //**** KDEBUG ****
 
@@ -1884,74 +1882,69 @@ nsTextServicesDocument::DidSplitNode(nsI
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::DidJoinNodes(nsIDOMNode  *aLeftNode,
                                      nsIDOMNode  *aRightNode,
                                      nsIDOMNode  *aParent,
                                      nsresult     aResult)
 {
-  if (NS_FAILED(aResult))
-    return NS_OK;
+  NS_ENSURE_SUCCESS(aResult, NS_OK);
 
   PRInt32 i;
   PRUint16 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!
 
   result = aLeftNode->GetNodeType(&type);
 
-  if (NS_FAILED(result))
-    return PR_FALSE;
+  NS_ENSURE_SUCCESS(result, PR_FALSE);
 
   if (nsIDOMNode::TEXT_NODE != type)
   {
     NS_ERROR("JoinNode called with a non-text left node!");
     return NS_ERROR_FAILURE;
   }
 
   result = aRightNode->GetNodeType(&type);
 
-  if (NS_FAILED(result))
-    return PR_FALSE;
+  NS_ENSURE_SUCCESS(result, PR_FALSE);
 
   if (nsIDOMNode::TEXT_NODE != type)
   {
     NS_ERROR("JoinNode called with a non-text right node!");
     return NS_ERROR_FAILURE;
   }
 
   // Note: The editor merges the contents of the left node into the
   //       contents of the right.
 
   PRInt32 leftIndex, rightIndex;
   PRBool leftHasEntry, rightHasEntry;
 
   result = NodeHasOffsetEntry(&mOffsetTable, aLeftNode, &leftHasEntry, &leftIndex);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   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);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   if (!rightHasEntry)
   {
     // It's okay if the node isn't in the offset table, the
     // editor could be cleaning house.
     return NS_OK;
   }
 
@@ -2077,33 +2070,31 @@ nsTextServicesDocument::GetDocumentConte
   if (htmlDoc)
   {
     // For HTML documents, the content root node is the body.
 
     nsCOMPtr<nsIDOMHTMLElement> bodyElement;
 
     result = htmlDoc->GetBody(getter_AddRefs(bodyElement));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     NS_ENSURE_TRUE(bodyElement, NS_ERROR_FAILURE);
 
     result = bodyElement->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aNode);
   }
   else
   {
     // For non-HTML documents, the content root node will be the document element.
 
     nsCOMPtr<nsIDOMElement> docElement;
 
     result = mDOMDocument->GetDocumentElement(getter_AddRefs(docElement));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     NS_ENSURE_TRUE(docElement, NS_ERROR_FAILURE);
 
     result = docElement->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aNode);
   }
 
   return result;
 }
@@ -2116,24 +2107,22 @@ nsTextServicesDocument::CreateDocumentCo
   NS_ENSURE_TRUE(aRange, NS_ERROR_NULL_POINTER);
 
   *aRange = 0;
 
   nsCOMPtr<nsIDOMNode>node;
 
   result = GetDocumentContentRootNode(getter_AddRefs(node));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SelectNodeContents(node);
 
   if (NS_FAILED(result))
   {
     NS_RELEASE((*aRange));
@@ -2157,18 +2146,17 @@ nsTextServicesDocument::CreateDocumentCo
 
   if (aOffset < 0)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMNode> bodyNode; 
 
   result = GetDocumentContentRootNode(getter_AddRefs(bodyNode));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(bodyNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> startNode;
   nsCOMPtr<nsIDOMNode> endNode;
   PRInt32 startOffset, endOffset;
 
   if (aToStart)
@@ -2191,33 +2179,30 @@ nsTextServicesDocument::CreateDocumentCo
 
     startNode   = do_QueryInterface(aParent);
     startOffset = aOffset;
     endNode     = bodyNode;
     endOffset   = 0;
 
     result = bodyNode->GetChildNodes(getter_AddRefs(nodeList));
 
-    if (NS_FAILED(result))
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_SUCCESS(result, NS_ERROR_FAILURE);
 
     if (nodeList)
     {
       result = nodeList->GetLength(&nodeListLength);
 
-      if (NS_FAILED(result))
-        return NS_ERROR_FAILURE;
+      NS_ENSURE_SUCCESS(result, NS_ERROR_FAILURE);
 
       endOffset = (PRInt32)nodeListLength;
     }
   }
 
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SetStart(startNode, startOffset);
 
   if (NS_SUCCEEDED(result))
     result = (*aRange)->SetEnd(endNode, endOffset);
 
@@ -2236,18 +2221,17 @@ nsTextServicesDocument::CreateDocumentCo
   nsresult result;
 
   NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMRange> range;
 
   result = CreateDocumentContentRange(getter_AddRefs(range));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = CreateContentIterator(range, aIterator);
 
   return result;
 }
 
 nsresult
 nsTextServicesDocument::AdjustContentIterator()
@@ -2457,18 +2441,17 @@ PRBool
 nsTextServicesDocument::IsTextNode(nsIDOMNode *aNode)
 {
   NS_ENSURE_TRUE(aNode, PR_FALSE);
 
   PRUint16 type;
 
   nsresult result = aNode->GetNodeType(&type);
 
-  if (NS_FAILED(result))
-    return PR_FALSE;
+  NS_ENSURE_SUCCESS(result, PR_FALSE);
 
   return nsIDOMNode::TEXT_NODE == type;
 }
 
 nsresult
 nsTextServicesDocument::SetSelectionInternal(PRInt32 aOffset, PRInt32 aLength, PRBool aDoUpdate)
 {
   nsresult result = NS_OK;
@@ -2546,23 +2529,21 @@ nsTextServicesDocument::SetSelectionInte
   //      use it.
 
   nsCOMPtr<nsISelection> selection;
 
   if (aDoUpdate)
   {
     result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     result = selection->Collapse(sNode, sOffset);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
    }
 
   if (aLength <= 0)
   {
     // We have a collapsed selection. (Caret)
 
     mSelEndIndex  = mSelStartIndex;
     mSelEndOffset = mSelStartOffset;
@@ -2608,18 +2589,17 @@ nsTextServicesDocument::SetSelectionInte
       }
     }
   }
 
   if (aDoUpdate && eNode)
   {
     result = selection->Extend(eNode, eOffset);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
 
   //**** KDEBUG ****
   // printf("\n * Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   //**** KDEBUG ****
 
   return result;
 }
@@ -2640,25 +2620,23 @@ nsTextServicesDocument::GetSelection(nsI
   if (mIteratorStatus == nsTextServicesDocument::eIsDone)
     return NS_OK;
 
   nsCOMPtr<nsISelection> selection;
   PRBool isCollapsed;
 
   result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   result = selection->GetIsCollapsed(&isCollapsed);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   // 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);
@@ -2673,18 +2651,17 @@ nsTextServicesDocument::GetSelection(nsI
 nsresult
 nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockSelectionStatus *aSelStatus, PRInt32 *aSelOffset, PRInt32 *aSelLength)
 {
   nsresult result;
   nsCOMPtr<nsISelection> selection;
 
   result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   // The calling function should have done the GetIsCollapsed()
   // check already. Just assume it's collapsed!
 
   nsCOMPtr<nsIDOMRange> range;
   OffsetEntry *entry;
@@ -2714,38 +2691,33 @@ nsTextServicesDocument::GetCollapsedSele
   else
     eEnd = eStart;
 
   eStartOffset = eStart->mNodeOffset;
   eEndOffset   = eEnd->mNodeOffset + eEnd->mLength;
 
   result = selection->GetRangeAt(0, getter_AddRefs(range));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = range->GetStartContainer(getter_AddRefs(parent));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = range->GetStartOffset(&offset);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = ComparePoints(eStart->mNode, eStartOffset, parent, offset, &e1s1);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = ComparePoints(eEnd->mNode, eEndOffset, parent, offset, &e2s1);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   if (e1s1 > 0 || e2s1 < 0)
   {
     // We're done if the caret is outside the
     // current text block.
 
     return NS_OK;
   }
@@ -2788,90 +2760,82 @@ nsTextServicesDocument::GetCollapsedSele
 
   nsCOMPtr<nsIDOMNode> node, saveNode;
   nsCOMPtr<nsIDOMNodeList> children;
   nsCOMPtr<nsIContentIterator> iter;
   PRBool hasChildren;
 
   result = CreateRange(eStart->mNode, eStartOffset, eEnd->mNode, eEndOffset, getter_AddRefs(range));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = CreateContentIterator(range, getter_AddRefs(iter));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = parent->HasChildNodes(&hasChildren);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   if (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.
 
     PRUint32 childIndex = (PRUint32)offset;
 
     result = parent->GetChildNodes(getter_AddRefs(children));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     NS_ENSURE_TRUE(children, NS_ERROR_FAILURE);
 
     if (childIndex > 0)
     {
       PRUint32 numChildren;
 
       result = children->GetLength(&numChildren);
 
-      if (NS_FAILED(result))
-        return result;
+      NS_ENSURE_SUCCESS(result, result);
 
       NS_ASSERTION(childIndex <= numChildren, "Invalid selection offset!");
 
       if (childIndex > numChildren)
         childIndex = numChildren;
 
       childIndex -= 1;
     }
 
     result = children->Item(childIndex, getter_AddRefs(saveNode));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     nsCOMPtr<nsIContent> content(do_QueryInterface(saveNode));
 
     NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
     result = iter->PositionAt(content);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
   }
   else
   {
     // The parent has no children, so position the iterator
     // on the parent.
 
     nsCOMPtr<nsIContent> content(do_QueryInterface(parent));
 
     NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
     result = iter->PositionAt(content);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     saveNode = parent;
   }
 
   // Now iterate to the left, towards the beginning of
   // the text block, to find the first text node you
   // come across.
 
@@ -2896,36 +2860,34 @@ nsTextServicesDocument::GetCollapsedSele
   if (node)
   {
     // We found a node, now set the offset to the end
     // of the text node.
 
     nsAutoString str;
     result = node->GetNodeValue(str);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     offset = str.Length();
   }
   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.
 
     {
       nsCOMPtr<nsIContent> content(do_QueryInterface(saveNode));
 
       result = iter->PositionAt(content);
 
-      if (NS_FAILED(result))
-        return result;
+      NS_ENSURE_SUCCESS(result, result);
     }
 
     while (!iter->IsDone())
     {
       nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
 
       if (IsTextNode(content))
       {
@@ -2983,18 +2945,17 @@ nsTextServicesDocument::GetUncollapsedSe
   nsresult result;
 
   nsCOMPtr<nsISelection> selection;
   nsCOMPtr<nsIDOMRange> range;
   OffsetEntry *entry;
 
   result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   // 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.
 
   nsCOMPtr<nsIDOMNode> startParent, endParent;
@@ -3017,45 +2978,40 @@ nsTextServicesDocument::GetUncollapsedSe
   else
     eEnd = eStart;
 
   eStartOffset = eStart->mNodeOffset;
   eEndOffset   = eEnd->mNodeOffset + eEnd->mLength;
 
   result = selection->GetRangeCount(&rangeCount);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   // Find the first range in the selection that intersects
   // the current text block.
 
   for (i = 0; i < rangeCount; i++)
   {
     result = selection->GetRangeAt(i, getter_AddRefs(range));
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     result = GetRangeEndPoints(range,
                                getter_AddRefs(startParent), &startOffset,
                                getter_AddRefs(endParent), &endOffset);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     result = ComparePoints(eStart->mNode, eStartOffset, endParent, endOffset, &e1s2);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     result = ComparePoints(eEnd->mNode, eEndOffset, startParent, startOffset, &e2s1);
 
-    if (NS_FAILED(result))
-      return result;
+    NS_ENSURE_SUCCESS(result, result);
 
     // Break out of the loop if the text block intersects the current range.
 
     if (e1s2 <= 0 && e2s1 >= 0)
       break;
   }
 
   // We're done if we didn't find an intersecting range.
@@ -3066,23 +3022,21 @@ nsTextServicesDocument::GetUncollapsedSe
     *aSelOffset = *aSelLength = -1;
     return NS_OK;
   }
 
   // Now that we have an intersecting range, find out more info:
 
   result = ComparePoints(eStart->mNode, eStartOffset, startParent, startOffset, &e1s1);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = ComparePoints(eEnd->mNode, eEndOffset, endParent, endOffset, &e2s2);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   if (rangeCount > 1)
   {
     // There are multiple selection ranges, we only deal
     // with the first one that intersects the current,
     // text block, so mark this a as a partial.
 
     *aSelStatus = nsITextServicesDocument::eBlockPartial;
@@ -3139,28 +3093,26 @@ nsTextServicesDocument::GetUncollapsedSe
   else
   {
     p2 = endParent;
     o2 = endOffset;
   }
 
   result = CreateRange(p1, o1, p2, o2, getter_AddRefs(range));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   // Now iterate over this range to figure out the selection's
   // block offset and length.
 
   nsCOMPtr<nsIContentIterator> iter;
 
   result = CreateContentIterator(range, getter_AddRefs(iter));
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   // Find the first text node in the range.
   
   PRBool found;
   nsCOMPtr<nsIContent> content;
 
   iter->First();
 
@@ -3207,18 +3159,17 @@ nsTextServicesDocument::GetUncollapsedSe
         p2 = do_QueryInterface(content);
 
         NS_ENSURE_TRUE(p2, NS_ERROR_FAILURE);
 
         nsString str;
 
         result = p2->GetNodeValue(str);
 
-        if (NS_FAILED(result))
-          return result;
+        NS_ENSURE_SUCCESS(result, result);
 
         o2 = str.Length();
         found = PR_TRUE;
 
         break;
       }
 
       iter->Prev();
@@ -3322,30 +3273,27 @@ nsTextServicesDocument::GetRangeEndPoint
                                           nsIDOMNode **aEndParent, PRInt32 *aEndOffset)
 {
   nsresult result;
 
   NS_ENSURE_TRUE(aRange && aStartParent && aStartOffset && aEndParent && aEndOffset, NS_ERROR_NULL_POINTER);
 
   result = aRange->GetStartContainer(aStartParent);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(aStartParent, NS_ERROR_FAILURE);
 
   result = aRange->GetStartOffset(aStartOffset);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   result = aRange->GetEndContainer(aEndParent);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(aEndParent, NS_ERROR_FAILURE);
 
   result = aRange->GetEndOffset(aEndOffset);
 
   return result;
 }
 
@@ -3353,18 +3301,17 @@ nsTextServicesDocument::GetRangeEndPoint
 nsresult
 nsTextServicesDocument::CreateRange(nsIDOMNode *aStartParent, PRInt32 aStartOffset,
                                     nsIDOMNode *aEndParent, PRInt32 aEndOffset,
                                     nsIDOMRange **aRange)
 {
   nsresult result;
 
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SetStart(aStartParent, aStartOffset);
 
   if (NS_SUCCEEDED(result))
     result = (*aRange)->SetEnd(aEndParent, aEndOffset);
 
@@ -3483,18 +3430,17 @@ nsTextServicesDocument::FirstTextNodeInP
 
   // 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);
 
-  if (NS_FAILED(result))
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_SUCCESS(result, NS_ERROR_FAILURE);
 
   // Point mIterator to the first node before the first text node:
 
   aIterator->Prev();
 
   if (aIterator->IsDone())
     return NS_ERROR_FAILURE;
 
@@ -3642,18 +3588,17 @@ nsTextServicesDocument::CreateOffsetTabl
   }
 
   // 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);
 
-  if (NS_FAILED(result))
-    return result;
+  NS_ENSURE_SUCCESS(result, result);
 
   PRInt32 offset = 0;
 
   ClearDidSkip(aIterator);
 
   while (!aIterator->IsDone())
   {
     nsCOMPtr<nsIContent> content = do_QueryInterface(aIterator->GetCurrentNode());
@@ -3665,18 +3610,17 @@ nsTextServicesDocument::CreateOffsetTabl
         nsCOMPtr<nsIDOMNode> node = do_QueryInterface(content);
 
         if (node)
         {
           nsString str;
 
           result = node->GetNodeValue(str);
 
-          if (NS_FAILED(result))
-            return result;
+          NS_ENSURE_SUCCESS(result, result);
 
           // Add an entry for this text node into the offset table:
 
           OffsetEntry *entry = new OffsetEntry(node, offset, str.Length());
 
           NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
 
           aOffsetTable->AppendElement(entry);