Bug 572618 - Make debugging the editor easier - Part 3: multiline version of part 2; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 17 Jun 2010 16:40:48 -0400
changeset 43807 bebdf341352258d8aa5967b9325188e31731e1ad
parent 43806 223b2b67edbd8da65198571534d75dd0c5431031
child 43808 45dd348924483d9270832a881b0beb481f9797ed
push idunknown
push userunknown
push dateunknown
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 3: multiline version of part 2; r=roc
editor/composer/src/nsComposerCommands.cpp
editor/composer/src/nsComposerCommandsUpdater.cpp
editor/composer/src/nsComposerDocumentCommands.cpp
editor/composer/src/nsEditingSession.cpp
editor/composer/src/nsEditorSpellCheck.cpp
editor/libeditor/base/CreateElementTxn.cpp
editor/libeditor/base/DeleteRangeTxn.cpp
editor/libeditor/base/EditAggregateTxn.cpp
editor/libeditor/base/IMETextTxn.cpp
editor/libeditor/base/InsertElementTxn.cpp
editor/libeditor/base/SplitElementTxn.cpp
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditorCommands.cpp
editor/libeditor/base/nsEditorEventListener.cpp
editor/libeditor/base/nsEditorUtils.cpp
editor/libeditor/base/nsStyleSheetTxns.cpp
editor/libeditor/html/TextEditorTest.cpp
editor/libeditor/html/nsEditorTxnLog.cpp
editor/libeditor/html/nsHTMLAbsPosition.cpp
editor/libeditor/html/nsHTMLAnonymousUtils.cpp
editor/libeditor/html/nsHTMLCSSUtils.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/nsHTMLObjectResizer.cpp
editor/libeditor/html/nsHTMLURIRefObject.cpp
editor/libeditor/html/nsTableEditor.cpp
editor/libeditor/html/nsWSRunObject.cpp
editor/libeditor/text/nsPlaintextDataTransfer.cpp
editor/libeditor/text/nsPlaintextEditor.cpp
editor/libeditor/text/nsTextEditRules.cpp
editor/libeditor/text/nsTextEditRulesBidi.cpp
editor/libeditor/text/nsTextEditUtils.cpp
editor/txmgr/src/nsTransactionItem.cpp
editor/txmgr/src/nsTransactionList.cpp
editor/txmgr/src/nsTransactionManager.cpp
editor/txmgr/src/nsTransactionStack.cpp
editor/txtsvc/src/nsFilteredContentIterator.cpp
editor/txtsvc/src/nsTextServicesDocument.cpp
--- a/editor/composer/src/nsComposerCommands.cpp
+++ b/editor/composer/src/nsComposerCommands.cpp
@@ -151,34 +151,31 @@ nsPasteNoFormattingCommand::IsCommandEna
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
   *outCmdEnabled = PR_FALSE;
 
   // This command is only implemented by nsIHTMLEditor, since
   //  pasting in a plaintext editor automatically only supplies 
   //  "unformatted" text
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon);
-  if (!htmlEditor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
 
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(htmlEditor);
-  if (!editor)
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
   return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled);
 }
 
 
 NS_IMETHODIMP
 nsPasteNoFormattingCommand::DoCommand(const char *aCommandName,
                                       nsISupports *refCon)
 {
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon);
-  if (!htmlEditor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
 
   return htmlEditor->PasteNoFormatting(nsIClipboard::kGlobalClipboard);
 }
 
 NS_IMETHODIMP
 nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName,
                                             nsICommandParams *aParams, 
                                             nsISupports *refCon)
@@ -240,18 +237,17 @@ nsStyleUpdatingCommand::GetCurrentState(
   aParams->SetBooleanValue(STATE_END, allOfSelectionHasProp);//not completely accurate
   return NS_OK;
 }
 
 nsresult
 nsStyleUpdatingCommand::ToggleState(nsIEditor *aEditor, const char* aTagName)
 {
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor)
-    return NS_ERROR_NO_INTERFACE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NO_INTERFACE);
 
   //create some params now...
   nsresult rv;
   nsCOMPtr<nsICommandParams> params =
       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
   if (NS_FAILED(rv) || !params)
     return rv;
 
@@ -328,18 +324,17 @@ nsListCommand::GetCurrentState(nsIEditor
   if (tagStr) NS_Free(tagStr);
   return NS_OK;
 }
 
 nsresult
 nsListCommand::ToggleState(nsIEditor *aEditor, const char* aTagName)
 {
   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(aEditor);
-  if (!editor)
-    return NS_NOINTERFACE;
+  NS_ENSURE_TRUE(editor, NS_NOINTERFACE);
   PRBool inList;
   // Need to use mTagName????
   nsresult rv;
   nsCOMPtr<nsICommandParams> params =
       do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
   if (NS_FAILED(rv) || !params)
     return rv;
 
@@ -370,18 +365,17 @@ nsListItemCommand::nsListItemCommand(con
 
 nsresult
 nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName,
                                    nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need editor here");
   // 39584
   nsCOMPtr<nsIHTMLEditor>  htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor)
-    return NS_NOINTERFACE;
+  NS_ENSURE_TRUE(htmlEditor, NS_NOINTERFACE);
 
   PRBool bMixed, bLI, bDT, bDD;
   nsresult rv = htmlEditor->GetListItemState(&bMixed, &bLI, &bDT, &bDD);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool inList = PR_FALSE;
   if (!bMixed)
   {
@@ -1192,18 +1186,17 @@ nsDecreaseZIndexCommand::IsCommandEnable
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDecreaseZIndexCommand::DoCommand(const char *aCommandName,
                                    nsISupports *refCon)
 {
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
-  if (!htmlEditor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
 
   return htmlEditor->RelativeChangeZIndex(-1);
 }
 
 NS_IMETHODIMP
 nsDecreaseZIndexCommand::DoCommandParams(const char *aCommandName,
                                          nsICommandParams *aParams, 
                                          nsISupports *refCon)
@@ -1247,18 +1240,17 @@ nsIncreaseZIndexCommand::IsCommandEnable
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsIncreaseZIndexCommand::DoCommand(const char *aCommandName,
                                    nsISupports *refCon)
 {
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
-  if (!htmlEditor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED);
 
   return htmlEditor->RelativeChangeZIndex(1);
 }
 
 NS_IMETHODIMP
 nsIncreaseZIndexCommand::DoCommandParams(const char *aCommandName,
                                          nsICommandParams *aParams, 
                                          nsISupports *refCon)
@@ -1455,18 +1447,17 @@ NS_IMETHODIMP
 nsInsertHTMLCommand::DoCommandParams(const char *aCommandName,
                                      nsICommandParams *aParams,
                                      nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(aParams);
   NS_ENSURE_ARG_POINTER(refCon);
 
   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
-  if (!editor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
 
   // Get HTML source string to insert from command params
   nsAutoString html;
   nsresult rv = aParams->GetStringValue(STATE_DATA, html);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!html.IsEmpty())
     return editor->InsertHTML(html);
@@ -1517,18 +1508,17 @@ nsInsertTagCommand::IsCommandEnabled(con
 
 // corresponding STATE_ATTRIBUTE is: src (img) and href (a) 
 NS_IMETHODIMP
 nsInsertTagCommand::DoCommand(const char *aCmdName, nsISupports *refCon)
 {
   if (0 == nsCRT::strcmp(mTagName, "hr"))
   {
     nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
-    if (!editor)
-      return NS_ERROR_NOT_IMPLEMENTED;
+    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;
 
@@ -1547,18 +1537,17 @@ nsInsertTagCommand::DoCommandParams(cons
 
   // inserting an hr shouldn't have an parameters, just call DoCommand for that
   if (0 == nsCRT::strcmp(mTagName, "hr"))
     return DoCommand(aCommandName, refCon);
 
   NS_ENSURE_ARG_POINTER(aParams);
 
   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon);
-  if (!editor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
 
   // do we have an href to use for creating link?
   nsXPIDLCString s;
   nsresult rv = aParams->GetCStringValue(STATE_ATTRIBUTE, getter_Copies(s));
   NS_ENSURE_SUCCESS(rv, rv);
   nsAutoString attrib; attrib.AssignWithConversion(s);
 
   if (attrib.IsEmpty())
@@ -1610,18 +1599,17 @@ nsInsertTagCommand::GetCommandStateParam
 
 /****************************/
 //HELPER METHODS
 /****************************/
 
 nsresult
 GetListState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval)
 {
-  if (!aMixed || !_retval || !aEditor) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && _retval && aEditor, NS_ERROR_NULL_POINTER);
   *_retval = nsnull;
   *aMixed = PR_FALSE;
 
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
   nsresult err = NS_ERROR_NO_INTERFACE;
   if (htmlEditor)
   {
     PRBool bOL, bUL, bDL;
@@ -1643,39 +1631,35 @@ GetListState(nsIEditor *aEditor, PRBool 
   }
   return err;
 }
 
 nsresult
 RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, 
                   const nsString &aAttr)
 {
-  if (!aEditor) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aEditor, NS_ERROR_NOT_INITIALIZED);
 
   /// XXX Hack alert! Look in nsIEditProperty.h for this
   nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(aProp);
-  if (! styleAtom) 
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE( styleAtom, NS_ERROR_OUT_OF_MEMORY);
 
   return aEditor->RemoveInlineProperty(styleAtom, aAttr);
 }
 
 
 // the name of the attribute here should be the contents of the appropriate
 // tag, e.g. 'b' for bold, 'i' for italics.
 nsresult
 RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, 
                    const PRUnichar *attr)
 {
-  if (!aEditor) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aEditor, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(aEditor);
-  if (!editor) 
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
   // OK, I'm really hacking now. This is just so that 
   //     we can accept 'all' as input.  
   nsAutoString  allStr(prop);
   
   ToLowerCase(allStr);
   PRBool    doingAll = (allStr.EqualsLiteral("all"));
   nsresult  err = NS_OK;
 
@@ -1697,23 +1681,21 @@ RemoveTextProperty(nsIEditor *aEditor, c
 // tag, e.g. 'b' for bold, 'i' for italics.
 nsresult
 SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, 
                 const PRUnichar *attr, const PRUnichar *value)
 {
   //static initialization 
   static const PRUnichar sEmptyStr = PRUnichar('\0');
   
-  if (!aEditor) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aEditor, NS_ERROR_NOT_INITIALIZED);
 
   /// XXX Hack alert! Look in nsIEditProperty.h for this
   nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(prop);
-  if (! styleAtom) 
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE( styleAtom, NS_ERROR_OUT_OF_MEMORY);
 
   nsresult  err = NS_NOINTERFACE;
 
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor,&err);
   if (htmlEditor)
     err = htmlEditor->SetInlineProperty(styleAtom,
                                 nsDependentString(attr?attr:&sEmptyStr),
                                 nsDependentString(value?value:&sEmptyStr));
--- a/editor/composer/src/nsComposerCommandsUpdater.cpp
+++ b/editor/composer/src/nsComposerCommandsUpdater.cpp
@@ -364,18 +364,17 @@ nsComposerCommandsUpdater::UpdateOneComm
 
   return NS_OK;  
 }
 
 PRBool
 nsComposerCommandsUpdater::SelectionIsCollapsed()
 {
   nsCOMPtr<nsIDOMWindow> domWindow = do_QueryReferent(mDOMWindow);
-  if (!domWindow)
-    return PR_TRUE;
+  NS_ENSURE_TRUE(domWindow, PR_TRUE);
 
   nsCOMPtr<nsISelection> domSelection;
   if (NS_SUCCEEDED(domWindow->GetSelection(getter_AddRefs(domSelection))) && domSelection)
   {
     PRBool selectionCollapsed = PR_FALSE;
     domSelection->GetIsCollapsed(&selectionCollapsed);
     return selectionCollapsed;
   }
@@ -413,14 +412,13 @@ nsComposerCommandsUpdater::Notify(nsITim
 #pragma mark -
 #endif
 
 
 nsresult
 NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult)
 {
   nsComposerCommandsUpdater* newThang = new nsComposerCommandsUpdater;
-  if (!newThang)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(newThang, NS_ERROR_OUT_OF_MEMORY);
 
   return newThang->QueryInterface(NS_GET_IID(nsISelectionListener),
                                   (void **)aInstancePtrResult);
 }
--- a/editor/composer/src/nsComposerDocumentCommands.cpp
+++ b/editor/composer/src/nsComposerDocumentCommands.cpp
@@ -230,18 +230,17 @@ nsSetDocumentStateCommand::DoCommand(con
 }
 
 NS_IMETHODIMP
 nsSetDocumentStateCommand::DoCommandParams(const char *aCommandName,
                                            nsICommandParams *aParams,
                                            nsISupports *refCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (!editor) 
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
 
     PRBool modified; 
     nsresult rv = aParams->GetBooleanValue(STATE_ATTRIBUTE, &modified);
 
@@ -273,64 +272,60 @@ nsSetDocumentStateCommand::DoCommandPara
 
     return editor->SetFlags(flags);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
-    if (!htmleditor) 
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     PRBool desireCSS;
     nsresult rvCSS = aParams->GetBooleanValue(STATE_ATTRIBUTE, &desireCSS);
     if (NS_FAILED(rvCSS))
       return rvCSS;
 
     return htmleditor->SetIsCSSEnabled(desireCSS);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
-    if (!htmleditor) 
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     PRBool insertBrOnReturn;
     nsresult rvBR = aParams->GetBooleanValue(STATE_ATTRIBUTE,
                                               &insertBrOnReturn);
     if (NS_FAILED(rvBR))
       return rvBR;
 
     return htmleditor->SetReturnInParagraphCreatesNewParagraph(!insertBrOnReturn);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
-    if (!resizer)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
 
     PRBool enabled;
     nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
     if (NS_FAILED(rvOR))
       return rvOR;
 
     return resizer->SetObjectResizingEnabled(enabled);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
-    if (!editor)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
     PRBool enabled;
     nsresult rvOR = aParams->GetBooleanValue(STATE_ATTRIBUTE, &enabled);
     if (NS_FAILED(rvOR))
       return rvOR;
 
     return editor->SetInlineTableEditingEnabled(enabled);
   }
@@ -343,18 +338,17 @@ nsSetDocumentStateCommand::GetCommandSta
                                                  nsICommandParams *aParams,
                                                  nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(aParams);
   NS_ENSURE_ARG_POINTER(refCon);
 
   // The base editor owns most state info
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (!editor) 
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
   // Always get the enabled state
   PRBool outCmdEnabled = PR_FALSE;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
   nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified"))
@@ -375,54 +369,50 @@ nsSetDocumentStateCommand::GetCommandSta
     PRBool isReadOnly = flags & nsIPlaintextEditor::eEditorReadonlyMask;
     return aParams->SetBooleanValue(STATE_ATTRIBUTE, isReadOnly);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentUseCSS"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
-    if (!htmleditor)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     PRBool isCSS;
     htmleditor->GetIsCSSEnabled(&isCSS);
     return aParams->SetBooleanValue(STATE_ATTRIBUTE, isCSS);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_insertBrOnReturn"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLEditor> htmleditor = do_QueryInterface(refCon);
-    if (!htmleditor)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(htmleditor, NS_ERROR_INVALID_ARG);
 
     PRBool createPOnReturn;
     htmleditor->GetReturnInParagraphCreatesNewParagraph(&createPOnReturn);
     return aParams->SetBooleanValue(STATE_ATTRIBUTE, !createPOnReturn);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_enableObjectResizing"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLObjectResizer> resizer = do_QueryInterface(refCon);
-    if (!resizer)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(resizer, NS_ERROR_INVALID_ARG);
 
     PRBool enabled;
     resizer->GetObjectResizingEnabled(&enabled);
     return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled);
   }
 
   if (!nsCRT::strcmp(aCommandName, "cmd_enableInlineTableEditing"))
   {
     NS_ENSURE_ARG_POINTER(aParams);
     nsCOMPtr<nsIHTMLInlineTableEditor> editor = do_QueryInterface(refCon);
-    if (!editor)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
     PRBool enabled;
     editor->GetInlineTableEditingEnabled(&enabled);
     return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled);
   }
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/editor/composer/src/nsEditingSession.cpp
+++ b/editor/composer/src/nsEditingSession.cpp
@@ -242,18 +242,17 @@ nsEditingSession::DisableJSAndPlugins(ns
   mDisabledJSAndPlugins = PR_TRUE;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditingSession::RestoreJSAndPlugins(nsIDOMWindow *aWindow)
 {
-  if (!mDisabledJSAndPlugins)
-    return NS_OK;
+  NS_ENSURE_TRUE(mDisabledJSAndPlugins, NS_OK);
 
   mDisabledJSAndPlugins = PR_FALSE;
 
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   nsresult rv = docShell->SetAllowJavascript(mScriptsEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -298,18 +297,17 @@ const char* const gSupportedTextTypes[] 
   "text/xul",                  // obsolete type
   "application/vnd.mozilla.xul+xml",
   NULL      // IMPORTANT! Null must be at end
 };
 
 PRBool
 IsSupportedTextType(const char* aMIMEType)
 {
-  if (!aMIMEType)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(aMIMEType, PR_FALSE);
 
   PRInt32 i = 0;
   while (gSupportedTextTypes[i])
   {
     if (strcmp(gSupportedTextTypes[i], aMIMEType) == 0)
     {
       return PR_TRUE;
     }
@@ -547,21 +545,19 @@ nsEditingSession::RemoveListenersAndCont
 
   TearDownEditorOnWindow
 
   void tearDownEditorOnWindow (in nsIDOMWindow aWindow);
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::TearDownEditorOnWindow(nsIDOMWindow *aWindow)
 {
-  if (!mDoneSetup)
-    return NS_OK;
+  NS_ENSURE_TRUE(mDoneSetup, NS_OK);
 
-  if (!aWindow)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER);
 
   nsresult rv;
   
   // Kill any existing reload timer
   if (mLoadBlankDocTimer)
   {
     mLoadBlankDocTimer->Cancel();
     mLoadBlankDocTimer = nsnull;
@@ -1161,18 +1157,17 @@ nsEditingSession::EndPageLoad(nsIWebProg
   GetDocShellFromWindow
 
   Utility method. This will always return nsnull if no docShell is found.
 ----------------------------------------------------------------------------*/
 nsIDocShell *
 nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
-  if (!window)
-    return nsnull;
+  NS_ENSURE_TRUE(window, nsnull);
 
   return window->GetDocShell();
 }
 
 /*---------------------------------------------------------------------------
 
   GetEditorDocShellFromWindow
 
@@ -1399,18 +1394,17 @@ nsEditingSession::RestoreAnimationMode(n
     if (utils)
       utils->SetImageAnimationMode(mImageAnimationMode);
   }
 }
 
 nsresult
 nsEditingSession::DetachFromWindow(nsIDOMWindow* aWindow)
 {
-  if (!mDoneSetup)
-    return NS_OK;
+  NS_ENSURE_TRUE(mDoneSetup, NS_OK);
 
   NS_ASSERTION(mStateMaintainer, "mStateMaintainer should exist.");
 
   // Kill any existing reload timer
   if (mLoadBlankDocTimer)
   {
     mLoadBlankDocTimer->Cancel();
     mLoadBlankDocTimer = nsnull;
@@ -1428,18 +1422,17 @@ nsEditingSession::DetachFromWindow(nsIDO
   mWindowToBeEdited = nsnull;
 
   return NS_OK;
 }
 
 nsresult
 nsEditingSession::ReattachToWindow(nsIDOMWindow* aWindow)
 {
-  if (!mDoneSetup)
-    return NS_OK;
+  NS_ENSURE_TRUE(mDoneSetup, NS_OK);
 
   NS_ASSERTION(mStateMaintainer, "mStateMaintainer should exist.");
 
   // Imitate nsEditorDocShell::MakeEditable() to reattach the
   // old editor ot the window.
   nsresult rv;
 
   mWindowToBeEdited = do_GetWeakReference(aWindow);
@@ -1472,18 +1465,17 @@ nsEditingSession::ReattachToWindow(nsIDO
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mStateMaintainer)
     mStateMaintainer->Init(aWindow);
 
   // Get editor
   nsCOMPtr<nsIEditor> editor;
   rv = GetEditorForWindow(aWindow, getter_AddRefs(editor));
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   if (!mInteractive)
   {
     // Disable animation of images in this document:
     nsCOMPtr<nsIDOMWindowUtils> utils(do_GetInterface(aWindow));
     NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);
 
     rv = utils->GetImageAnimationMode(&mImageAnimationMode);
--- a/editor/composer/src/nsEditorSpellCheck.cpp
+++ b/editor/composer/src/nsEditorSpellCheck.cpp
@@ -115,18 +115,17 @@ nsEditorSpellCheck::InitSpellChecker(nsI
 {
   nsresult rv;
 
   // We can spell check with any editor type
   nsCOMPtr<nsITextServicesDocument>tsDoc =
      do_CreateInstance("@mozilla.org/textservices/textservicesdocument;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!tsDoc)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(tsDoc, NS_ERROR_NULL_POINTER);
 
   tsDoc->SetFilter(mTxtSrvFilter);
 
   // Pass the editor to the text services document
   rv = tsDoc->InitWithEditor(aEditor);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aEnableSelectionChecking) {
@@ -175,18 +174,17 @@ nsEditorSpellCheck::InitSpellChecker(nsI
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
 
   mSpellChecker = do_CreateInstance(NS_SPELLCHECKER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (!mSpellChecker)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NULL_POINTER);
 
   rv = mSpellChecker->SetDocument(tsDoc, PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Tell the spellchecker what dictionary to use:
 
   nsXPIDLString dictName;
 
@@ -253,18 +251,17 @@ nsEditorSpellCheck::InitSpellChecker(nsI
   DeleteSuggestedWordList();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::GetNextMisspelledWord(PRUnichar **aNextMisspelledWord)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   nsAutoString nextMisspelledWord;
   
   DeleteSuggestedWordList();
   // Beware! This may flush notifications via synchronous
   // ScrollSelectionIntoView.
   nsresult rv = mSpellChecker->NextMisspelledWord(nextMisspelledWord,
                                                   &mSuggestedWordList);
@@ -287,61 +284,56 @@ nsEditorSpellCheck::GetSuggestedWord(PRU
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::CheckCurrentWord(const PRUnichar *aSuggestedWord,
                                      PRBool *aIsMisspelled)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   DeleteSuggestedWordList();
   return mSpellChecker->CheckWord(nsDependentString(aSuggestedWord),
                                   aIsMisspelled, &mSuggestedWordList);
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::CheckCurrentWordNoSuggest(const PRUnichar *aSuggestedWord,
                                               PRBool *aIsMisspelled)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   return mSpellChecker->CheckWord(nsDependentString(aSuggestedWord),
                                   aIsMisspelled, nsnull);
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::ReplaceWord(const PRUnichar *aMisspelledWord,
                                 const PRUnichar *aReplaceWord,
                                 PRBool           allOccurrences)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   return mSpellChecker->Replace(nsDependentString(aMisspelledWord),
                                 nsDependentString(aReplaceWord), allOccurrences);
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::IgnoreWordAllOccurrences(const PRUnichar *aWord)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   return mSpellChecker->IgnoreAll(nsDependentString(aWord));
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::GetPersonalDictionary()
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
    // We can spell check with any editor type
   mDictionaryList.Clear();
   mDictionaryIndex = 0;
   return mSpellChecker->GetPersonalDictionary(&mDictionaryList);
 }
 
 NS_IMETHODIMP    
@@ -357,39 +349,35 @@ nsEditorSpellCheck::GetPersonalDictionar
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::AddWordToDictionary(const PRUnichar *aWord)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   return mSpellChecker->AddWordToPersonalDictionary(nsDependentString(aWord));
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::RemoveWordFromDictionary(const PRUnichar *aWord)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   return mSpellChecker->RemoveWordFromPersonalDictionary(nsDependentString(aWord));
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::GetDictionaryList(PRUnichar ***aDictionaryList, PRUint32 *aCount)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
-  if (!aDictionaryList || !aCount)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDictionaryList && aCount, NS_ERROR_NULL_POINTER);
 
   *aDictionaryList = 0;
   *aCount          = 0;
 
   nsTArray<nsString> dictList;
 
   nsresult rv = mSpellChecker->GetDictionaryList(&dictList);
 
@@ -400,30 +388,28 @@ nsEditorSpellCheck::GetDictionaryList(PR
 
   if (dictList.Length() < 1)
   {
     // If there are no dictionaries, return an array containing
     // one element and a count of one.
 
     tmpPtr = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *));
 
-    if (!tmpPtr)
-      return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(tmpPtr, NS_ERROR_OUT_OF_MEMORY);
 
     *tmpPtr          = 0;
     *aDictionaryList = tmpPtr;
     *aCount          = 0;
 
     return NS_OK;
   }
 
   tmpPtr = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * dictList.Length());
 
-  if (!tmpPtr)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(tmpPtr, NS_ERROR_OUT_OF_MEMORY);
 
   *aDictionaryList = tmpPtr;
   *aCount          = dictList.Length();
 
   PRUint32 i;
 
   for (i = 0; i < *aCount; i++)
   {
@@ -431,50 +417,45 @@ nsEditorSpellCheck::GetDictionaryList(PR
   }
 
   return rv;
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::GetCurrentDictionary(PRUnichar **aDictionary)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
-  if (!aDictionary)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDictionary, NS_ERROR_NULL_POINTER);
 
   *aDictionary = 0;
 
   nsAutoString dictStr;
   nsresult rv = mSpellChecker->GetCurrentDictionary(dictStr);
   NS_ENSURE_SUCCESS(rv, rv);
 
   *aDictionary = ToNewUnicode(dictStr);
 
   return rv;
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::SetCurrentDictionary(const PRUnichar *aDictionary)
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
-  if (!aDictionary)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDictionary, NS_ERROR_NULL_POINTER);
 
   return mSpellChecker->SetCurrentDictionary(nsDependentString(aDictionary));
 }
 
 NS_IMETHODIMP    
 nsEditorSpellCheck::UninitSpellChecker()
 {
-  if (!mSpellChecker)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED);
 
   // we preserve the last selected language, but ignore errors so we continue
   // to uninitialize
   nsresult rv = SaveDefaultDictionary();
   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "failed to set default dictionary");
 
   // Cleanup - kill the spell checker
   DeleteSuggestedWordList();
--- a/editor/libeditor/base/CreateElementTxn.cpp
+++ b/editor/libeditor/base/CreateElementTxn.cpp
@@ -223,16 +223,14 @@ NS_IMETHODIMP CreateElementTxn::GetTxnDe
 {
   aString.AssignLiteral("CreateElementTxn: ");
   aString += mTag;
   return NS_OK;
 }
 
 NS_IMETHODIMP CreateElementTxn::GetNewNode(nsIDOMNode **aNewNode)
 {
-  if (!aNewNode)
-    return NS_ERROR_NULL_POINTER;
-  if (!mNewNode)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aNewNode, NS_ERROR_NULL_POINTER);
+  NS_ENSURE_TRUE(mNewNode, NS_ERROR_NOT_INITIALIZED);
   *aNewNode = mNewNode;
   NS_ADDREF(*aNewNode);
   return NS_OK;
 }
--- a/editor/libeditor/base/DeleteRangeTxn.cpp
+++ b/editor/libeditor/base/DeleteRangeTxn.cpp
@@ -160,18 +160,17 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEd
 }
 
 NS_IMETHODIMP DeleteRangeTxn::DoTransaction(void)
 {
 #ifdef NS_DEBUG
   if (gNoisy) { printf("Do Delete Range\n"); }
 #endif
 
-  if (!mStartParent || !mEndParent || !mCommonParent || !mEditor) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mStartParent && mEndParent && mCommonParent && mEditor, NS_ERROR_NOT_INITIALIZED);
 
   nsresult result; 
   // build the child transactions
 
   if (mStartParent==mEndParent)
   { // the selection begins and ends in the same node
     result = CreateTxnsToDeleteBetween(mStartParent, mStartOffset, mEndOffset);
   }
@@ -218,30 +217,28 @@ NS_IMETHODIMP DeleteRangeTxn::DoTransact
 }
 
 NS_IMETHODIMP DeleteRangeTxn::UndoTransaction(void)
 {
 #ifdef NS_DEBUG
   if (gNoisy) { printf("Undo Delete Range\n"); }
 #endif
 
-  if (!mStartParent || !mEndParent || !mCommonParent || !mEditor) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mStartParent && mEndParent && mCommonParent && mEditor, NS_ERROR_NOT_INITIALIZED);
 
   return EditAggregateTxn::UndoTransaction();
 }
 
 NS_IMETHODIMP DeleteRangeTxn::RedoTransaction(void)
 {
 #ifdef NS_DEBUG
   if (gNoisy) { printf("Redo Delete Range\n"); }
 #endif
 
-  if (!mStartParent || !mEndParent || !mCommonParent || !mEditor) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mStartParent && mEndParent && mCommonParent && mEditor, NS_ERROR_NOT_INITIALIZED);
 
   return EditAggregateTxn::RedoTransaction();
 }
 
 NS_IMETHODIMP DeleteRangeTxn::GetTxnDescription(nsAString& aString)
 {
   aString.AssignLiteral("DeleteRangeTxn");
   return NS_OK;
@@ -253,18 +250,17 @@ DeleteRangeTxn::CreateTxnsToDeleteBetwee
                                           PRUint32    aEndOffset)
 {
   nsresult result;
   // see what kind of node we have
   nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(aStartParent);
   if (textNode)
   { // if the node is a text node, then delete text content
     nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn();
-    if (!txn)
-      return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
 
     PRInt32 numToDel;
     if (aStartOffset==aEndOffset)
       numToDel = 1;
     else
       numToDel = aEndOffset-aStartOffset;
     result = txn->Init(mEditor, textNode, aStartOffset, numToDel, mRangeUpdater);
     if (NS_SUCCEEDED(result))
@@ -286,18 +282,17 @@ DeleteRangeTxn::CreateTxnsToDeleteBetwee
     for (i=aStartOffset; i<aEndOffset; i++)
     {
       nsCOMPtr<nsIDOMNode> child;
       result = children->Item(i, getter_AddRefs(child));
       NS_ENSURE_SUCCESS(result, result);
       NS_ENSURE_TRUE(child, NS_ERROR_NULL_POINTER);
 
       nsRefPtr<DeleteElementTxn> txn = new DeleteElementTxn();
-      if (!txn)
-        return NS_ERROR_OUT_OF_MEMORY;
+      NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
 
       result = txn->Init(mEditor, child, mRangeUpdater);
       if (NS_SUCCEEDED(result))
         AppendChild(txn);
     }
   }
   return result;
 }
@@ -322,18 +317,17 @@ NS_IMETHODIMP DeleteRangeTxn::CreateTxns
     {
       start=0;
       numToDelete=aOffset;
     }
     
     if (numToDelete)
     {
       nsRefPtr<DeleteTextTxn> txn = new DeleteTextTxn();
-      if (!txn)
-        return NS_ERROR_OUT_OF_MEMORY;
+      NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
 
       result = txn->Init(mEditor, textNode, start, numToDelete, mRangeUpdater);
       if (NS_SUCCEEDED(result))
         AppendChild(txn);
     }
   }
 
   return result;
@@ -345,22 +339,20 @@ NS_IMETHODIMP DeleteRangeTxn::CreateTxns
   NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
 
   nsresult result = iter->Init(mRange);
   NS_ENSURE_SUCCESS(result, result);
 
   while (!iter->IsDone() && NS_SUCCEEDED(result))
   {
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(iter->GetCurrentNode());
-    if (!node)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     nsRefPtr<DeleteElementTxn> txn = new DeleteElementTxn();
-    if (!txn)
-      return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
 
     result = txn->Init(mEditor, node, mRangeUpdater);
     if (NS_SUCCEEDED(result))
       AppendChild(txn);
     iter->Next();
   }
   return result;
 }
--- a/editor/libeditor/base/EditAggregateTxn.cpp
+++ b/editor/libeditor/base/EditAggregateTxn.cpp
@@ -166,18 +166,17 @@ NS_IMETHODIMP EditAggregateTxn::GetTxnAt
   *aTxn = nsnull; // initialize out param as soon as we know it's a valid pointer
   // get the transaction at aIndex
   PRUint32 txnCount = mChildren.Length();
   if (0>aIndex || ((PRInt32)txnCount)<=aIndex) {
     return NS_ERROR_UNEXPECTED;
   }
   // ugh, this is all wrong - what a mess we have with editor transaction interfaces
   *aTxn = mChildren[aIndex];
-  if (!*aTxn)
-    return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_UNEXPECTED);
   NS_ADDREF(*aTxn);
   return NS_OK;
 }
 
 
 NS_IMETHODIMP EditAggregateTxn::SetName(nsIAtom *aName)
 {
   mName = do_QueryInterface(aName);
--- a/editor/libeditor/base/IMETextTxn.cpp
+++ b/editor/libeditor/base/IMETextTxn.cpp
@@ -76,18 +76,17 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCha
                                PRUint32                 aOffset,
                                PRUint32                 aReplaceLength,
                                nsIPrivateTextRangeList *aTextRangeList,
                                const nsAString         &aStringToInsert,
                                nsWeakPtr                aSelConWeak)
 {
   NS_ASSERTION(aElement, "illegal value- null ptr- aElement");
   NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList");
-  if (!aElement || !aTextRangeList)
-     return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement && aTextRangeList, NS_ERROR_NULL_POINTER);
   mElement = do_QueryInterface(aElement);
   mOffset = aOffset;
   mReplaceLength = aReplaceLength;
   mStringToInsert = aStringToInsert;
   mSelConWeak = aSelConWeak;
   mRangeList = do_QueryInterface(aTextRangeList);
   mFixed = PR_FALSE;
   return NS_OK;
@@ -138,18 +137,17 @@ NS_IMETHODIMP IMETextTxn::UndoTransactio
   }
   return result;
 }
 
 NS_IMETHODIMP IMETextTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
 {
   NS_ASSERTION(aDidMerge, "illegal vaule- null ptr- aDidMerge");
   NS_ASSERTION(aTransaction, "illegal vaule- null ptr- aTransaction");
-  if (!aDidMerge || !aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDidMerge && aTransaction, NS_ERROR_NULL_POINTER);
     
 #ifdef DEBUG_IMETXN
   printf("Merge IME Text element = %p\n", mElement.get());
 #endif
 
   // 
   // check to make sure we aren't fixed, if we are then nothing get's absorbed
   //
@@ -213,18 +211,17 @@ static SelectionType TextRangeToSelectio
       default:
            return nsISelectionController::SELECTION_NORMAL;
    };
 }
 
 NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aTextRangeList)
 {
   NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
-  if (!aTextRangeList)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTextRangeList, NS_ERROR_NULL_POINTER);
   aResult = mStringToInsert;
   *aTextRangeList = mRangeList;
   return NS_OK;
 }
 
 static SelectionType sel[4]=
 {
   nsISelectionController::SELECTION_IME_RAWINPUT,
--- a/editor/libeditor/base/InsertElementTxn.cpp
+++ b/editor/libeditor/base/InsertElementTxn.cpp
@@ -67,25 +67,23 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMETHODIMP InsertElementTxn::Init(nsIDOMNode *aNode,
                                      nsIDOMNode *aParent,
                                      PRInt32     aOffset,
                                      nsIEditor  *aEditor)
 {
   NS_ASSERTION(aNode && aParent && aEditor, "bad arg");
-  if (!aNode || !aParent || !aEditor)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aParent && aEditor, NS_ERROR_NULL_POINTER);
 
   mNode = do_QueryInterface(aNode);
   mParent = do_QueryInterface(aParent);
   mOffset = aOffset;
   mEditor = aEditor;
-  if (!mNode || !mParent || !mEditor)
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(mNode && mParent && mEditor, NS_ERROR_INVALID_ARG);
   return NS_OK;
 }
 
 
 NS_IMETHODIMP InsertElementTxn::DoTransaction(void)
 {
 #ifdef NS_DEBUG
   if (gNoisy) 
--- a/editor/libeditor/base/SplitElementTxn.cpp
+++ b/editor/libeditor/base/SplitElementTxn.cpp
@@ -256,16 +256,14 @@ NS_IMETHODIMP SplitElementTxn::RedoTrans
 NS_IMETHODIMP SplitElementTxn::GetTxnDescription(nsAString& aString)
 {
   aString.AssignLiteral("SplitElementTxn");
   return NS_OK;
 }
 
 NS_IMETHODIMP SplitElementTxn::GetNewNode(nsIDOMNode **aNewNode)
 {
-  if (!aNewNode)
-    return NS_ERROR_NULL_POINTER;
-  if (!mNewLeftNode)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aNewNode, NS_ERROR_NULL_POINTER);
+  NS_ENSURE_TRUE(mNewLeftNode, NS_ERROR_NOT_INITIALIZED);
   *aNewNode = mNewLeftNode;
   NS_ADDREF(*aNewNode);
   return NS_OK;
 }
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -480,32 +480,30 @@ nsEditor::GetIsDocumentEditable(PRBool *
   *aIsDocumentEditable = doc ? PR_TRUE : PR_FALSE;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsEditor::GetDocument(nsIDOMDocument **aDoc)
 {
-  if (!aDoc)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
   *aDoc = nsnull; // init out param
   NS_PRECONDITION(mDocWeak, "bad state, mDocWeak weak pointer not initialized");
   nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
   NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
   NS_ADDREF(*aDoc = doc);
   return NS_OK;
 }
 
 
 nsresult 
 nsEditor::GetPresShell(nsIPresShell **aPS)
 {
-  if (!aPS)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aPS, NS_ERROR_NULL_POINTER);
   *aPS = nsnull; // init out param
   NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak");
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
   NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
   NS_ADDREF(*aPS = ps);
   return NS_OK;
 }
 
@@ -524,18 +522,17 @@ nsEditor::SetContentsMIMEType(const char
 {
   mContentMIMEType.Assign(aContentsMIMEType ? aContentsMIMEType : "");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::GetSelectionController(nsISelectionController **aSel)
 {
-  if (!aSel)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
   *aSel = nsnull; // init out param
   NS_PRECONDITION(mSelConWeak, "bad state, null mSelConWeak");
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
   NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
   NS_ADDREF(*aSel = selCon);
   return NS_OK;
 }
 
@@ -546,18 +543,17 @@ nsEditor::DeleteSelection(EDirection aAc
   return DeleteSelectionImpl(aAction);
 }
 
 
 
 NS_IMETHODIMP
 nsEditor::GetSelection(nsISelection **aSelection)
 {
-  if (!aSelection)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   *aSelection = nsnull;
   nsCOMPtr<nsISelectionController> selcon = do_QueryReferent(mSelConWeak);
   NS_ENSURE_TRUE(selcon, NS_ERROR_NOT_INITIALIZED);
   return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection);  // does an addref
 }
 
 NS_IMETHODIMP 
 nsEditor::DoTransaction(nsITransaction *aTxn)
@@ -691,18 +687,17 @@ nsEditor::EnableUndo(PRBool aEnable)
 
 
 NS_IMETHODIMP
 nsEditor::GetTransactionManager(nsITransactionManager* *aTxnManager)
 {
   NS_ENSURE_ARG_POINTER(aTxnManager);
   
   *aTxnManager = NULL;
-  if (!mTxnMgr)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mTxnMgr, NS_ERROR_FAILURE);
 
   NS_ADDREF(*aTxnManager = mTxnMgr);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::SetTransactionManager(nsITransactionManager *aTxnManager)
 {
@@ -719,18 +714,17 @@ nsEditor::Undo(PRUint32 aCount)
   if (gNoisy) { printf("Editor::Undo ----------\n"); }
 #endif
 
   nsresult result = NS_OK;
   ForceCompositionEnd();
 
   PRBool hasTxnMgr, hasTransaction = PR_FALSE;
   CanUndo(&hasTxnMgr, &hasTransaction);
-  if (!hasTransaction)
-    return result;
+  NS_ENSURE_TRUE(hasTransaction, result);
 
   nsAutoRules beginRulesSniffing(this, kOpUndo, nsIEditor::eNone);
 
   if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
   {
     PRUint32 i=0;
     for ( ; i<aCount; i++)
     {
@@ -746,18 +740,17 @@ nsEditor::Undo(PRUint32 aCount)
 
   NotifyEditorObservers();  
   return result;
 }
 
 
 NS_IMETHODIMP nsEditor::CanUndo(PRBool *aIsEnabled, PRBool *aCanUndo)
 {
-  if (!aIsEnabled || !aCanUndo)
-     return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIsEnabled && aCanUndo, NS_ERROR_NULL_POINTER);
   *aIsEnabled = ((PRBool)((nsITransactionManager *)0!=mTxnMgr.get()));
   if (*aIsEnabled)
   {
     PRInt32 numTxns=0;
     mTxnMgr->GetNumberOfUndoItems(&numTxns);
     *aCanUndo = ((PRBool)(0!=numTxns));
   }
   else {
@@ -773,18 +766,17 @@ nsEditor::Redo(PRUint32 aCount)
 #ifdef NS_DEBUG_EDITOR
   if (gNoisy) { printf("Editor::Redo ----------\n"); }
 #endif
 
   nsresult result = NS_OK;
 
   PRBool hasTxnMgr, hasTransaction = PR_FALSE;
   CanRedo(&hasTxnMgr, &hasTransaction);
-  if (!hasTransaction)
-    return result;
+  NS_ENSURE_TRUE(hasTransaction, result);
 
   nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone);
 
   if ((nsITransactionManager *)nsnull!=mTxnMgr.get())
   {
     PRUint32 i=0;
     for ( ; i<aCount; i++)
     {
@@ -800,18 +792,17 @@ nsEditor::Redo(PRUint32 aCount)
 
   NotifyEditorObservers();  
   return result;
 }
 
 
 NS_IMETHODIMP nsEditor::CanRedo(PRBool *aIsEnabled, PRBool *aCanRedo)
 {
-  if (!aIsEnabled || !aCanRedo)
-     return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIsEnabled && aCanRedo, NS_ERROR_NULL_POINTER);
 
   *aIsEnabled = ((PRBool)((nsITransactionManager *)0!=mTxnMgr.get()));
   if (*aIsEnabled)
   {
     PRInt32 numTxns=0;
     mTxnMgr->GetNumberOfRedoItems(&numTxns);
     *aCanRedo = ((PRBool)(0!=numTxns));
   }
@@ -865,18 +856,17 @@ nsEditor::BeginPlaceHolderTransaction(ns
     // time to turn on the batch
     BeginUpdateViewBatch();
     mPlaceHolderTxn = nsnull;
     mPlaceHolderName = aName;
     nsCOMPtr<nsISelection> selection;
     nsresult res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
     mSelState = new nsSelectionState();
-    if (!mSelState)
-      return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(mSelState, NS_ERROR_OUT_OF_MEMORY);
 
     mSelState->SaveSelection(selection);
   }
   mPlaceHolderBatch++;
 
   return NS_OK;
 }
 
@@ -959,18 +949,17 @@ nsEditor::SetShouldTxnSetSelection(PRBoo
 }
 
 NS_IMETHODIMP
 nsEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
 {
   *aDocumentIsEmpty = PR_TRUE;
 
   nsIDOMElement *rootElement = GetRoot(); 
-  if (!rootElement)
-    return NS_ERROR_NULL_POINTER; 
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); 
 
   PRBool hasChildNodes;
   nsresult res = rootElement->HasChildNodes(&hasChildNodes);
 
   *aDocumentIsEmpty = !hasChildNodes;
 
   return res;
 }
@@ -997,23 +986,21 @@ NS_IMETHODIMP nsEditor::BeginningOfDocum
 {
   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;
-  if (!selection)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
     
   // get the root element 
   nsIDOMElement *rootElement = GetRoot(); 
-  if (!rootElement)
-    return NS_ERROR_NULL_POINTER; 
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); 
   
   // find first editable thingy
   nsCOMPtr<nsIDOMNode> firstNode;
   result = GetFirstEditableNode(rootElement, address_of(firstNode));
   if (firstNode)
   {
     // if firstNode is text, set selection to beginning of the text node
     if (IsTextNode(firstNode)) 
@@ -1049,33 +1036,31 @@ nsEditor::EndOfDocument()
   // get selection 
   nsCOMPtr<nsISelection> selection; 
   res = GetSelection(getter_AddRefs(selection)); 
   NS_ENSURE_SUCCESS(res, res); 
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); 
   
   // get the root element 
   nsIDOMElement *rootElement = GetRoot(); 
-  if (!rootElement)
-    return NS_ERROR_NULL_POINTER; 
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); 
 
   // get the length of the rot element 
   PRUint32 len; 
   res = GetLengthOfDOMNode(rootElement, len); 
   NS_ENSURE_SUCCESS(res, res);
 
   // set the selection to after the last child of the root element 
   return selection->Collapse(rootElement, (PRInt32)len); 
 } 
   
 NS_IMETHODIMP
 nsEditor::GetDocumentModified(PRBool *outDocModified)
 {
-  if (!outDocModified)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outDocModified, NS_ERROR_NULL_POINTER);
 
   PRInt32  modCount = 0;
   GetModificationCount(&modCount);
 
   *outDocModified = (modCount != 0);
   return NS_OK;
 }
 
@@ -1197,18 +1182,17 @@ nsEditor::SetAttribute(nsIDOMElement *aE
 }
 
 NS_IMETHODIMP 
 nsEditor::GetAttributeValue(nsIDOMElement *aElement, 
                             const nsAString & aAttribute, 
                             nsAString & aResultValue, 
                             PRBool *aResultIsSet)
 {
-  if (!aResultIsSet)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aResultIsSet, NS_ERROR_NULL_POINTER);
   *aResultIsSet=PR_FALSE;
   nsresult result=NS_OK;
   if (aElement)
   {
     nsCOMPtr<nsIDOMAttr> attNode;
     result = aElement->GetAttributeNode(aAttribute, getter_AddRefs(attNode));
     if ((NS_SUCCEEDED(result)) && attNode)
     {
@@ -1466,18 +1450,17 @@ NS_IMETHODIMP nsEditor::DeleteNode(nsIDO
 nsresult
 nsEditor::ReplaceContainer(nsIDOMNode *inNode, 
                            nsCOMPtr<nsIDOMNode> *outNode, 
                            const nsAString &aNodeType,
                            const nsAString *aAttribute,
                            const nsAString *aValue,
                            PRBool aCloneAttributes)
 {
-  if (!inNode || !outNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inNode && outNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   nsresult res = GetNodeLocation(inNode, address_of(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
 
   // create new container
   nsCOMPtr<nsIContent> newContent;
 
@@ -1530,18 +1513,17 @@ nsEditor::ReplaceContainer(nsIDOMNode *i
 
 ///////////////////////////////////////////////////////////////////////////
 // RemoveContainer: remove inNode, reparenting its children into their
 //                  the parent of inNode
 //
 nsresult
 nsEditor::RemoveContainer(nsIDOMNode *inNode)
 {
-  if (!inNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   
   nsresult res = GetNodeLocation(inNode, address_of(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
   
   // loop through the child nodes of inNode and promote them
   // into inNode's parent.
@@ -1579,18 +1561,17 @@ nsEditor::RemoveContainer(nsIDOMNode *in
 //                   of outNode, and outNode can be child of old parent.
 nsresult
 nsEditor::InsertContainerAbove( nsIDOMNode *inNode, 
                                 nsCOMPtr<nsIDOMNode> *outNode, 
                                 const nsAString &aNodeType,
                                 const nsAString *aAttribute,
                                 const nsAString *aValue)
 {
-  if (!inNode || !outNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inNode && outNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   nsresult res = GetNodeLocation(inNode, address_of(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
 
   // create new container
   nsCOMPtr<nsIContent> newContent;
 
@@ -1624,18 +1605,17 @@ nsEditor::InsertContainerAbove( nsIDOMNo
   return InsertNode(*outNode, parent, offset);
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // MoveNode:  move aNode to {aParent,aOffset}
 nsresult
 nsEditor::MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset)
 {
-  if (!aNode || !aParent)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aParent, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> oldParent;
   PRInt32 oldOffset;
   nsresult res = GetNodeLocation(aNode, address_of(oldParent), &oldOffset);
   
   if (aOffset == -1)
   {
     PRUint32 unsignedOffset;
@@ -1670,35 +1650,33 @@ nsEditor::MoveNode(nsIDOMNode *aNode, ns
 #endif
 
 NS_IMETHODIMP
 nsEditor::AddEditorObserver(nsIEditorObserver *aObserver)
 {
   // we don't keep ownership of the observers.  They must
   // remove themselves as observers before they are destroyed.
   
-  if (!aObserver)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aObserver, NS_ERROR_NULL_POINTER);
 
   // Make sure the listener isn't already on the list
   if (mEditorObservers.IndexOf(aObserver) == -1) 
   {
     if (!mEditorObservers.AppendObject(aObserver))
       return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsEditor::RemoveEditorObserver(nsIEditorObserver *aObserver)
 {
-  if (!aObserver)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aObserver, NS_ERROR_FAILURE);
 
   if (!mEditorObservers.RemoveObject(aObserver))
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
 void nsEditor::NotifyEditorObservers(void)
@@ -1711,35 +1689,33 @@ void nsEditor::NotifyEditorObservers(voi
 #pragma mark -
 #pragma mark  action listener maintainance
 #pragma mark -
 #endif
 
 NS_IMETHODIMP
 nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   // Make sure the listener isn't already on the list
   if (mActionListeners.IndexOf(aListener) == -1) 
   {
     if (!mActionListeners.AppendObject(aListener))
       return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsEditor::RemoveEditActionListener(nsIEditActionListener *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE);
 
   if (!mActionListeners.RemoveObject(aListener))
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
 
@@ -1748,34 +1724,32 @@ nsEditor::RemoveEditActionListener(nsIEd
 #pragma mark  docstate listener maintainance
 #pragma mark -
 #endif
 
 
 NS_IMETHODIMP
 nsEditor::AddDocumentStateListener(nsIDocumentStateListener *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   if (mDocStateListeners.IndexOf(aListener) == -1)
   {
     if (!mDocStateListeners.AppendObject(aListener))
       return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsEditor::RemoveDocumentStateListener(nsIDocumentStateListener *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   if (!mDocStateListeners.RemoveObject(aListener))
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
 
@@ -1949,53 +1923,47 @@ nsEditor::GetPhonetic(nsAString& aPhonet
 
   return NS_OK;
 }
 
 
 static nsresult
 GetEditorContentWindow(nsIDOMElement *aRoot, nsIWidget **aResult)
 {
-  if (!aRoot || !aResult)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRoot && aResult, NS_ERROR_NULL_POINTER);
 
   *aResult = 0;
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aRoot);
 
-  if (!content)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
   // Not ref counted
   nsIFrame *frame = content->GetPrimaryFrame();
 
-  if (!frame)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
   *aResult = frame->GetWindow();
-  if (!*aResult)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(*aResult, NS_ERROR_FAILURE);
 
   NS_ADDREF(*aResult);
   return NS_OK;
 }
 
 nsresult
 nsEditor::GetWidget(nsIWidget **aWidget)
 {
-  if (!aWidget)
-    return NS_ERROR_NULL_POINTER;
+  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;
-  if (!widget)
-    return NS_ERROR_NOT_AVAILABLE;
+  NS_ENSURE_TRUE(widget, NS_ERROR_NOT_AVAILABLE);
 
   NS_ADDREF(*aWidget = widget);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::ForceCompositionEnd()
@@ -2116,23 +2084,21 @@ nsEditor::EndOperation()
   mDirection = eNone;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::CloneAttribute(const nsAString & aAttribute,
                          nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
 {
-  if (!aDestNode || !aSourceNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDestNode && aSourceNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMElement> destElement = do_QueryInterface(aDestNode);
   nsCOMPtr<nsIDOMElement> sourceElement = do_QueryInterface(aSourceNode);
-  if (!destElement || !sourceElement)
-    return NS_ERROR_NO_INTERFACE;
+  NS_ENSURE_TRUE(destElement && sourceElement, NS_ERROR_NO_INTERFACE);
 
   nsAutoString attrValue;
   PRBool isAttrSet;
   nsresult rv = GetAttributeValue(sourceElement,
                                   aAttribute,
                                   attrValue,
                                   &isAttrSet);
   if (NS_FAILED(rv))
@@ -2144,38 +2110,34 @@ nsEditor::CloneAttribute(const nsAString
 
   return rv;
 }
 
 // Objects must be DOM elements
 NS_IMETHODIMP
 nsEditor::CloneAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
 {
-  if (!aDestNode || !aSourceNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDestNode && aSourceNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMElement> destElement = do_QueryInterface(aDestNode);
   nsCOMPtr<nsIDOMElement> sourceElement = do_QueryInterface(aSourceNode);
-  if (!destElement || !sourceElement)
-    return NS_ERROR_NO_INTERFACE;
+  NS_ENSURE_TRUE(destElement && sourceElement, NS_ERROR_NO_INTERFACE);
 
   nsCOMPtr<nsIDOMNamedNodeMap> sourceAttributes;
   sourceElement->GetAttributes(getter_AddRefs(sourceAttributes));
   nsCOMPtr<nsIDOMNamedNodeMap> destAttributes;
   destElement->GetAttributes(getter_AddRefs(destAttributes));
-  if (!sourceAttributes || !destAttributes)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(sourceAttributes && destAttributes, NS_ERROR_FAILURE);
 
   nsAutoEditBatch beginBatching(this);
 
   // Use transaction system for undo only if destination
   //   is already in the document
   nsIDOMElement *rootElement = GetRoot();
-  if (!rootElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
 
   PRBool destInBody = PR_TRUE;
   nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(rootElement);
   nsCOMPtr<nsIDOMNode> p = aDestNode;
   while (p && p != rootNode)
   {
     nsCOMPtr<nsIDOMNode> tmp;
     if (NS_FAILED(p->GetParentNode(getter_AddRefs(tmp))) || !tmp)
@@ -2515,18 +2477,17 @@ nsresult nsEditor::GetLastEditableNode(n
 }
 #endif
 
 
 NS_IMETHODIMP
 nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationType)
 {
   PRInt32 numListeners = mDocStateListeners.Count();
-  if (!numListeners)
-    return NS_OK;    // maybe there just aren't any.
+  NS_ENSURE_TRUE(numListeners, NS_OK);    // maybe there just aren't any.
  
   nsCOMArray<nsIDocumentStateListener> listeners(mDocStateListeners);
   nsresult rv = NS_OK;
   PRInt32 i;
 
   switch (aNotificationType)
   {
     case eDocumentCreated:
@@ -2616,54 +2577,48 @@ NS_IMETHODIMP nsEditor::DeleteText(nsIDO
 }
 
 
 NS_IMETHODIMP nsEditor::CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
                                                PRUint32             aOffset,
                                                PRUint32             aLength,
                                                DeleteTextTxn      **aTxn)
 {
-  if (!aElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   *aTxn = new DeleteTextTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
   return (*aTxn)->Init(this, aElement, aOffset, aLength, &mRangeUpdater);
 }
 
 
 
 
 NS_IMETHODIMP nsEditor::CreateTxnForSplitNode(nsIDOMNode *aNode,
                                          PRUint32    aOffset,
                                          SplitElementTxn **aTxn)
 {
-  if (!aNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   *aTxn = new SplitElementTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aNode, aOffset);
 }
 
 NS_IMETHODIMP nsEditor::CreateTxnForJoinNode(nsIDOMNode  *aLeftNode,
                                              nsIDOMNode  *aRightNode,
                                              JoinElementTxn **aTxn)
 {
-  if (!aLeftNode || !aRightNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aLeftNode && aRightNode, NS_ERROR_NULL_POINTER);
 
   *aTxn = new JoinElementTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aLeftNode, aRightNode);
 }
 
 
 // END nsEditor core implementation
 
@@ -3018,18 +2973,17 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNo
 
 nsresult 
 nsEditor::GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
 {
   NS_ASSERTION((aChild && aParent), "bad args");
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
   nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
-  if (!cChild || !content)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(cChild && content, NS_ERROR_NULL_POINTER);
 
   aOffset = content->IndexOf(cChild);
 
   return NS_OK;
 }
 
 nsresult 
 nsEditor::GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr<nsIDOMNode> *outParent, PRInt32 *outOffset)
@@ -3495,18 +3449,17 @@ PRBool
 nsEditor::TagCanContainTag(const nsAString &aParentTag, const nsAString &aChildTag)
 {
   return PR_TRUE;
 }
 
 PRBool 
 nsEditor::IsRootNode(nsIDOMNode *inNode) 
 {
-  if (!inNode)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(inNode, PR_FALSE);
 
   nsIDOMElement *rootElement = GetRoot();
 
   nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(rootElement);
 
   return inNode == rootNode;
 }
 
@@ -3791,36 +3744,34 @@ nsEditor::GetIndexOf(nsIDOMNode *parent,
 //
 nsCOMPtr<nsIDOMNode> 
 nsEditor::GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset)
 {
   nsCOMPtr<nsIDOMNode> resultNode;
   
   nsCOMPtr<nsIContent> parent = do_QueryInterface(aParent);
 
-  if (!parent) 
-    return resultNode;
+  NS_ENSURE_TRUE(parent, resultNode);
 
   resultNode = do_QueryInterface(parent->GetChildAt(aOffset));
 
   return resultNode;
 }
   
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetStartNodeAndOffset: returns whatever the start parent & offset is of 
 //                        the first range in the selection.
 nsresult 
 nsEditor::GetStartNodeAndOffset(nsISelection *aSelection,
                                        nsIDOMNode **outStartNode,
                                        PRInt32 *outStartOffset)
 {
-  if (!outStartNode || !outStartOffset || !aSelection) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outStartNode && outStartOffset && aSelection, NS_ERROR_NULL_POINTER);
 
   *outStartNode = nsnull;
 
   // brade:  set outStartNode to null or ?
 
   nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(aSelection));
   nsCOMPtr<nsIEnumerator> enumerator;
   nsresult result = selPrivate->GetEnumerator(getter_AddRefs(enumerator));
@@ -3828,18 +3779,17 @@ nsEditor::GetStartNodeAndOffset(nsISelec
     return NS_ERROR_FAILURE;
     
   enumerator->First(); 
   nsCOMPtr<nsISupports> currentItem;
   if (NS_FAILED(enumerator->CurrentItem(getter_AddRefs(currentItem))))
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
-  if (!range)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
     
   if (NS_FAILED(range->GetStartContainer(outStartNode)))
     return NS_ERROR_FAILURE;
     
   if (NS_FAILED(range->GetStartOffset(outStartOffset)))
     return NS_ERROR_FAILURE;
     
   return NS_OK;
@@ -3849,35 +3799,33 @@ nsEditor::GetStartNodeAndOffset(nsISelec
 ///////////////////////////////////////////////////////////////////////////
 // GetEndNodeAndOffset: returns whatever the end parent & offset is of 
 //                        the first range in the selection.
 nsresult 
 nsEditor::GetEndNodeAndOffset(nsISelection *aSelection,
                                        nsIDOMNode **outEndNode,
                                        PRInt32 *outEndOffset)
 {
-  if (!outEndNode || !outEndOffset) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outEndNode && outEndOffset, NS_ERROR_NULL_POINTER);
 
   *outEndNode = nsnull;
     
   nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(aSelection));
   nsCOMPtr<nsIEnumerator> enumerator;
   nsresult result = selPrivate->GetEnumerator(getter_AddRefs(enumerator));
   if (NS_FAILED(result) || !enumerator)
     return NS_ERROR_FAILURE;
     
   enumerator->First(); 
   nsCOMPtr<nsISupports> currentItem;
   if (NS_FAILED(enumerator->CurrentItem(getter_AddRefs(currentItem))))
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
-  if (!range)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
     
   if (NS_FAILED(range->GetEndContainer(outEndNode)))
     return NS_ERROR_FAILURE;
     
   if (NS_FAILED(range->GetEndOffset(outEndOffset)))
     return NS_ERROR_FAILURE;
     
   return NS_OK;
@@ -4451,141 +4399,127 @@ nsEditor::DoAfterRedoTransaction()
 }
 
 NS_IMETHODIMP 
 nsEditor::CreateTxnForSetAttribute(nsIDOMElement *aElement, 
                                    const nsAString& aAttribute, 
                                    const nsAString& aValue,
                                    ChangeAttributeTxn ** aTxn)
 {
-  if (!aElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   *aTxn = new ChangeAttributeTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
   return (*aTxn)->Init(this, aElement, aAttribute, aValue, PR_FALSE);
 }
 
 
 NS_IMETHODIMP 
 nsEditor::CreateTxnForRemoveAttribute(nsIDOMElement *aElement, 
                                       const nsAString& aAttribute,
                                       ChangeAttributeTxn ** aTxn)
 {
-  if (!aElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   *aTxn = new ChangeAttributeTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aElement, aAttribute, EmptyString(), PR_TRUE);
 }
 
 
 NS_IMETHODIMP nsEditor::CreateTxnForCreateElement(const nsAString& aTag,
                                                   nsIDOMNode     *aParent,
                                                   PRInt32         aPosition,
                                                   CreateElementTxn ** aTxn)
 {
-  if (!aParent)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aParent, NS_ERROR_NULL_POINTER);
 
   *aTxn = new CreateElementTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aTag, aParent, aPosition);
 }
 
 
 NS_IMETHODIMP nsEditor::CreateTxnForInsertElement(nsIDOMNode * aNode,
                                                   nsIDOMNode * aParent,
                                                   PRInt32      aPosition,
                                                   InsertElementTxn ** aTxn)
 {
-  if (!aNode || !aParent)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aParent, NS_ERROR_NULL_POINTER);
 
   *aTxn = new InsertElementTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(aNode, aParent, aPosition, this);
 }
 
 NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement,
                                              DeleteElementTxn ** aTxn)
 {
-  if (!aElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   *aTxn = new DeleteElementTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aElement, &mRangeUpdater);
 }
 
 NS_IMETHODIMP 
 nsEditor::CreateTxnForIMEText(const nsAString& aStringToInsert,
                               IMETextTxn ** aTxn)
 {
   NS_ASSERTION(aTxn, "illegal value- null ptr- aTxn");
      
   *aTxn = new IMETextTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(mIMETextNode, mIMETextOffset, mIMEBufferLength,
                        mIMETextRangeList, aStringToInsert, mSelConWeak);
 }
 
 
 NS_IMETHODIMP 
 nsEditor::CreateTxnForAddStyleSheet(nsCSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn)
 {
   *aTxn = new AddStyleSheetTxn();
-  if (! *aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE( *aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aSheet);
 }
 
 
 
 NS_IMETHODIMP 
 nsEditor::CreateTxnForRemoveStyleSheet(nsCSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn)
 {
   *aTxn = new RemoveStyleSheetTxn();
-  if (! *aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE( *aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
 
   return (*aTxn)->Init(this, aSheet);
 }
 
 
 NS_IMETHODIMP
 nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction,
                                       EditAggregateTxn ** aTxn,
                                       nsIDOMNode ** aNode,
                                       PRInt32 *aOffset,
                                       PRInt32 *aLength)
 {
-  if (!aTxn)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTxn, NS_ERROR_NULL_POINTER);
   *aTxn = nsnull;
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
   NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsISelection> selection;
   nsresult result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
                                          getter_AddRefs(selection));
   if ((NS_SUCCEEDED(result)) && selection)
@@ -4878,18 +4812,17 @@ nsEditor::CreateRange(nsIDOMNode *aStart
                       nsIDOMNode *aEndParent, PRInt32 aEndOffset,
                       nsIDOMRange **aRange)
 {
   nsresult result;
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
   if (NS_FAILED(result))
     return result;
 
-  if (!*aRange)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SetStart(aStartParent, aStartOffset);
 
   if (NS_SUCCEEDED(result))
     result = (*aRange)->SetEnd(aEndParent, aEndOffset);
 
   if (NS_FAILED(result))
   {
@@ -4936,30 +4869,28 @@ nsresult nsEditor::ClearSelection()
 
 nsresult
 nsEditor::CreateHTMLContent(const nsAString& aTag, nsIContent** aContent)
 {
   nsCOMPtr<nsIDOMDocument> tempDoc;
   GetDocument(getter_AddRefs(tempDoc));
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(tempDoc);
-  if (!doc)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   // XXX Wallpaper over editor bug (editor tries to create elements with an
   //     empty nodename).
   if (aTag.IsEmpty()) {
     NS_ERROR("Don't pass an empty tag to nsEditor::CreateHTMLContent, "
              "check caller.");
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIAtom> tag = do_GetAtom(aTag);
-  if (!tag)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(tag, NS_ERROR_OUT_OF_MEMORY);
 
   return doc->CreateElem(tag, nsnull, kNameSpaceID_XHTML, PR_FALSE, aContent);
 }
 
 nsresult
 nsEditor::SetAttributeOrEquivalent(nsIDOMElement * aElement,
                                    const nsAString & aAttribute,
                                    const nsAString & aValue,
@@ -5144,18 +5075,17 @@ nsEditor::SwitchTextDirection()
   nsIDOMElement *rootElement = GetRoot();
 
   nsresult rv;
   nsCOMPtr<nsIContent> content = do_QueryInterface(rootElement, &rv);
   if (NS_FAILED(rv))
     return rv;
 
   nsIFrame *frame = content->GetPrimaryFrame();
-  if (!frame)
-    return NS_ERROR_FAILURE; 
+  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
     rv = rootElement->SetAttribute(NS_LITERAL_STRING("dir"), NS_LITERAL_STRING("rtl"));
 
   return rv;
--- a/editor/libeditor/base/nsEditorCommands.cpp
+++ b/editor/libeditor/base/nsEditorCommands.cpp
@@ -407,18 +407,17 @@ nsPasteCommand::IsCommandEnabled(const c
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsPasteCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
   
   return editor->Paste(nsIClipboard::kGlobalClipboard);
 }
 
 NS_IMETHODIMP 
 nsPasteCommand::DoCommandParams(const char *aCommandName,
                                 nsICommandParams *aParams,
                                 nsISupports *aCommandRefCon)
@@ -457,48 +456,43 @@ nsPasteTransferableCommand::DoCommand(co
 }
 
 NS_IMETHODIMP 
 nsPasteTransferableCommand::DoCommandParams(const char *aCommandName,
                                             nsICommandParams *aParams,
                                             nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
   
   nsCOMPtr<nsISupports> supports;
   aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
-  if (!supports)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(supports, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsITransferable> trans = do_QueryInterface(supports);
-  if (!trans)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
 
   return editor->PasteTransferable(trans);
 }
 
 NS_IMETHODIMP 
 nsPasteTransferableCommand::GetCommandStateParams(const char *aCommandName,
                                                   nsICommandParams *aParams,
                                                   nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsITransferable> trans;
 
   nsCOMPtr<nsISupports> supports;
   aParams->GetISupportsValue("transferable", getter_AddRefs(supports));
   if (supports) {
     trans = do_QueryInterface(supports);
-    if (!trans)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
   }
 
   PRBool canPaste;
   nsresult rv = editor->CanPasteTransferable(trans, &canPaste);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return aParams->SetBooleanValue(STATE_ENABLED, canPaste);
 }
@@ -514,18 +508,17 @@ nsSwitchTextDirectionCommand::IsCommandE
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSwitchTextDirectionCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   return editor->SwitchTextDirection();
 }
 
 NS_IMETHODIMP 
 nsSwitchTextDirectionCommand::DoCommandParams(const char *aCommandName,
                                 nsICommandParams *aParams,
                                 nsISupports *aCommandRefCon)
@@ -547,18 +540,17 @@ NS_IMETHODIMP
 nsDeleteCommand::IsCommandEnabled(const char * aCommandName,
                                   nsISupports *aCommandRefCon,
                                   PRBool *outCmdEnabled)
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   *outCmdEnabled = PR_FALSE;
   // we can delete when we can cut
-  if (!editor)
-    return NS_OK;
+  NS_ENSURE_TRUE(editor, NS_OK);
     
   if (!nsCRT::strcmp(aCommandName,"cmd_delete"))
     return editor->CanCut(outCmdEnabled);
   else if (!nsCRT::strcmp(aCommandName,"cmd_deleteCharBackward"))
     *outCmdEnabled = PR_TRUE;
   else if (!nsCRT::strcmp(aCommandName,"cmd_deleteCharForward"))
     *outCmdEnabled = PR_TRUE;
   else if (!nsCRT::strcmp(aCommandName,"cmd_deleteWordBackward"))
@@ -573,18 +565,17 @@ nsDeleteCommand::IsCommandEnabled(const 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsDeleteCommand::DoCommand(const char *aCommandName, nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
     
   nsIEditor::EDirection deleteDir = nsIEditor::eNone;
   
   if (!nsCRT::strcmp("cmd_delete",aCommandName))
     deleteDir = nsIEditor::ePrevious;
   else if (!nsCRT::strcmp("cmd_deleteCharBackward",aCommandName))
     deleteDir = nsIEditor::ePrevious;
   else if (!nsCRT::strcmp("cmd_deleteCharForward",aCommandName))
@@ -668,37 +659,34 @@ nsSelectAllCommand::GetCommandStateParam
 NS_IMETHODIMP
 nsSelectionMoveCommands::IsCommandEnabled(const char * aCommandName,
                                           nsISupports *aCommandRefCon,
                                           PRBool *outCmdEnabled)
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   *outCmdEnabled = (editor != nsnull);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsSelectionMoveCommands::DoCommand(const char *aCommandName,
                                    nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
-  if (!editor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsISelectionController> selCont;
   nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont)); 
   if (NS_FAILED(rv))
     return rv;
-  if (!selCont)
-    return NS_ERROR_FAILURE;
+  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);
 
   // complete move commands
@@ -823,18 +811,17 @@ nsInsertPlaintextCommand::DoCommand(cons
 NS_IMETHODIMP
 nsInsertPlaintextCommand::DoCommandParams(const char *aCommandName,
                                           nsICommandParams *aParams,
                                           nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(aParams);
 
   nsCOMPtr<nsIPlaintextEditor> editor = do_QueryInterface(refCon);
-  if (!editor)
-    return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
 
   // Get text to insert from command params
   nsAutoString text;
   nsresult rv = aParams->GetStringValue(STATE_DATA, text);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!text.IsEmpty())
     return editor->InsertText(text);
--- a/editor/libeditor/base/nsEditorEventListener.cpp
+++ b/editor/libeditor/base/nsEditorEventListener.cpp
@@ -355,18 +355,17 @@ nsEditorEventListener::MouseClick(nsIDOM
   if (!mouseEvent || !nsevent ||
       NS_FAILED(nsevent->GetIsTrusted(&isTrusted)) || !isTrusted) {
     // Non-ui or non-trusted event passed in. Bad things.
     return NS_OK;
   }
 
   nsresult rv;
   nsCOMPtr<nsIDOMNSUIEvent> nsuiEvent = do_QueryInterface(aMouseEvent);
-  if (!nsuiEvent)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nsuiEvent, NS_ERROR_NULL_POINTER);
 
   PRBool preventDefault;
   rv = nsuiEvent->GetPreventDefault(&preventDefault);
   if (NS_FAILED(rv) || preventDefault)
   {
     // We're done if 'preventdefault' is true (see for example bug 70698).
     return rv;
   }
@@ -519,18 +518,17 @@ nsEditorEventListener::DragGesture(nsIDO
 
   return rv;
 }
 
 nsresult
 nsEditorEventListener::DragEnter(nsIDOMDragEvent* aDragEvent)
 {
   nsCOMPtr<nsIPresShell> presShell = GetPresShell();
-  if (!presShell)
-    return NS_OK;
+  NS_ENSURE_TRUE(presShell, NS_OK);
 
   if (!mCaret)
   {
     NS_NewCaret(getter_AddRefs(mCaret));
     if (mCaret)
     {
       mCaret->Init(presShell);
       mCaret->SetCaretReadOnly(PR_TRUE);
@@ -551,18 +549,17 @@ nsEditorEventListener::DragOver(nsIDOMDr
   if (nsuiEvent) {
     PRBool defaultPrevented;
     nsuiEvent->GetPreventDefault(&defaultPrevented);
     if (defaultPrevented)
       return NS_OK;
 
     nsuiEvent->GetRangeParent(getter_AddRefs(parent));
     nsCOMPtr<nsIContent> dropParent = do_QueryInterface(parent);
-    if (!dropParent)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(dropParent, NS_ERROR_FAILURE);
 
     if (!dropParent->IsEditable())
       return NS_OK;
   }
 
   PRBool canDrop = CanDrop(aDragEvent);
   if (canDrop)
   {
@@ -635,18 +632,17 @@ nsEditorEventListener::Drop(nsIDOMDragEv
     PRBool defaultPrevented;
     nsuiEvent->GetPreventDefault(&defaultPrevented);
     if (defaultPrevented)
       return NS_OK;
 
     nsCOMPtr<nsIDOMNode> parent;
     nsuiEvent->GetRangeParent(getter_AddRefs(parent));
     nsCOMPtr<nsIContent> dropParent = do_QueryInterface(parent);
-    if (!dropParent)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(dropParent, NS_ERROR_FAILURE);
 
     if (!dropParent->IsEditable())
       return NS_OK;
   }
 
   PRBool canDrop = CanDrop(aMouseEvent);
   if (!canDrop)
   {
@@ -674,52 +670,47 @@ nsEditorEventListener::CanDrop(nsIDOMDra
 {
   // if the target doc is read-only, we can't drop
   if (mEditor->IsReadonly() || mEditor->IsDisabled()) {
     return PR_FALSE;
   }
 
   nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
   aEvent->GetDataTransfer(getter_AddRefs(dataTransfer));
-  if (!dataTransfer)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(dataTransfer, PR_FALSE);
 
   nsCOMPtr<nsIDOMDOMStringList> types;
   dataTransfer->GetTypes(getter_AddRefs(types));
-  if (!types)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(types, PR_FALSE);
 
   // Plaintext editors only support dropping text. Otherwise, HTML and files
   // can be dropped as well.
   PRBool typeSupported;
   types->Contains(NS_LITERAL_STRING(kTextMime), &typeSupported);
   if (!typeSupported) {
     types->Contains(NS_LITERAL_STRING(kMozTextInternal), &typeSupported);
     if (!typeSupported && !mEditor->IsPlaintextEditor()) {
       types->Contains(NS_LITERAL_STRING(kHTMLMime), &typeSupported);
       if (!typeSupported) {
         types->Contains(NS_LITERAL_STRING(kFileMime), &typeSupported);
       }
     }
   }
 
-  if (!typeSupported)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(typeSupported, PR_FALSE);
 
   nsCOMPtr<nsIDOMNSDataTransfer> dataTransferNS(do_QueryInterface(dataTransfer));
-  if (!dataTransferNS)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(dataTransferNS, PR_FALSE);
 
   // If there is no source node, this is probably an external drag and the
   // drop is allowed. The later checks rely on checking if the drag target
   // is the same as the drag source.
   nsCOMPtr<nsIDOMNode> sourceNode;
   dataTransferNS->GetMozSourceNode(getter_AddRefs(sourceNode));
-  if (!sourceNode)
-    return PR_TRUE;
+  NS_ENSURE_TRUE(sourceNode, PR_TRUE);
 
   // There is a source node, so compare the source documents and this document.
   // Disallow drops on the same document.
 
   nsCOMPtr<nsIDOMDocument> domdoc;
   nsresult rv = mEditor->GetDocument(getter_AddRefs(domdoc));
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
 
--- a/editor/libeditor/base/nsEditorUtils.cpp
+++ b/editor/libeditor/base/nsEditorUtils.cpp
@@ -143,18 +143,17 @@ nsDOMIterator::AppendList(nsBoolDomIterF
                           nsCOMArray<nsIDOMNode>& arrayOfNodes) const
 {
   nsCOMPtr<nsIDOMNode> node;
   
   // iterate through dom and build list
   while (!mIter->IsDone())
   {
     node = do_QueryInterface(mIter->GetCurrentNode());
-    if (!node)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     if (functor(node))
     {
       arrayOfNodes.AppendObject(node);
     }
     mIter->Next();
   }
   return NS_OK;
@@ -254,31 +253,29 @@ nsEditorHookUtils::GetHookEnumeratorFrom
 }
 
 PRBool
 nsEditorHookUtils::DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aDropEvent,  
                                    nsITransferable *aTrans)
 {
   nsCOMPtr<nsISimpleEnumerator> enumerator;
   GetHookEnumeratorFromDocument(aDoc, getter_AddRefs(enumerator));
-  if (!enumerator)
-    return PR_TRUE;
+  NS_ENSURE_TRUE(enumerator, PR_TRUE);
 
   PRBool hasMoreHooks = PR_FALSE;
   while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreHooks)) && hasMoreHooks)
   {
     nsCOMPtr<nsISupports> isupp;
     if (NS_FAILED(enumerator->GetNext(getter_AddRefs(isupp))))
       break;
 
     nsCOMPtr<nsIClipboardDragDropHooks> override = do_QueryInterface(isupp);
     if (override)
     {
       PRBool doInsert = PR_TRUE;
       nsresult hookResult = override->OnPasteOrDrop(aDropEvent, aTrans, &doInsert);
       NS_ASSERTION(NS_SUCCEEDED(hookResult), "hook failure in OnPasteOrDrop");
-      if (!doInsert)
-        return PR_FALSE;
+      NS_ENSURE_TRUE(doInsert, PR_FALSE);
     }
   }
 
   return PR_TRUE;
 }
--- a/editor/libeditor/base/nsStyleSheetTxns.cpp
+++ b/editor/libeditor/base/nsStyleSheetTxns.cpp
@@ -89,41 +89,38 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn)
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMETHODIMP
 AddStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
 {
-  if (!aEditor || !aSheet)
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
 
   mEditor = aEditor;
   mSheet = aSheet;
   
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 AddStyleSheetTxn::DoTransaction()
 {
-  if (!mEditor || !mSheet)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
   
   AddStyleSheet(mEditor, mSheet);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 AddStyleSheetTxn::UndoTransaction()
 {
-  if (!mEditor || !mSheet)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
   
   RemoveStyleSheet(mEditor, mSheet);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 AddStyleSheetTxn::GetTxnDescription(nsAString& aString)
 {
@@ -153,41 +150,38 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn)
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMETHODIMP
 RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
 {
-  if (!aEditor || !aSheet)
-    return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
 
   mEditor = aEditor;
   mSheet = aSheet;
 
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 RemoveStyleSheetTxn::DoTransaction()
 {
-  if (!mEditor || !mSheet)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
 
   RemoveStyleSheet(mEditor, mSheet);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 RemoveStyleSheetTxn::UndoTransaction()
 {
-  if (!mEditor || !mSheet)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
 
   AddStyleSheet(mEditor, mSheet);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 RemoveStyleSheetTxn::GetTxnDescription(nsAString& aString)
 {
--- a/editor/libeditor/html/TextEditorTest.cpp
+++ b/editor/libeditor/html/TextEditorTest.cpp
@@ -71,18 +71,17 @@ void TextEditorTest::Run(nsIEditor *aEdi
   mEditor = do_QueryInterface(aEditor);
   RunUnitTest(outNumTests, outNumTestsFailed);
 }
 
 nsresult TextEditorTest::RunUnitTest(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
 {
   nsresult result;
   
-  if (!outNumTests || !outNumTestsFailed)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
   
   *outNumTests = 0;
   *outNumTestsFailed = 0;
   
   result = InitDoc();
   TEST_RESULT(result);
   // shouldn't we just bail on error here?
   
@@ -183,18 +182,17 @@ nsresult TextEditorTest::TestTextPropert
   nsCOMPtr<nsIDOMCharacterData>textData;
   textData = do_QueryInterface(textNode);
   PRUint32 length;
   textData->GetLength(&length);
   selection->Collapse(textNode, 0);
   selection->Extend(textNode, length);
 
   nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mTextEditor));
-  if (!htmlEditor)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   PRBool any = PR_FALSE;
   PRBool all = PR_FALSE;
   PRBool first=PR_FALSE;
 
   const nsAFlatString& empty = EmptyString();
 
   result = htmlEditor->GetInlineProperty(nsEditProperty::b, empty, empty, &first, &any, &all);
--- a/editor/libeditor/html/nsEditorTxnLog.cpp
+++ b/editor/libeditor/html/nsEditorTxnLog.cpp
@@ -357,18 +357,17 @@ nsEditorTxnLog::PrintIndent(PRInt32 aInd
     Write("  ");
 
   return NS_OK;
 }
 
 nsresult
 nsEditorTxnLog::Write(const char *aBuffer)
 {
-  if (!aBuffer)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBuffer, NS_ERROR_NULL_POINTER);
 
   if (mEditorLog)
     mEditorLog->Write(aBuffer);
   else
   {
     PRInt32 len = strlen(aBuffer);
     if (len > 0)
       fwrite(aBuffer, 1, len, stdout);
--- a/editor/libeditor/html/nsHTMLAbsPosition.cpp
+++ b/editor/libeditor/html/nsHTMLAbsPosition.cpp
@@ -262,18 +262,17 @@ nsHTMLEditor::CreateGrabber(nsIDOMNode *
 {
   // let's create a grabber through the element factory
   nsresult res = CreateAnonymousElement(NS_LITERAL_STRING("span"),
                                         aParentNode,
                                         NS_LITERAL_STRING("mozGrabber"),
                                         PR_FALSE,
                                         aReturn);
 
-  if (!*aReturn)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(*aReturn, NS_ERROR_FAILURE);
 
   // add the mouse listener so we can detect a click on a resizer
   nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(*aReturn));
   evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
                               mEventListener, PR_FALSE);
 
   return res;
 }
--- a/editor/libeditor/html/nsHTMLAnonymousUtils.cpp
+++ b/editor/libeditor/html/nsHTMLAnonymousUtils.cpp
@@ -142,18 +142,17 @@ nsHTMLEditor::CreateAnonymousElement(con
                                      const nsAString & aAnonClass, PRBool aIsCreatedHidden,
                                      nsIDOMElement ** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aParentNode);
   NS_ENSURE_ARG_POINTER(aReturn);
   *aReturn = nsnull;
 
   nsCOMPtr<nsIContent> parentContent( do_QueryInterface(aParentNode) );
-  if (!parentContent)
-    return NS_OK;
+  NS_ENSURE_TRUE(parentContent, NS_OK);
 
   // Get the document
   nsCOMPtr<nsIDOMDocument> domDoc;
   GetDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
   NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
 
   // Get the pres shell
@@ -161,18 +160,17 @@ nsHTMLEditor::CreateAnonymousElement(con
   NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   // Create a new node through the element factory
   nsCOMPtr<nsIContent> newContent;
   nsresult res = CreateHTMLContent(aTag, getter_AddRefs(newContent));
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newContent);
-  if (!newElement)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(newElement, NS_ERROR_FAILURE);
 
   // add the "hidden" class if needed
   if (aIsCreatedHidden) {
     res = newElement->SetAttribute(NS_LITERAL_STRING("class"),
                                    NS_LITERAL_STRING("hidden"));
     NS_ENSURE_SUCCESS(res, res);
   }
 
@@ -274,20 +272,19 @@ nsHTMLEditor::DeleteRefToAnonymousNode(n
 // handles, a grabber and/or inline table editing UI need to be displayed
 // or refreshed
 NS_IMETHODIMP
 nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection)
 {
   NS_ENSURE_ARG_POINTER(aSelection);
 
   // early way out if all contextual UI extensions are disabled
-  if (!mIsObjectResizingEnabled &&
-      !mIsAbsolutelyPositioningEnabled &&
-      !mIsInlineTableEditingEnabled)
-    return NS_OK;
+  NS_ENSURE_TRUE(mIsObjectResizingEnabled ||
+      mIsAbsolutelyPositioningEnabled ||
+      mIsInlineTableEditingEnabled, NS_OK);
 
   // Don't change selection state if we're moving.
   if (mIsMoving) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMElement> focusElement;
   // let's get the containing element of the selection
--- a/editor/libeditor/html/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp
@@ -514,22 +514,20 @@ nsHTMLCSSUtils::RemoveCSSProperty(nsIDOM
 
 nsresult 
 nsHTMLCSSUtils::CreateCSSPropertyTxn(nsIDOMElement *aElement, 
                                      nsIAtom * aAttribute,
                                      const nsAString& aValue,
                                      ChangeCSSInlineStyleTxn ** aTxn,
                                      PRBool aRemoveProperty)
 {
-  if (!aElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   *aTxn = new ChangeCSSInlineStyleTxn();
-  if (!*aTxn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
   return (*aTxn)->Init(mHTMLEditor, aElement, aAttribute, aValue, aRemoveProperty);
 }
 
 nsresult
 nsHTMLCSSUtils::GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
                                      nsAString & aValue)
 {
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -203,34 +203,31 @@ NS_IMETHODIMP nsHTMLEditor::LoadHTML(con
       res = DeleteSelection(eNone);
       NS_ENSURE_SUCCESS(res, res);
     }
 
     // Get the first range in the selection, for context:
     nsCOMPtr<nsIDOMRange> range;
     res = selection->GetRangeAt(0, getter_AddRefs(range));
     NS_ENSURE_SUCCESS(res, res);
-    if (!range)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range));
-    if (!nsrange)
-      return NS_ERROR_NO_INTERFACE;
+    NS_ENSURE_TRUE(nsrange, NS_ERROR_NO_INTERFACE);
 
     // create fragment for pasted html
     nsCOMPtr<nsIDOMDocumentFragment> docfrag;
     {
       res = nsrange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
       NS_ENSURE_SUCCESS(res, res);
     }
     // put the fragment into the document
     nsCOMPtr<nsIDOMNode> parent, junk;
     res = range->GetStartContainer(getter_AddRefs(parent));
     NS_ENSURE_SUCCESS(res, res);
-    if (!parent)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
     PRInt32 childOffset;
     res = range->GetStartOffset(&childOffset);
     NS_ENSURE_SUCCESS(res, res);
 
     nsCOMPtr<nsIDOMNode> nodeToInsert;
     docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
     while (nodeToInsert)
     {
@@ -312,18 +309,17 @@ nsHTMLEditor::InsertHTMLWithContext(cons
                                 (nsIDOMNode **)address_of(streamStartParent), 
                                 &streamStartOffset,
                                 (nsIDOMNode **)address_of(streamEndParent),
                                 &streamEndOffset, 
                                 (nsIDOMNode **)address_of(targetNode), 
                                 &targetOffset, &doContinue);
 
   NS_ENSURE_SUCCESS(res, res);
-  if (!doContinue)
-    return NS_OK;
+  NS_ENSURE_TRUE(doContinue, NS_OK);
 
   // if we have a destination / target node, we want to insert there
   // rather than in place of the selection
   // ignore aDeleteSelection here if no aDestNode since deletion will
   // also occur later; this block is intended to cover the various
   // scenarios where we are dropping in an editor (and may want to delete
   // the selection before collapsing the selection in the new destination)
   if (aDestNode)
@@ -964,34 +960,32 @@ nsHTMLEditor::RelativizeURIInFragmentLis
   }
 
   return NS_OK;
 }
 
 nsresult
 nsHTMLEditor::AddInsertionListener(nsIContentFilter *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   // don't let a listener be added more than once
   if (mContentFilters.IndexOfObject(aListener) == -1)
   {
     if (!mContentFilters.AppendObject(aListener))
       return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
  
 nsresult
 nsHTMLEditor::RemoveInsertionListener(nsIContentFilter *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE);
 
   if (!mContentFilters.RemoveObject(aListener))
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
  
 nsresult
@@ -1023,18 +1017,17 @@ nsHTMLEditor::DoContentFilterCallback(co
   }
 
   return NS_OK;
 }
 
 PRBool
 nsHTMLEditor::IsInLink(nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *outLink)
 {
-  if (!aNode) 
-    return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   if (outLink)
     *outLink = nsnull;
   nsCOMPtr<nsIDOMNode> tmp, node = aNode;
   while (node)
   {
     if (nsHTMLEditUtils::IsLink(node)) 
     {
       if (outLink)
@@ -2529,18 +2522,17 @@ void RemoveBodyAndHead(nsIDOMNode *aNode
  * *aResult must be NULL.
  *
  * The target for a paste is found by either finding the node that contains
  * the magical comment node containing kInsertCookie or, failing that, the
  * firstChild of the firstChild (until we reach a leaf).
  */
 nsresult FindTargetNode(nsIDOMNode *aStart, nsCOMPtr<nsIDOMNode> &aResult)
 {
-  if (!aStart)
-    return NS_OK;
+  NS_ENSURE_TRUE(aStart, NS_OK);
 
   nsCOMPtr<nsIDOMNode> child, tmp;
 
   nsresult rv = aStart->GetFirstChild(getter_AddRefs(child));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!child)
   {
@@ -2595,18 +2587,17 @@ nsresult nsHTMLEditor::CreateDOMFragment
                                                   const nsAString & aContextStr,
                                                   const nsAString & aInfoStr,
                                                   nsCOMPtr<nsIDOMNode> *outFragNode,
                                                   nsCOMPtr<nsIDOMNode> *outStartNode,
                                                   nsCOMPtr<nsIDOMNode> *outEndNode,
                                                   PRInt32 *outStartOffset,
                                                   PRInt32 *outEndOffset)
 {
-  if (!outFragNode || !outStartNode || !outEndNode) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outFragNode && outStartNode && outEndNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMDocumentFragment> docfrag;
   nsCOMPtr<nsIDOMNode> contextAsNode, tmp;  
   nsresult res = NS_OK;
 
   nsCOMPtr<nsIDOMDocument> domDoc;
   GetDocument(getter_AddRefs(domDoc));
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
@@ -2672,27 +2663,25 @@ nsresult nsHTMLEditor::CreateDOMFragment
     numstr1 = Substring(aInfoStr, 0, sep);
     numstr2 = Substring(aInfoStr, sep+1, aInfoStr.Length() - (sep+1));
 
     // Move the start and end children.
     num = numstr1.ToInteger(&err);
     while (num--)
     {
       (*outStartNode)->GetFirstChild(getter_AddRefs(tmp));
-      if (!tmp)
-        return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
       tmp.swap(*outStartNode);
     }
 
     num = numstr2.ToInteger(&err);
     while (num--)
     {
       (*outEndNode)->GetLastChild(getter_AddRefs(tmp));
-      if (!tmp)
-        return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
       tmp.swap(*outEndNode);
     }
   }
 
   GetLengthOfDOMNode(*outEndNode, (PRUint32&)*outEndOffset);
   return res;
 }
 
@@ -2781,18 +2770,17 @@ nsresult nsHTMLEditor::CreateTagStack(ns
 
 nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode  *aFragmentAsNode,
                                                 nsCOMArray<nsIDOMNode>& outNodeList,
                                                 nsIDOMNode *aStartNode,
                                                 PRInt32 aStartOffset,
                                                 nsIDOMNode *aEndNode,
                                                 PRInt32 aEndOffset)
 {
-  if (!aFragmentAsNode) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aFragmentAsNode, NS_ERROR_NULL_POINTER);
 
   nsresult res;
 
   // if no info was provided about the boundary between context and stream,
   // then assume all is stream.
   if (!aStartNode)
   {
     PRInt32 fragLen;
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -582,18 +582,17 @@ nsHTMLEditRules::AfterEditInner(PRInt32 
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::WillDoAction(nsISelection *aSelection, 
                               nsRulesInfo *aInfo, 
                               PRBool *aCancel, 
                               PRBool *aHandled)
 {
-  if (!aInfo || !aCancel || !aHandled) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aInfo && aCancel && aHandled, NS_ERROR_NULL_POINTER);
 #if defined(DEBUG_ftang)
   printf("nsHTMLEditRules::WillDoAction action = %d\n", aInfo->action);
 #endif
 
   *aCancel = PR_FALSE;
   *aHandled = PR_FALSE;
     
   // my kingdom for dynamic cast
@@ -722,18 +721,17 @@ nsHTMLEditRules::DidDoAction(nsISelectio
   
 /********************************************************
  *  nsIHTMLEditRules methods
  ********************************************************/
 
 NS_IMETHODIMP 
 nsHTMLEditRules::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool *aDL)
 {
-  if (!aMixed || !aOL || !aUL || !aDL)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && aOL && aUL && aDL, NS_ERROR_NULL_POINTER);
   *aMixed = PR_FALSE;
   *aOL = PR_FALSE;
   *aUL = PR_FALSE;
   *aDL = PR_FALSE;
   PRBool bNonList = PR_FALSE;
   
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   nsresult res = GetListActionNodes(arrayOfNodes, PR_FALSE, PR_TRUE);
@@ -774,18 +772,17 @@ nsHTMLEditRules::GetListState(PRBool *aM
   if ( (*aUL + *aOL + *aDL + bNonList) > 1) *aMixed = PR_TRUE;
   
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditRules::GetListItemState(PRBool *aMixed, PRBool *aLI, PRBool *aDT, PRBool *aDD)
 {
-  if (!aMixed || !aLI || !aDT || !aDD)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && aLI && aDT && aDD, NS_ERROR_NULL_POINTER);
   *aMixed = PR_FALSE;
   *aLI = PR_FALSE;
   *aDT = PR_FALSE;
   *aDD = PR_FALSE;
   PRBool bNonList = PR_FALSE;
   
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   nsresult res = GetListActionNodes(arrayOfNodes, PR_FALSE, PR_TRUE);
@@ -837,31 +834,29 @@ nsHTMLEditRules::GetAlignment(PRBool *aM
   // if it's mixed.  This is for efficiency
   // given that our current ui doesn't care if it's mixed.
   // cmanske: NOT TRUE! We would like to pay attention to mixed state
   //  in Format | Align submenu!
 
   // this routine assumes that alignment is done ONLY via divs
 
   // default alignment is left
-  if (!aMixed || !aAlign)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && aAlign, NS_ERROR_NULL_POINTER);
   *aMixed = PR_FALSE;
   *aAlign = nsIHTMLEditor::eLeft;
 
   // get selection
   nsCOMPtr<nsISelection>selection;
   nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
 
   // get selection location
   nsCOMPtr<nsIDOMNode> parent;
   nsIDOMElement *rootElem = mHTMLEditor->GetRoot();
-  if (!rootElem)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(rootElem, NS_ERROR_FAILURE);
 
   PRInt32 offset, rootOffset;
   res = nsEditor::GetNodeLocation(rootElem, address_of(parent), &rootOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
 
   // is the selection collapsed?
@@ -1000,28 +995,26 @@ nsIAtom* MarginPropertyAtomForIndent(nsH
   aHTMLCSSUtils->GetComputedProperty(aNode, nsEditProperty::cssDirection, direction);
   return direction.EqualsLiteral("rtl") ?
     nsEditProperty::cssMarginRight : nsEditProperty::cssMarginLeft;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent)
 {
-  if (!aCanIndent || !aCanOutdent)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aCanIndent && aCanOutdent, NS_ERROR_FAILURE);
   *aCanIndent = PR_TRUE;    
   *aCanOutdent = PR_FALSE;
 
   // get selection
   nsCOMPtr<nsISelection>selection;
   nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
-  if (!selPriv)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selPriv, NS_ERROR_FAILURE);
 
   // contruct a list of nodes to act on.
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   res = GetNodesFromSelection(selection, kIndent, arrayOfNodes, PR_TRUE);
   NS_ENSURE_SUCCESS(res, res);
 
   // examine nodes in selection for blockquotes or list elements;
   // these we can outdent.  Note that we return true for canOutdent
@@ -1107,18 +1100,17 @@ nsHTMLEditRules::GetIndentState(PRBool *
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat)
 {
   // This routine is *heavily* tied to our ui choices in the paragraph
   // style popup.  I can't see a way around that.
-  if (!aMixed)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
   *aMixed = PR_TRUE;
   outFormat.Truncate(0);
   
   PRBool bMixed = PR_FALSE;
   // using "x" as an uninitialized value, since "" is meaningful
   nsAutoString formatStr(NS_LITERAL_STRING("x")); 
   
   nsCOMArray<nsIDOMNode> arrayOfNodes;
@@ -1785,18 +1777,17 @@ nsHTMLEditRules::DidInsertBreak(nsISelec
 {
   return NS_OK;
 }
 
 
 nsresult
 nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRBool *aHandled)
 {
-  if (!aSelection || !aHandled)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection && aHandled, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(aSelection));
   nsCOMPtr<nsIDOMNode> citeNode, selNode, leftCite, rightCite;
   PRInt32 selOffset, newOffset;
   nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = GetTopEnclosingMailCite(selNode, address_of(citeNode), aPlaintext);
   NS_ENSURE_SUCCESS(res, res);
   if (citeNode)
@@ -2247,18 +2238,17 @@ nsHTMLEditRules::WillDeleteSelection(nsI
       else
         leftParent = mHTMLEditor->GetBlockNodeParent(leftNode);
       if (IsBlockNode(rightNode))
         rightParent = rightNode;
       else
         rightParent = mHTMLEditor->GetBlockNodeParent(rightNode);
       
       // sanity checks
-      if (!leftParent || !rightParent)
-        return NS_ERROR_NULL_POINTER;  
+      NS_ENSURE_TRUE(leftParent && rightParent, NS_ERROR_NULL_POINTER);  
       if (leftParent == rightParent)
         return NS_ERROR_UNEXPECTED;  
       
       // now join them
       nsCOMPtr<nsIDOMNode> selPointNode = startNode;
       PRInt32 selPointOffset = startOffset;
       {
         nsAutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater, address_of(selPointNode), &selPointOffset);
@@ -2313,18 +2303,17 @@ nsHTMLEditRules::WillDeleteSelection(nsI
       else
         leftParent = mHTMLEditor->GetBlockNodeParent(leftNode);
       if (IsBlockNode(rightNode))
         rightParent = rightNode;
       else
         rightParent = mHTMLEditor->GetBlockNodeParent(rightNode);
       
       // sanity checks
-      if (!leftParent || !rightParent)
-        return NS_ERROR_NULL_POINTER;  
+      NS_ENSURE_TRUE(leftParent && rightParent, NS_ERROR_NULL_POINTER);  
       if (leftParent == rightParent)
         return NS_ERROR_UNEXPECTED;  
       
       // now join them
       nsCOMPtr<nsIDOMNode> selPointNode = startNode;
       PRInt32 selPointOffset = startOffset;
       {
         nsAutoTrackDOMPoint tracker(mHTMLEditor->mRangeUpdater, address_of(selPointNode), &selPointOffset);
@@ -2570,18 +2559,17 @@ nsHTMLEditRules::WillDeleteSelection(nsI
 /*****************************************************************************************************
 *    InsertBRIfNeeded: determines if a br is needed for current selection to not be spastic.
 *    If so, it inserts one.  Callers responsibility to only call with collapsed selection.
 *         nsISelection *aSelection      the collapsed selection 
 */
 nsresult
 nsHTMLEditRules::InsertBRIfNeeded(nsISelection *aSelection)
 {
-  if (!aSelection)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   
   // get selection  
   nsCOMPtr<nsIDOMNode> node;
   PRInt32 offset;
   nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
@@ -2608,18 +2596,17 @@ nsHTMLEditRules::InsertBRIfNeeded(nsISel
 *         nsIEditor::EDirection aAction      which edge to find: eNext indicates beginning, ePrevious ending
 *         nsCOMPtr<nsIDOMNode> *outSelNode   desired sel node
 *         PRInt32 *outSelOffset              desired sel offset
 */
 nsresult
 nsHTMLEditRules::GetGoodSelPointForNode(nsIDOMNode *aNode, nsIEditor::EDirection aAction, 
                                         nsCOMPtr<nsIDOMNode> *outSelNode, PRInt32 *outSelOffset)
 {
-  if (!aNode || !outSelNode || !outSelOffset)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outSelNode && outSelOffset, NS_ERROR_NULL_POINTER);
   
   nsresult res = NS_OK;
   
   // default values
   *outSelNode = aNode;
   *outSelOffset = 0;
   
   if (mHTMLEditor->IsTextNode(aNode) || mHTMLEditor->IsContainer(aNode))
@@ -2747,18 +2734,17 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsI
     res = CheckForInvisibleBR(*aLeftBlock, kBlockEnd, address_of(brNode));
     NS_ENSURE_SUCCESS(res, res);
     if (bMergeLists)
     {
       // idea here is to take all children in  rightList that are past
       // theOffset, and pull them into leftlist.
       nsCOMPtr<nsIDOMNode> childToMove;
       nsCOMPtr<nsIContent> parent(do_QueryInterface(rightList));
-      if (!parent)
-        return NS_ERROR_NULL_POINTER;
+      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;
@@ -4297,18 +4283,17 @@ nsHTMLEditRules::RemovePartOfBlock(nsIDO
 nsresult 
 nsHTMLEditRules::SplitBlock(nsIDOMNode *aBlock, 
                             nsIDOMNode *aStartChild, 
                             nsIDOMNode *aEndChild,
                             nsCOMPtr<nsIDOMNode> *aLeftNode,
                             nsCOMPtr<nsIDOMNode> *aRightNode,
                             nsCOMPtr<nsIDOMNode> *aMiddleNode)
 {
-  if (!aBlock || !aStartChild || !aEndChild)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBlock && aStartChild && aEndChild, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsIDOMNode> startParent, endParent, leftNode, rightNode;
   PRInt32 startOffset, endOffset, offset;
   nsresult res;
 
   // get split point location
   res = nsEditor::GetNodeLocation(aStartChild, address_of(startParent), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -4438,18 +4423,17 @@ nsHTMLEditRules::CreateStyleForInsertTex
   NS_ENSURE_SUCCESS(res, res);
 
   // next examine our present style and make sure default styles are either present or
   // explicitly overridden.  If neither, add the default style to the TypeInState
   PRInt32 j, defcon = mHTMLEditor->mDefaultStyles.Length();
   for (j=0; j<defcon; j++)
   {
     PropItem *propItem = mHTMLEditor->mDefaultStyles[j];
-    if (!propItem) 
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(propItem, NS_ERROR_NULL_POINTER);
     PRBool bFirst, bAny, bAll;
 
     // GetInlineProperty also examine TypeInState.  The only gotcha here is that a cleared
     // property looks like an unset property.  For now I'm assuming that's not a problem:
     // that default styles will always be multivalue styles (like font face or size) where
     // clearing the style means we want to go back to the default.  If we ever wanted a 
     // "toggle" style like bold for a default, though, I'll have to add code to detect the
     // difference between unset and explicitly cleared, else user would never be able to
@@ -5111,18 +5095,17 @@ nsHTMLEditRules::GetInnerContent(nsIDOMN
 
 ///////////////////////////////////////////////////////////////////////////
 // ExpandSelectionForDeletion: this promotes our selection to include blocks
 // that have all their children selected.
 //                  
 PRBool
 nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
 {
-  if (!aSelection) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   
   // don't need to touch collapsed selections
   PRBool bCollapsed;
   nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
   if (bCollapsed) return res;
 
   PRInt32 rangeCount;
@@ -5156,18 +5139,17 @@ nsHTMLEditRules::ExpandSelectionForDelet
     selCommon = nsHTMLEditor::GetBlockNodeParent(selCommon);
 
   // set up for loops and cache our root element
   PRBool stillLooking = PR_TRUE;
   nsCOMPtr<nsIDOMNode> visNode, firstBRParent;
   PRInt32 visOffset=0, firstBROffset=0;
   PRInt16 wsType;
   nsIDOMElement *rootElement = mHTMLEditor->GetRoot();
-  if (!rootElement)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
 
   // find previous visible thingy before start of selection
   if ((selStartNode!=selCommon) && (selStartNode!=rootElement))
   {
     while (stillLooking)
     {
       nsWSRunObject wsObj(mHTMLEditor, selStartNode, selStartOffset);
       res = wsObj.PriorVisibleNode(selStartNode, selStartOffset, address_of(visNode), &visOffset, &wsType);
@@ -6013,18 +5995,17 @@ nsHTMLEditRules::GetListActionNodes(nsCO
                                     PRBool aDontTouchContent)
 {
   nsresult res = NS_OK;
   
   nsCOMPtr<nsISelection>selection;
   res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
-  if (!selPriv)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selPriv, NS_ERROR_FAILURE);
   // added this in so that ui code can ask to change an entire list, even if selection
   // is only in part of it.  used by list item dialog.
   if (aEntireList)
   {       
     nsCOMPtr<nsIEnumerator> enumerator;
     res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
     NS_ENSURE_SUCCESS(res, res);
     NS_ENSURE_TRUE(enumerator, NS_ERROR_UNEXPECTED);
@@ -6646,18 +6627,17 @@ nsHTMLEditRules::ReturnInParagraph(nsISe
       }
     }
     if (!newBRneeded)
       sibling = nearNode;
   }
   if (newBRneeded)
   {
     // if CR does not create a new P, default to BR creation
-    if (!doesCRCreateNewP)
-      return NS_OK;
+    NS_ENSURE_TRUE(doesCRCreateNewP, NS_OK);
 
     nsCOMPtr<nsIDOMNode> brNode;
     res =  mHTMLEditor->CreateBR(parent, offset, address_of(brNode));
     sibling = brNode;
   }
   nsCOMPtr<nsIDOMNode> selNode = aNode;
   *aHandled = PR_TRUE;
   return SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &aOffset);
@@ -6668,18 +6648,17 @@ nsHTMLEditRules::ReturnInParagraph(nsISe
 //                       
 nsresult 
 nsHTMLEditRules::SplitParagraph(nsIDOMNode *aPara,
                                 nsIDOMNode *aBRNode, 
                                 nsISelection *aSelection,
                                 nsCOMPtr<nsIDOMNode> *aSelNode, 
                                 PRInt32 *aOffset)
 {
-  if (!aPara || !aBRNode || !aSelNode || !*aSelNode || !aOffset || !aSelection) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aPara && aBRNode && aSelNode && *aSelNode && aOffset && aSelection, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   
   // split para
   PRInt32 newOffset;
   // get ws code to adjust any ws
   nsCOMPtr<nsIDOMNode> leftPara, rightPara;
   res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, aSelNode, aOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -7282,21 +7261,20 @@ nsHTMLEditRules::SplitAsNeeded(const nsA
 //                  aNodeLeft & aNodeRight must be same type of node.
 nsresult 
 nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft, 
                                  nsIDOMNode *aNodeRight, 
                                  nsCOMPtr<nsIDOMNode> *aOutMergeParent, 
                                  PRInt32 *aOutMergeOffset)
 {
   // check parms
-  if (!aNodeLeft ||  
-      !aNodeRight || 
-      !aOutMergeParent ||
-      !aOutMergeOffset) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNodeLeft &&  
+      aNodeRight && 
+      aOutMergeParent &&
+      aOutMergeOffset, NS_ERROR_NULL_POINTER);
   
   nsresult res = NS_OK;
   // caller responsible for:
   //   left & right node are same type
   PRInt32 parOffset;
   nsCOMPtr<nsIDOMNode> parent, rightParent;
   res = nsEditor::GetNodeLocation(aNodeLeft, address_of(parent), &parOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -7348,18 +7326,17 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMN
 
 
 nsresult 
 nsHTMLEditRules::GetTopEnclosingMailCite(nsIDOMNode *aNode, 
                                          nsCOMPtr<nsIDOMNode> *aOutCiteNode,
                                          PRBool aPlainText)
 {
   // check parms
-  if (!aNode || !aOutCiteNode) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aOutCiteNode, NS_ERROR_NULL_POINTER);
   
   nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> node, parentNode;
   node = do_QueryInterface(aNode);
   
   while (node)
   {
     if ( (aPlainText && nsHTMLEditUtils::IsPre(node)) ||
@@ -7930,18 +7907,17 @@ nsHTMLEditRules::RemoveEmptyNodes()
   nsTArray<nsIDOMNode*> skipList;
 
   // check for empty nodes
   while (!iter->IsDone())
   {
     nsCOMPtr<nsIDOMNode> node, parent;
 
     node = do_QueryInterface(iter->GetCurrentNode());
-    if (!node)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
     node->GetParentNode(getter_AddRefs(parent));
     
     PRUint32 idx = skipList.IndexOf(node);
     if (idx != skipList.NoIndex)
     {
       // this node is on our skip list.  Skip processing for this node, 
       // and replace it's value in the skip list with the value of it's parent
@@ -8160,18 +8136,17 @@ nsHTMLEditRules::ListIsEmptyLine(nsCOMAr
   return PR_TRUE;
 }
 
 
 nsresult 
 nsHTMLEditRules::PopListItem(nsIDOMNode *aListItem, PRBool *aOutOfList)
 {
   // check parms
-  if (!aListItem || !aOutOfList) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListItem && aOutOfList, NS_ERROR_NULL_POINTER);
   
   // init out params
   *aOutOfList = PR_FALSE;
   
   nsCOMPtr<nsIDOMNode> curParent;
   nsCOMPtr<nsIDOMNode> curNode( do_QueryInterface(aListItem));
   PRInt32 offset;
   nsresult res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset);
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -250,18 +250,17 @@ NS_INTERFACE_MAP_END_INHERITING(nsPlaint
 
 
 NS_IMETHODIMP
 nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell,
                    nsIContent *aRoot, nsISelectionController *aSelCon,
                    PRUint32 aFlags)
 {
   NS_PRECONDITION(aDoc && aPresShell, "bad arg");
-  if (!aDoc || !aPresShell)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDoc && aPresShell, NS_ERROR_NULL_POINTER);
 
   nsresult result = NS_OK, rulesRes = NS_OK;
 
   // make a range util object for comparing dom points
   if (!sRangeHelper) {
     result = CallGetService("@mozilla.org/content/range-utils;1",
                             &sRangeHelper);
     NS_ENSURE_TRUE(sRangeHelper, result);
@@ -533,18 +532,17 @@ 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;
-  if (!selection)
-    return NS_ERROR_NOT_INITIALIZED;
+  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;
   nsCOMPtr<nsIDOMNode> curNode(rootElement), selNode;
@@ -919,18 +917,17 @@ nsHTMLEditor::IsBlockNode(nsIDOMNode *aN
   return isBlock;
 }
 
 // Non-static version for the nsIEditor interface and JavaScript
 NS_IMETHODIMP 
 nsHTMLEditor::SetDocumentTitle(const nsAString &aTitle)
 {
   nsRefPtr<SetDocTitleTxn> txn = new SetDocTitleTxn();
-  if (!txn)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
 
   nsresult result = txn->Init(this, &aTitle);
   if (NS_FAILED(result))
     return result;
 
   //Don't let Rules System change the selection
   nsAutoTxnsConserveSelection dontChangeSelection(this);
   return nsEditor::DoTransaction(txn);  
@@ -1322,33 +1319,31 @@ nsHTMLEditor::IsPrevCharWhitespace(nsIDO
 
 
 
 /* ------------ End Block methods -------------- */
 
 
 PRBool nsHTMLEditor::IsVisBreak(nsIDOMNode *aNode)
 {
-  if (!aNode) 
-    return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   if (!nsTextEditUtils::IsBreak(aNode)) 
     return PR_FALSE;
   // check if there is a later node in block after br
   nsCOMPtr<nsIDOMNode> priorNode, nextNode;
   GetPriorHTMLNode(aNode, address_of(priorNode), PR_TRUE); 
   GetNextHTMLNode(aNode, address_of(nextNode), PR_TRUE); 
   // if we are next to another break, we are visible
   if (priorNode && nsTextEditUtils::IsBreak(priorNode))
     return PR_TRUE;
   if (nextNode && nsTextEditUtils::IsBreak(nextNode))
     return PR_TRUE;
   
   // if we are right before block boundary, then br not visible
-  if (!nextNode) 
-    return PR_FALSE;  // this break is trailer in block, it's not visible
+  NS_ENSURE_TRUE(nextNode, PR_FALSE);  // this break is trailer in block, it's not visible
   if (IsBlockNode(nextNode))
     return PR_FALSE; // break is right before a block, it's not visible
     
   // sigh.  We have to use expensive whitespace calculation code to 
   // determine what is going on
   nsCOMPtr<nsIDOMNode> selNode, tmp;
   PRInt32 selOffset;
   GetNodeLocation(aNode, address_of(selNode), &selOffset);
@@ -1752,18 +1747,17 @@ nsHTMLEditor::ReplaceHeadContentsWithHTM
 
   // 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;
 
   nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range));
-  if (!nsrange)
-    return NS_ERROR_NO_INTERFACE;
+  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>
   // Special code is needed in JS to handle title anyway, so it really doesn't matter!
 
   if (NS_FAILED(res))
@@ -2025,18 +2019,17 @@ nsHTMLEditor::NormalizeEOLInsertPosition
 NS_IMETHODIMP
 nsHTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSelection)
 {
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   nsresult res = NS_ERROR_NOT_INITIALIZED;
   
-  if (!aElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
   
   ForceCompositionEnd();
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertElement, nsIEditor::eNext);
 
   nsCOMPtr<nsISelection>selection;
@@ -2364,18 +2357,17 @@ nsHTMLEditor::GetCSSBackgroundColorState
   nsCOMPtr<nsIDOMNode> tmp;
 
   if (aBlockLevel) {
     // we are querying the block background (and not the text background), let's
     // climb to the block container
     nsCOMPtr<nsIDOMNode> blockParent = nodeToExamine;
     if (!isBlock) {
       blockParent = GetBlockNodeParent(nodeToExamine);
-      if (!blockParent)
-        return NS_OK;
+      NS_ENSURE_TRUE(blockParent, NS_OK);
     }
 
     // Make sure to not walk off onto the Document node
     nsCOMPtr<nsIDOMElement> element;
     do {
       // retrieve the computed style of background-color for blockParent
       mHTMLCSSUtils->GetComputedProperty(blockParent,
                                          nsEditProperty::cssBackgroundColor,
@@ -2979,18 +2971,17 @@ NODE_FOUND:
   else res = NS_EDITOR_ELEMENT_NOT_FOUND;
 
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetSelectedElement(const nsAString& aTagName, nsIDOMElement** aReturn)
 {
-  if (!aReturn )
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aReturn , NS_ERROR_NULL_POINTER);
   
   // default is null - no element found
   *aReturn = nsnull;
   
   // First look for a single element in selection
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
@@ -3218,19 +3209,18 @@ nsHTMLEditor::GetSelectedElement(const n
 
 NS_IMETHODIMP
 nsHTMLEditor::CreateElementWithDefaults(const nsAString& aTagName, nsIDOMElement** aReturn)
 {
   nsresult res=NS_ERROR_NOT_INITIALIZED;
   if (aReturn)
     *aReturn = nsnull;
 
-  if (aTagName.IsEmpty() || !aReturn)
-//  if (!aTagName || !aReturn)
-    return NS_ERROR_NULL_POINTER;
+//  NS_ENSURE_TRUE(aTagName && aReturn, NS_ERROR_NULL_POINTER);
+  NS_ENSURE_TRUE(!aTagName.IsEmpty() && aReturn, NS_ERROR_NULL_POINTER);
     
   nsAutoString TagName(aTagName);
   ToLowerCase(TagName);
   nsAutoString realTagName;
 
   if (IsLinkTag(TagName) || IsNamedAnchorTag(TagName))
   {
     realTagName.AssignLiteral("a");
@@ -3324,18 +3314,17 @@ nsHTMLEditor::InsertLinkAroundSelection(
       NS_ENSURE_SUCCESS(res, res);
       if (!href.IsEmpty())      
       {
         nsAutoEditBatch beginBatching(this);
 
         // Set all attributes found on the supplied anchor element
         nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
         aAnchorElement->GetAttributes(getter_AddRefs(attrMap));
-        if (!attrMap)
-          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(attrMap, NS_ERROR_FAILURE);
 
         PRUint32 count, i;
         attrMap->GetLength(&count);
         nsAutoString name, value;
 
         for (i = 0; i < count; i++)
         {
           nsCOMPtr<nsIDOMNode> attrNode;
@@ -3426,48 +3415,44 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttri
 {
   // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level
 
   NS_ASSERTION(mDocWeak, "Missing Editor DOM Document");
   
   // Set the background color attribute on the body tag
   nsIDOMElement *bodyElement = GetRoot();
 
-  if (!bodyElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);
 
   // Use the editor method that goes through the transaction system
   return SetAttribute(bodyElement, aAttribute, aValue);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetLinkedObjects(nsISupportsArray** aNodeList)
 {
-  if (!aNodeList)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNodeList, NS_ERROR_NULL_POINTER);
 
   nsresult res;
 
   res = NS_NewISupportsArray(aNodeList);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(*aNodeList, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIContentIterator> iter =
        do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
   NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
   if ((NS_SUCCEEDED(res)))
   {
     nsCOMPtr<nsIDOMDocument> domdoc;
     nsEditor::GetDocument(getter_AddRefs(domdoc));
-    if (!domdoc)
-      return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(domdoc, NS_ERROR_UNEXPECTED);
 
     nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
-    if (!doc)
-      return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
 
     iter->Init(doc->GetRootElement());
 
     // loop through the content iterator for each content node
     while (!iter->IsDone())
     {
       nsCOMPtr<nsIDOMNode> node (do_QueryInterface(iter->GetCurrentNode()));
       if (node)
@@ -3537,18 +3522,17 @@ nsHTMLEditor::ReplaceStyleSheet(const ns
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::RemoveStyleSheet(const nsAString &aURL)
 {
   nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!sheet)
-    return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(sheet, NS_ERROR_UNEXPECTED);
 
   nsRefPtr<RemoveStyleSheetTxn> txn;
   rv = CreateTxnForRemoveStyleSheet(sheet, getter_AddRefs(txn));
   if (!txn) rv = NS_ERROR_NULL_POINTER;
   if (NS_SUCCEEDED(rv))
   {
     rv = DoTransaction(txn);
     if (NS_SUCCEEDED(rv))
@@ -3566,34 +3550,32 @@ NS_IMETHODIMP
 nsHTMLEditor::AddOverrideStyleSheet(const nsAString& aURL)
 {
   // Enable existing sheet if already loaded.
   if (EnableExistingStyleSheet(aURL))
     return NS_OK;
 
   // Make sure the pres shell doesn't disappear during the load.
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIURI> uaURI;
   nsresult rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We MUST ONLY load synchronous local files (no @import)
   // XXXbz Except this will actually try to load remote files
   // synchronously, of course..
   nsRefPtr<nsCSSStyleSheet> sheet;
   // Editor override style sheets may want to style Gecko anonymous boxes
   rv = ps->GetDocument()->CSSLoader()->
     LoadSheetSync(uaURI, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
 
   // Synchronous loads should ALWAYS return completed
-  if (!sheet)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(sheet, NS_ERROR_NULL_POINTER);
 
   // Add the override style sheet
   // (This checks if already exists)
   ps->AddOverrideStyleSheet(sheet);
 
   ps->ReconstructStyleData();
 
   // Save as the last-loaded sheet
@@ -3628,18 +3610,17 @@ nsHTMLEditor::RemoveOverrideStyleSheet(c
 {
   nsRefPtr<nsCSSStyleSheet> sheet;
   GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
 
   // Make sure we remove the stylesheet from our internal list in all
   // cases.
   nsresult rv = RemoveStyleSheetFromList(aURL);
 
-  if (!sheet)
-    return NS_OK; /// Don't fail if sheet not found
+  NS_ENSURE_TRUE(sheet, NS_OK); /// Don't fail if sheet not found
 
   NS_ENSURE_TRUE(mPresShellWeak, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
   NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   ps->RemoveOverrideStyleSheet(sheet);
   ps->ReconstructStyleData();
 
@@ -3648,18 +3629,17 @@ nsHTMLEditor::RemoveOverrideStyleSheet(c
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::EnableStyleSheet(const nsAString &aURL, PRBool aEnable)
 {
   nsRefPtr<nsCSSStyleSheet> sheet;
   nsresult rv = GetStyleSheetForURL(aURL, getter_AddRefs(sheet));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!sheet)
-    return NS_OK; // Don't fail if sheet not found
+  NS_ENSURE_TRUE(sheet, NS_OK); // Don't fail if sheet not found
 
   // Ensure the style sheet is owned by our document.
   nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
   sheet->SetOwningDocument(doc);
 
   return sheet->SetDisabled(!aEnable);
 }
 
@@ -3725,18 +3705,17 @@ nsHTMLEditor::GetStyleSheetForURL(const 
 
   // is it already in the list?
   PRUint32 foundIndex;
   foundIndex = mStyleSheetURLs.IndexOf(aURL);
   if (foundIndex == mStyleSheetURLs.NoIndex)
     return NS_OK; //No sheet -- don't fail!
 
   *aStyleSheet = mStyleSheets[foundIndex];
-  if (!*aStyleSheet)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(*aStyleSheet, NS_ERROR_FAILURE);
 
   NS_ADDREF(*aStyleSheet);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetURLForStyleSheet(nsCSSStyleSheet *aStyleSheet,
@@ -3758,38 +3737,35 @@ nsHTMLEditor::GetURLForStyleSheet(nsCSSS
 
 /*
  * nsIEditorMailSupport methods
  */
 
 NS_IMETHODIMP
 nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)
 {
-  if (!aNodeList)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNodeList, NS_ERROR_NULL_POINTER);
 
   nsresult res;
 
   res = NS_NewISupportsArray(aNodeList);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(*aNodeList, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIContentIterator> iter =
       do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
   NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
   if ((NS_SUCCEEDED(res)))
   {
     nsCOMPtr<nsIDOMDocument> domdoc;
     nsEditor::GetDocument(getter_AddRefs(domdoc));
-    if (!domdoc)
-      return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(domdoc, NS_ERROR_UNEXPECTED);
 
     nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
-    if (!doc)
-      return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
 
     iter->Init(doc->GetRootElement());
 
     // loop through the content iterator for each content node
     while (!iter->IsDone())
     {
       nsCOMPtr<nsIDOMNode> node (do_QueryInterface(iter->GetCurrentNode()));
       if (node)
@@ -4042,22 +4018,20 @@ nsHTMLEditor::GetHeadContentsAsHTML(nsAS
   }
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::DebugUnitTests(PRInt32 *outNumTests, PRInt32 *outNumTestsFailed)
 {
 #ifdef DEBUG
-  if (!outNumTests || !outNumTestsFailed)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
 
   TextEditorTest *tester = new TextEditorTest();
-  if (!tester)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(tester, NS_ERROR_OUT_OF_MEMORY);
    
   tester->Run(this, outNumTests, outNumTestsFailed);
   delete tester;
   return NS_OK;
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }
@@ -4430,30 +4404,26 @@ nsHTMLEditor::GetEnclosingTable(nsIDOMNo
 #pragma mark -
 #endif
 
 #ifdef PRE_NODE_IN_BODY
 nsCOMPtr<nsIDOMElement> nsHTMLEditor::FindPreElement()
 {
   nsCOMPtr<nsIDOMDocument> domdoc;
   nsEditor::GetDocument(getter_AddRefs(domdoc));
-  if (!domdoc)
-    return 0;
+  NS_ENSURE_TRUE(domdoc, 0);
 
   nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
-  if (!doc)
-    return 0;
+  NS_ENSURE_TRUE(doc, 0);
 
   nsCOMPtr<nsIContent> rootContent = doc->GetRootElement();
-  if (!rootContent)
-    return 0;
+  NS_ENSURE_TRUE(rootContent, 0);
 
   nsCOMPtr<nsIDOMNode> rootNode (do_QueryInterface(rootContent));
-  if (!rootNode)
-    return 0;
+  NS_ENSURE_TRUE(rootNode, 0);
 
   nsString prestr ("PRE");  // GetFirstNodeOfType requires capitals
   nsCOMPtr<nsIDOMNode> preNode;
   if (NS_FAILED(nsEditor::GetFirstNodeOfType(rootNode, prestr,
                                                  getter_AddRefs(preNode))))
     return 0;
 
   return do_QueryInterface(preNode);
@@ -4525,36 +4495,34 @@ nsHTMLEditor::CollapseAdjacentTextNodes(
 
   return result;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::SetSelectionAtDocumentStart(nsISelection *aSelection)
 {
   nsIDOMElement *rootElement = GetRoot();  
-  if (!rootElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
 
   return aSelection->Collapse(rootElement,0);
 }
 
 #ifdef XP_MAC
 #pragma mark -
 #endif
 
 ///////////////////////////////////////////////////////////////////////////
 // RemoveBlockContainer: remove inNode, reparenting it's children into their
 //                  the parent of inNode.  In addition, INSERT ANY BR's NEEDED
 //                  TO PRESERVE IDENTITY OF REMOVED BLOCK.
 //
 nsresult
 nsHTMLEditor::RemoveBlockContainer(nsIDOMNode *inNode)
 {
-  if (!inNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inNode, NS_ERROR_NULL_POINTER);
   nsresult res;
   nsCOMPtr<nsIDOMNode> sibling, child, unused;
   
   // Two possibilities: the container cold be empty of editable content.
   // If that is the case, we need to compare what is before and after inNode
   // to determine if we need a br.
   // Or it could not be empty, in which case we have to compare previous
   // sibling and first child to determine if we need a leading br,
@@ -5005,18 +4973,17 @@ nsHTMLEditor::IsTextInDirtyFrameVisible(
 ///////////////////////////////////////////////////////////////////////////
 // IsVisTextNode: figure out if textnode aTextNode has any visible content.
 //                  
 nsresult
 nsHTMLEditor::IsVisTextNode( nsIDOMNode *aNode, 
                              PRBool *outIsEmptyNode, 
                              PRBool aSafeToAskFrames)
 {
-  if (!aNode || !outIsEmptyNode) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outIsEmptyNode, NS_ERROR_NULL_POINTER);
   *outIsEmptyNode = PR_TRUE;
   nsresult res = NS_OK;
 
   nsCOMPtr<nsIContent> textContent = do_QueryInterface(aNode);
   // callers job to only call us with text nodes
   if (!textContent || !textContent->IsNodeOfType(nsINode::eTEXT)) 
     return NS_ERROR_NULL_POINTER;
   PRUint32 length = textContent->TextLength();
@@ -5439,18 +5406,17 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
         // this can easily happen with the subtree 
         // iterator if the selection doesn't contain
         // any *whole* nodes.
         if (NS_SUCCEEDED(res))
         {
           while (!iter->IsDone())
           {
             node = do_QueryInterface(iter->GetCurrentNode());
-            if (!node)
-              return NS_ERROR_FAILURE;
+            NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
             if (IsEditable(node))
             {
               arrayOfNodes.AppendObject(node);
             }
 
             iter->Next();
           }
--- a/editor/libeditor/html/nsHTMLEditorLog.cpp
+++ b/editor/libeditor/html/nsHTMLEditorLog.cpp
@@ -666,18 +666,17 @@ nsHTMLEditorLog:: SplitTableCell()
 NS_IMETHODIMP
 nsHTMLEditorLog:: NormalizeTable(nsIDOMElement *aTable)
 {
   nsAutoHTMLEditorLogLock logLock(this);
 
   if (!mLocked && mFileStream)
   {
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aTable);
-    if (!node)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     PrintNode(node, 0);
     Write("GetCurrentEditor().normalizeTable(n0);\n");
     Flush();
   }
 
   return nsHTMLEditor::NormalizeTable(aTable);
 }
@@ -685,18 +684,17 @@ nsHTMLEditorLog:: NormalizeTable(nsIDOME
 NS_IMETHODIMP
 nsHTMLEditorLog::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell)
 {
   nsAutoHTMLEditorLogLock logLock(this);
 
   if (!mLocked && mFileStream)
   {
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aSourceCell);
-    if (!node)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     PrintNode(node, 0);
     Write("GetCurrentEditor().switchTableCellHeaderType(n0);\n");
     Flush();
   }
 
   return nsHTMLEditor::SwitchTableCellHeaderType(aSourceCell, aNewCell);
 }
@@ -761,23 +759,21 @@ nsHTMLEditorLog::Align(const nsAString& 
 
 NS_IMETHODIMP
 nsHTMLEditorLog::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSelection)
 {
   nsAutoHTMLEditorLogLock logLock(this);
 
   if (!mLocked && mFileStream)
   {
-    if (!aElement)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
 
-    if (!node)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     PrintSelection();
     PrintNode(node, 0);
     Write("GetCurrentEditor().insertElementAtSelection(n0, ");
     Write(aDeleteSelection ? "true" : "false");
     Write(");\n");
     Flush();
   }
@@ -787,23 +783,21 @@ nsHTMLEditorLog::InsertElementAtSelectio
 
 NS_IMETHODIMP
 nsHTMLEditorLog::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
 {
   nsAutoHTMLEditorLogLock logLock(this);
 
   if (!mLocked && mFileStream)
   {
-    if (!aAnchorElement)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(aAnchorElement, NS_ERROR_NULL_POINTER);
 
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aAnchorElement);
 
-    if (!node)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
     PrintSelection();
     PrintNode(node, 0);
     Write("GetCurrentEditor().insertLinkAroundSelection(n0);\n");
     Flush();
   }
 
   return nsHTMLEditor::InsertLinkAroundSelection(aAnchorElement);
@@ -828,18 +822,17 @@ nsHTMLEditorLog::SetDocumentTitle(const 
   return nsHTMLEditor::SetDocumentTitle(aTitle);
 }
 
 NS_IMETHODIMP
 nsHTMLEditorLog::StartLogging(nsIFile *aLogFile)
 {
   nsresult result = NS_ERROR_FAILURE;
 
-  if (!aLogFile)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aLogFile, NS_ERROR_NULL_POINTER);
 
   if (mFileStream)
   {
     result = StopLogging();
 
     if (NS_FAILED(result))
       return result;
   }
@@ -885,18 +878,17 @@ nsHTMLEditorLog::StopLogging()
 }
 
 
 nsresult
 nsHTMLEditorLog::Write(const char *aBuffer)
 {
   nsresult result;
 
-  if (!aBuffer)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBuffer, NS_ERROR_NULL_POINTER);
 
   PRInt32 len = strlen(aBuffer);
 
   if (mFileStream)
   {
     PRUint32 retval;
 
     result = mFileStream->Write(aBuffer, len, &retval);
@@ -999,31 +991,29 @@ nsHTMLEditorLog::PrintSelection()
     if (NS_FAILED(result))
       return result;
     
     result = range->GetStartContainer(getter_AddRefs(startNode));
 
     if (NS_FAILED(result))
       return result;
 
-    if (!startNode)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(startNode, NS_ERROR_NULL_POINTER);
 
     result = range->GetStartOffset(&startOffset);
 
     if (NS_FAILED(result))
       return result;
 
     result = range->GetEndContainer(getter_AddRefs(endNode));
 
     if (NS_FAILED(result))
       return result;
 
-    if (!endNode)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(endNode, NS_ERROR_NULL_POINTER);
 
     result = range->GetEndOffset(&endOffset);
 
     if (NS_FAILED(result))
       return result;
 
     PRInt32 *offsetArray = 0;
     PRInt32 arrayLength = 0;
@@ -1087,18 +1077,17 @@ nsHTMLEditorLog::PrintSelection()
 nsresult
 nsHTMLEditorLog::PrintElementNode(nsIDOMNode *aNode, PRInt32 aDepth)
 {
   nsresult result;
   nsAutoString tag, name, value;
   nsCOMPtr<nsIDOMElement> ele = do_QueryInterface(aNode);
   nsCOMPtr<nsIDOMNamedNodeMap> map;
 
-  if (!ele)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(ele, NS_ERROR_NULL_POINTER);
 
   result = ele->GetTagName(tag);
 
   if (NS_FAILED(result))
     return result;
 
   Write("n");
   WriteInt(aDepth);
@@ -1106,36 +1095,34 @@ nsHTMLEditorLog::PrintElementNode(nsIDOM
   PrintUnicode(tag);
   Write("\");\n");
 
   result = aNode->GetAttributes(getter_AddRefs(map));
 
   if (NS_FAILED(result))
     return result;
 
-  if (!map)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(map, NS_ERROR_NULL_POINTER);
 
   PRUint32 i, len;
   nsCOMPtr<nsIDOMNode> attr;
 
   result = map->GetLength(&len);
 
   if (NS_FAILED(result))
     return result;
 
   for (i = 0; i < len; i++)
   {
     result = map->Item(i, getter_AddRefs(attr));
 
     if (NS_FAILED(result))
       return result;
 
-    if (!attr)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(attr, NS_ERROR_NULL_POINTER);
 
     result = PrintAttributeNode(attr, aDepth);
 
     if (NS_FAILED(result))
       return result;
   }
 
   result = PrintNodeChildren(aNode, aDepth);
@@ -1144,18 +1131,17 @@ nsHTMLEditorLog::PrintElementNode(nsIDOM
 }
 
 nsresult
 nsHTMLEditorLog::PrintAttributeNode(nsIDOMNode *aNode, PRInt32 aDepth)
 {
   nsresult result;
   nsCOMPtr<nsIDOMAttr> attr = do_QueryInterface(aNode);
 
-  if (!attr)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(attr, NS_ERROR_NULL_POINTER);
 
   nsAutoString str;
 
   result = attr->GetName(str);
 
   if (NS_FAILED(result))
     return result;
 
@@ -1185,18 +1171,17 @@ nsHTMLEditorLog::PrintAttributeNode(nsID
   return NS_OK;
 }
 
 nsresult
 nsHTMLEditorLog::PrintNodeChildren(nsIDOMNode *aNode, PRInt32 aDepth)
 {
   nsresult result;
 
-  if (!aNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNodeList> list;
 
   result = aNode->GetChildNodes(getter_AddRefs(list));
   
   if (NS_FAILED(result))
     return result;
 
@@ -1238,18 +1223,17 @@ nsHTMLEditorLog::PrintNodeChildren(nsIDO
 
 nsresult
 nsHTMLEditorLog::PrintTextNode(nsIDOMNode *aNode, PRInt32 aDepth)
 {
   nsresult result;
 
   nsCOMPtr<nsIDOMCharacterData> cd = do_QueryInterface(aNode);
 
-  if (!cd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(cd, NS_ERROR_NULL_POINTER);
 
   nsAutoString str;
 
   result = cd->GetData(str);
 
   if (NS_FAILED(result))
     return result;
 
@@ -1262,18 +1246,17 @@ nsHTMLEditorLog::PrintTextNode(nsIDOMNod
   return NS_OK;
 }
 
 nsresult
 nsHTMLEditorLog::PrintNode(nsIDOMNode *aNode, PRInt32 aDepth)
 {
   nsresult result = NS_OK;
 
-  if (!aNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   PRUint16 nodeType;
   
   result = aNode->GetNodeType(&nodeType);
 
   switch (nodeType)
   {
     case nsIDOMNode::ELEMENT_NODE:
@@ -1303,18 +1286,17 @@ nsHTMLEditorLog::PrintNode(nsIDOMNode *a
   return result;
 }
 
 nsresult
 nsHTMLEditorLog::GetNodeTreeOffsets(nsIDOMNode *aNode, PRInt32 **aResult, PRInt32 *aLength)
 {
   nsresult result;
 
-  if (!aNode || !aResult || !aLength)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aResult && aLength, NS_ERROR_NULL_POINTER);
 
   *aResult = 0;
   *aLength = 0;
 
   nsIDOMNode *parent = aNode;
   PRInt32 i = 0;
 
   // Count the number of parent nodes above aNode.
@@ -1329,18 +1311,17 @@ nsHTMLEditorLog::GetNodeTreeOffsets(nsID
     if (parent)
       ++i;
   }
 
   // Allocate an array big enough to hold all the offsets.
 
   *aResult = new PRInt32[i];
 
-  if (!aResult)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(aResult, NS_ERROR_OUT_OF_MEMORY);
 
   *aLength = i;
 
   while (aNode && i > 0)
   {
     PRInt32 offset = 0;
 
     result = aNode->GetParentNode(&parent);
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -220,18 +220,17 @@ NS_IMETHODIMP nsHTMLEditor::SetInlinePro
         // this can easily happen with the subtree 
         // iterator if the selection doesn't contain
         // any *whole* nodes.
         if (NS_SUCCEEDED(res))
         {
           while (!iter->IsDone())
           {
             node = do_QueryInterface(iter->GetCurrentNode());
-            if (!node)
-              return NS_ERROR_FAILURE;
+            NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
             if (IsEditable(node))
             { 
               arrayOfNodes.AppendObject(node);
             }
 
             iter->Next();
           }
@@ -635,18 +634,17 @@ PRBool nsHTMLEditor::NodeIsProperty(nsID
 
 nsresult nsHTMLEditor::ApplyDefaultProperties()
 {
   nsresult res = NS_OK;
   PRUint32 j, defcon = mDefaultStyles.Length();
   for (j=0; j<defcon; j++)
   {
     PropItem *propItem = mDefaultStyles[j];
-    if (!propItem) 
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(propItem, NS_ERROR_NULL_POINTER);
     res = SetInlineProperty(propItem->tag, propItem->attr, propItem->value);
     NS_ENSURE_SUCCESS(res, res);
   }
   return res;
 }
 
 nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, 
                                    nsIAtom *aProperty,   // null here means remove all properties
@@ -1004,18 +1002,17 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
                              const nsAString *aAttribute,
                              const nsAString *aValue,
                              PRBool *aFirst, 
                              PRBool *aAny, 
                              PRBool *aAll,
                              nsAString *outValue,
                              PRBool aCheckDefaults)
 {
-  if (!aProperty)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
 
   nsresult result;
   *aAny=PR_FALSE;
   *aAll=PR_TRUE;
   *aFirst=PR_FALSE;
   PRBool first=PR_TRUE;
 
   PRBool useCSS;
@@ -1212,18 +1209,17 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
 
 NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty, 
                                               const nsAString &aAttribute, 
                                               const nsAString &aValue,
                                               PRBool *aFirst, 
                                               PRBool *aAny, 
                                               PRBool *aAll)
 {
-  if (!aProperty || !aFirst || !aAny || !aAll)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aProperty && aFirst && aAny && aAll, NS_ERROR_NULL_POINTER);
   const nsAString *att = nsnull;
   if (!aAttribute.IsEmpty())
     att = &aAttribute;
   const nsAString *val = nsnull;
   if (!aValue.IsEmpty())
     val = &aValue;
   return GetInlinePropertyBase( aProperty, att, val, aFirst, aAny, aAll, nsnull);
 }
@@ -1232,18 +1228,17 @@ NS_IMETHODIMP nsHTMLEditor::GetInlinePro
 NS_IMETHODIMP nsHTMLEditor::GetInlinePropertyWithAttrValue(nsIAtom *aProperty, 
                                               const nsAString &aAttribute, 
                                               const nsAString &aValue,
                                               PRBool *aFirst, 
                                               PRBool *aAny, 
                                               PRBool *aAll,
                                               nsAString &outValue)
 {
-  if (!aProperty || !aFirst || !aAny || !aAll)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aProperty && aFirst && aAny && aAll, NS_ERROR_NULL_POINTER);
   const nsAString *att = nsnull;
   if (!aAttribute.IsEmpty())
     att = &aAttribute;
   const nsAString *val = nsnull;
   if (!aValue.IsEmpty())
     val = &aValue;
   return GetInlinePropertyBase( aProperty, att, val, aFirst, aAny, aAll, &outValue);
 }
@@ -1386,18 +1381,17 @@ nsresult nsHTMLEditor::RemoveInlinePrope
         nsCOMArray<nsIDOMNode> arrayOfNodes;
         nsCOMPtr<nsIDOMNode> node;
         
         // iterate range and build up array
         iter->Init(range);
         while (!iter->IsDone())
         {
           node = do_QueryInterface(iter->GetCurrentNode());
-          if (!node)
-            return NS_ERROR_FAILURE;
+          NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
           if (IsEditable(node))
           { 
             arrayOfNodes.AppendObject(node);
           }
 
           iter->Next();
         }
@@ -1566,18 +1560,17 @@ nsHTMLEditor::RelativeFontChange( PRInt3
       
       // iterate range and build up array
       res = iter->Init(range);
       if (NS_SUCCEEDED(res))
       {
         while (!iter->IsDone())
         {
           node = do_QueryInterface(iter->GetCurrentNode());
-          if (!node)
-            return NS_ERROR_FAILURE;
+          NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
           if (IsEditable(node))
           { 
             arrayOfNodes.AppendObject(node);
           }
 
           iter->Next();
         }
@@ -1838,18 +1831,17 @@ nsHTMLEditor::RelativeFontChangeOnNode( 
     }
   }
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetFontFaceState(PRBool *aMixed, nsAString &outFace)
 {
-  if (!aMixed)
-      return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aMixed, NS_ERROR_FAILURE);
   *aMixed = PR_TRUE;
   outFace.Truncate();
 
   nsresult res;
   PRBool first, any, all;
   
   NS_NAMED_LITERAL_STRING(attr, "face");
   res = GetInlinePropertyBase(nsEditProperty::font, &attr, nsnull, &first, &any, &all, &outFace);
@@ -1878,18 +1870,17 @@ nsHTMLEditor::GetFontFaceState(PRBool *a
     *aMixed = PR_FALSE;
   }
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetFontColorState(PRBool *aMixed, nsAString &aOutColor)
 {
-  if (!aMixed)
-      return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
   *aMixed = PR_TRUE;
   aOutColor.Truncate();
   
   nsresult res;
   NS_NAMED_LITERAL_STRING(colorStr, "color");
   PRBool first, any, all;
   
   res = GetInlinePropertyBase(nsEditProperty::font, &colorStr, nsnull, &first, &any, &all, &aOutColor);
--- a/editor/libeditor/html/nsHTMLObjectResizer.cpp
+++ b/editor/libeditor/html/nsHTMLObjectResizer.cpp
@@ -183,18 +183,17 @@ nsHTMLEditor::CreateResizer(nsIDOMElemen
 {
   nsresult res = CreateAnonymousElement(NS_LITERAL_STRING("span"),
                                         aParentNode,
                                         NS_LITERAL_STRING("mozResizer"),
                                         PR_FALSE,
                                         aReturn);
 
   NS_ENSURE_SUCCESS(res, res);
-  if (!*aReturn)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(*aReturn, NS_ERROR_FAILURE);
 
   // add the mouse listener so we can detect a click on a resizer
   nsCOMPtr<nsIDOMEventTarget> evtTarget(do_QueryInterface(*aReturn));
   evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), mEventListener,
                               PR_TRUE);
 
   nsAutoString locationStr;
   switch (aLocation) {
@@ -242,43 +241,40 @@ nsHTMLEditor::CreateShadow(nsIDOMElement
   else
     name.AssignLiteral("span");
   nsresult res = CreateAnonymousElement(name,
                                         aParentNode,
                                         NS_LITERAL_STRING("mozResizingShadow"),
                                         PR_TRUE,
                                         aReturn);
 
-  if (!*aReturn)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(*aReturn, NS_ERROR_FAILURE);
 
   return res;
 }
 
 nsresult
 nsHTMLEditor::CreateResizingInfo(nsIDOMElement ** aReturn, nsIDOMNode * aParentNode)
 {
   // let's create an info box through the element factory
   nsresult res = CreateAnonymousElement(NS_LITERAL_STRING("span"),
                                         aParentNode,
                                         NS_LITERAL_STRING("mozResizingInfo"),
                                         PR_TRUE,
                                         aReturn);
 
-  if (!*aReturn)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(*aReturn, NS_ERROR_FAILURE);
 
   return res;
 }
 
 nsresult
 nsHTMLEditor::SetAllResizersPosition()
 {
-  if (!mTopLeftHandle)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mTopLeftHandle, NS_ERROR_FAILURE);
 
   PRInt32 x = mResizedObjectX;
   PRInt32 y = mResizedObjectY;
   PRInt32 w = mResizedObjectWidth;
   PRInt32 h = mResizedObjectHeight;
 
   // now let's place all the resizers around the image
 
@@ -307,18 +303,17 @@ nsHTMLEditor::SetAllResizersPosition()
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::RefreshResizers()
 {
   // nothing to do if resizers are not displayed...
-  if (!mResizedObject)
-    return NS_OK;
+  NS_ENSURE_TRUE(mResizedObject, NS_OK);
 
   nsresult res = GetPositionAndDimensions(mResizedObject,
                                           mResizedObjectX,
                                           mResizedObjectY,
                                           mResizedObjectWidth,
                                           mResizedObjectHeight,
                                           mResizedObjectBorderLeft,
                                           mResizedObjectBorderTop,
@@ -429,18 +424,17 @@ nsHTMLEditor::ShowResizersInner(nsIDOMEl
 
   aResizedElement->SetAttribute(NS_LITERAL_STRING("_moz_resizing"), NS_LITERAL_STRING("true"));
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::HideResizers(void)
 {
-  if (!mResizedObject)
-    return NS_OK;
+  NS_ENSURE_TRUE(mResizedObject, NS_OK);
 
   // get the presshell's document observer interface.
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
   // We allow the pres shell to be null; when it is, we presume there
   // are no document observers to notify, but we still want to
   // UnbindFromTree.
 
   nsresult res;
--- a/editor/libeditor/html/nsHTMLURIRefObject.cpp
+++ b/editor/libeditor/html/nsHTMLURIRefObject.cpp
@@ -125,35 +125,32 @@ nsHTMLURIRefObject::Reset()
 {
   mCurAttrIndex = 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLURIRefObject::GetNextURI(nsAString & aURI)
 {
-  if (!mNode)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
 
   nsAutoString tagName;
   nsresult rv = mNode->GetNodeName(tagName);
   if (NS_FAILED(rv))
   return rv;
 
   // Loop over attribute list:
   if (!mAttributes)
   {
     nsCOMPtr<nsIDOMElement> element (do_QueryInterface(mNode));
-    if (!element)
-      return NS_ERROR_INVALID_ARG;
+    NS_ENSURE_TRUE(element, NS_ERROR_INVALID_ARG);
 
     mCurAttrIndex = 0;
     mNode->GetAttributes(getter_AddRefs(mAttributes));
-    if (!mAttributes)
-      return NS_ERROR_NOT_INITIALIZED;
+    NS_ENSURE_TRUE(mAttributes, NS_ERROR_NOT_INITIALIZED);
 
     rv = mAttributes->GetLength(&mAttributeCnt);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ENSURE_TRUE(mAttributeCnt, NS_ERROR_FAILURE);
     mCurAttrIndex = 0;
   }
 #ifdef DEBUG_akkana
   printf("Looking at tag '%s'\n",
@@ -285,20 +282,18 @@ nsHTMLURIRefObject::RewriteAllURIs(const
   printf("Can't rewrite URIs yet\n");
 #endif
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsHTMLURIRefObject::GetNode(nsIDOMNode** aNode)
 {
-  if (!mNode)
-    return NS_ERROR_NOT_INITIALIZED;
-  if (!aNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   *aNode = mNode.get();
   NS_ADDREF(*aNode);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLURIRefObject::SetNode(nsIDOMNode *aNode)
 {
--- a/editor/libeditor/html/nsTableEditor.cpp
+++ b/editor/libeditor/html/nsTableEditor.cpp
@@ -1383,18 +1383,17 @@ nsHTMLEditor::DeleteRow(nsIDOMElement *a
           cellInDeleteRow = cell; // Reference cell to find row to delete
       }
       // Skip over other columns spanned by this cell
       colIndex += actualColSpan;
     }
   } while (cell);
 
   // Things are messed up if we didn't find a cell in the row!
-  if (!cellInDeleteRow)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(cellInDeleteRow, NS_ERROR_FAILURE);
 
   // Delete the entire row
   nsCOMPtr<nsIDOMElement> parentRow;
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("tr"), cellInDeleteRow, getter_AddRefs(parentRow));
   NS_ENSURE_SUCCESS(res, res);
 
   if (parentRow)
   {
@@ -2725,18 +2724,17 @@ nsHTMLEditor::GetTableSize(nsIDOMElement
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTable, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
   
   // frames are not ref counted, so don't use an nsCOMPtr
   nsITableLayout *tableLayoutObject;
   res = GetTableLayoutObject(table.get(), &tableLayoutObject);
   NS_ENSURE_SUCCESS(res, res);
-  if (!tableLayoutObject)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(tableLayoutObject, NS_ERROR_FAILURE);
 
   return tableLayoutObject->GetTableSize(*aRowCount, *aColCount); 
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex,
                             PRInt32 aColIndex, nsIDOMElement **aCell, 
                             PRInt32* aStartRowIndex, PRInt32* aStartColIndex, 
@@ -3399,18 +3397,17 @@ nsHTMLEditor::AllCellsInRowSelected(nsID
                                  &actualRowSpan, &actualColSpan, &isSelected);
  
     NS_ENSURE_SUCCESS(res, PR_FALSE);
     // If no cell, we may have a "ragged" right edge,
     //   so return TRUE only if we already found a cell in the row
     NS_ENSURE_TRUE(cell, (col > 0) ? PR_TRUE : PR_FALSE);
 
     // Return as soon as a non-selected cell is found
-    if (!isSelected)
-      return PR_FALSE;
+    NS_ENSURE_TRUE(isSelected, PR_FALSE);
 
     NS_ASSERTION((actualColSpan > 0),"ActualColSpan = 0 in AllCellsInRowSelected");
   }
   return PR_TRUE;
 }
 
 PRBool 
 nsHTMLEditor::AllCellsInColumnSelected(nsIDOMElement *aTable, PRInt32 aColIndex, PRInt32 aNumberOfRows)
@@ -3429,18 +3426,17 @@ nsHTMLEditor::AllCellsInColumnSelected(n
                                  &actualRowSpan, &actualColSpan, &isSelected);
     
     NS_ENSURE_SUCCESS(res, PR_FALSE);
     // If no cell, we must have a "ragged" right edge on the last column
     //   so return TRUE only if we already found a cell in the row
     NS_ENSURE_TRUE(cell, (row > 0) ? PR_TRUE : PR_FALSE);
 
     // Return as soon as a non-selected cell is found
-    if (!isSelected)
-      return PR_FALSE;
+    NS_ENSURE_TRUE(isSelected, PR_FALSE);
   }
   return PR_TRUE;
 }
 
 PRBool 
 nsHTMLEditor::IsEmptyCell(nsIDOMElement *aCell)
 {
   nsCOMPtr<nsIDOMNode> cellChild;
--- a/editor/libeditor/html/nsWSRunObject.cpp
+++ b/editor/libeditor/html/nsWSRunObject.cpp
@@ -92,70 +92,65 @@ nsWSRunObject::~nsWSRunObject()
 //--------------------------------------------------------------------------------------------
 
 nsresult
 nsWSRunObject::ScrubBlockBoundary(nsHTMLEditor *aHTMLEd, 
                                   nsCOMPtr<nsIDOMNode> *aBlock,
                                   BlockBoundary aBoundary,
                                   PRInt32 *aOffset)
 {
-  if (!aBlock || !aHTMLEd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBlock && aHTMLEd, NS_ERROR_NULL_POINTER);
   if ((aBoundary == kBlockStart) || (aBoundary == kBlockEnd))
     return ScrubBlockBoundaryInner(aHTMLEd, aBlock, aBoundary);
   
   // else we are scrubbing an outer boundary - just before or after
   // a block element.
-  if (!aOffset) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOffset, NS_ERROR_NULL_POINTER);
   nsAutoTrackDOMPoint tracker(aHTMLEd->mRangeUpdater, aBlock, aOffset);
   nsWSRunObject theWSObj(aHTMLEd, *aBlock, *aOffset);
   return theWSObj.Scrub();
 }
 
 nsresult 
 nsWSRunObject::PrepareToJoinBlocks(nsHTMLEditor *aHTMLEd, 
                                    nsIDOMNode *aLeftParent, 
                                    nsIDOMNode *aRightParent)
 {
-  if (!aLeftParent || !aRightParent || !aHTMLEd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aLeftParent && aRightParent && aHTMLEd, NS_ERROR_NULL_POINTER);
   PRUint32 count;
   aHTMLEd->GetLengthOfDOMNode(aLeftParent, count);
   nsWSRunObject leftWSObj(aHTMLEd, aLeftParent, count);
   nsWSRunObject rightWSObj(aHTMLEd, aRightParent, 0);
 
   return leftWSObj.PrepareToDeleteRangePriv(&rightWSObj);
 }
 
 nsresult 
 nsWSRunObject::PrepareToDeleteRange(nsHTMLEditor *aHTMLEd, 
                                     nsCOMPtr<nsIDOMNode> *aStartNode,
                                     PRInt32 *aStartOffset, 
                                     nsCOMPtr<nsIDOMNode> *aEndNode,
                                     PRInt32 *aEndOffset)
 {
-  if (!aStartNode || !aEndNode || !*aStartNode || !*aEndNode || !aStartOffset || !aEndOffset || !aHTMLEd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStartNode && aEndNode && *aStartNode && *aEndNode && aStartOffset && aEndOffset && aHTMLEd, NS_ERROR_NULL_POINTER);
 
   nsAutoTrackDOMPoint trackerStart(aHTMLEd->mRangeUpdater, aStartNode, aStartOffset);
   nsAutoTrackDOMPoint trackerEnd(aHTMLEd->mRangeUpdater, aEndNode, aEndOffset);
   
   nsWSRunObject leftWSObj(aHTMLEd, *aStartNode, *aStartOffset);
   nsWSRunObject rightWSObj(aHTMLEd, *aEndNode, *aEndOffset);
 
   return leftWSObj.PrepareToDeleteRangePriv(&rightWSObj);
 }
 
 nsresult 
 nsWSRunObject::PrepareToDeleteNode(nsHTMLEditor *aHTMLEd, 
                                    nsIDOMNode *aNode)
 {
-  if (!aNode || !aHTMLEd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aHTMLEd, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   res = aHTMLEd->GetNodeLocation(aNode, address_of(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
   
   nsWSRunObject leftWSObj(aHTMLEd, parent, offset);
@@ -164,18 +159,17 @@ nsWSRunObject::PrepareToDeleteNode(nsHTM
   return leftWSObj.PrepareToDeleteRangePriv(&rightWSObj);
 }
 
 nsresult 
 nsWSRunObject::PrepareToSplitAcrossBlocks(nsHTMLEditor *aHTMLEd, 
                                           nsCOMPtr<nsIDOMNode> *aSplitNode, 
                                           PRInt32 *aSplitOffset)
 {
-  if (!aSplitNode || !aSplitOffset || !*aSplitNode || !aHTMLEd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSplitNode && aSplitOffset && *aSplitNode && aHTMLEd, NS_ERROR_NULL_POINTER);
 
   nsAutoTrackDOMPoint tracker(aHTMLEd->mRangeUpdater, aSplitNode, aSplitOffset);
   
   nsWSRunObject wsObj(aHTMLEd, *aSplitNode, *aSplitOffset);
 
   return wsObj.PrepareToSplitAcrossBlocksPriv();
 }
 
@@ -186,18 +180,17 @@ nsWSRunObject::PrepareToSplitAcrossBlock
 nsresult 
 nsWSRunObject::InsertBreak(nsCOMPtr<nsIDOMNode> *aInOutParent, 
                            PRInt32 *aInOutOffset, 
                            nsCOMPtr<nsIDOMNode> *outBRNode, 
                            nsIEditor::EDirection aSelect)
 {
   // MOOSE: for now, we always assume non-PRE formatting.  Fix this later.
   // meanwhile, the pre case is handled in WillInsertText in nsHTMLEditRules.cpp
-  if (!aInOutParent || !aInOutOffset || !outBRNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aInOutParent && aInOutOffset && outBRNode, NS_ERROR_NULL_POINTER);
 
   nsresult res = NS_OK;
   WSFragment *beforeRun, *afterRun;
   res = FindRun(*aInOutParent, *aInOutOffset, &beforeRun, PR_FALSE);
   res = FindRun(*aInOutParent, *aInOutOffset, &afterRun, PR_TRUE);
   
   {
     // some scoping for nsAutoTrackDOMPoint.  This will track our insertion point
@@ -278,18 +271,17 @@ nsWSRunObject::InsertText(const nsAStrin
 {
   // MOOSE: for now, we always assume non-PRE formatting.  Fix this later.
   // meanwhile, the pre case is handled in WillInsertText in nsHTMLEditRules.cpp
 
   // MOOSE: for now, just getting the ws logic straight.  This implementation
   // is very slow.  Will need to replace edit rules impl with a more efficient
   // text sink here that does the minimal amount of searching/replacing/copying
 
-  if (!aInOutParent || !aInOutOffset || !aDoc)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aInOutParent && aInOutOffset && aDoc, NS_ERROR_NULL_POINTER);
 
   nsresult res = NS_OK;
   if (aStringToInsert.IsEmpty()) return res;
   
   // string copying sux.  
   nsAutoString theString(aStringToInsert);
   
   WSFragment *beforeRun, *afterRun;
@@ -558,18 +550,17 @@ nsresult
 nsWSRunObject::PriorVisibleNode(nsIDOMNode *aNode, 
                                 PRInt32 aOffset, 
                                 nsCOMPtr<nsIDOMNode> *outVisNode, 
                                 PRInt32 *outVisOffset,
                                 PRInt16 *outType)
 {
   // Find first visible thing before the point.  position outVisNode/outVisOffset
   // just _after_ that thing.  If we don't find anything return start of ws.
-  if (!aNode || !outVisNode || !outVisOffset || !outType)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outVisNode && outVisOffset && outType, NS_ERROR_NULL_POINTER);
     
   *outType = eNone;
   WSFragment *run;
   FindRun(aNode, aOffset, &run, PR_FALSE);
   
   // is there a visible run there or earlier?
   while (run)
   {
@@ -614,18 +605,17 @@ nsresult
 nsWSRunObject::NextVisibleNode (nsIDOMNode *aNode, 
                                 PRInt32 aOffset, 
                                 nsCOMPtr<nsIDOMNode> *outVisNode, 
                                 PRInt32 *outVisOffset,
                                 PRInt16 *outType)
 {
   // Find first visible thing after the point.  position outVisNode/outVisOffset
   // just _before_ that thing.  If we don't find anything return end of ws.
-  if (!aNode || !outVisNode || !outVisOffset || !outType)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outVisNode && outVisOffset && outType, NS_ERROR_NULL_POINTER);
     
   WSFragment *run;
   FindRun(aNode, aOffset, &run, PR_TRUE);
   
   // is there a visible run there or later?
   while (run)
   {
     if (run->mType == eNormalWS)
@@ -689,18 +679,17 @@ nsWSRunObject::AdjustWhitespace()
 
 //--------------------------------------------------------------------------------------------
 //   protected methods
 //--------------------------------------------------------------------------------------------
 
 already_AddRefed<nsIDOMNode>
 nsWSRunObject::GetWSBoundingParent()
 {
-  if (!mNode)
-    return nsnull;
+  NS_ENSURE_TRUE(mNode, nsnull);
   nsCOMPtr<nsIDOMNode> wsBoundingParent = mNode;
   while (!IsBlockNode(wsBoundingParent))
   {
     nsCOMPtr<nsIDOMNode> parent;
     wsBoundingParent->GetParentNode(getter_AddRefs(parent));
     if (!parent || !mHTMLEditor->IsEditable(parent))
       break;
     wsBoundingParent.swap(parent);
@@ -1237,18 +1226,17 @@ nsresult
 nsWSRunObject::GetPreviousWSNode(nsIDOMNode *aStartNode,
                                  PRInt16 aOffset, 
                                  nsIDOMNode *aBlockParent, 
                                  nsCOMPtr<nsIDOMNode> *aPriorNode)
 {
   // can't really recycle various getnext/prior routines because we
   // have special needs here.  Need to step into inline containers but
   // not block containers.
-  if (!aStartNode || !aBlockParent || !aPriorNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStartNode && aBlockParent && aPriorNode, NS_ERROR_NULL_POINTER);
   *aPriorNode = 0;
 
   if (mHTMLEditor->IsTextNode(aStartNode))
     return GetPreviousWSNode(aStartNode, aBlockParent, aPriorNode);
   if (!mHTMLEditor->IsContainer(aStartNode))
     return GetPreviousWSNode(aStartNode, aBlockParent, aPriorNode);
   
   if (!aOffset)
@@ -1261,18 +1249,17 @@ nsWSRunObject::GetPreviousWSNode(nsIDOMN
 
     // we are at start of non-block container
     return GetPreviousWSNode(aStartNode, aBlockParent, aPriorNode);
   }
 
   nsCOMPtr<nsIContent> startContent( do_QueryInterface(aStartNode) );
   NS_ENSURE_STATE(startContent);
   nsIContent *priorContent = startContent->GetChildAt(aOffset - 1);
-  if (!priorContent) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(priorContent, NS_ERROR_NULL_POINTER);
   *aPriorNode = do_QueryInterface(priorContent);
   // we have a prior node.  If it's a block, return it.
   if (IsBlockNode(*aPriorNode))
     return NS_OK;
   // else if it's a container, get deep rightmost child
   else if (mHTMLEditor->IsContainer(*aPriorNode))
   {
     nsCOMPtr<nsIDOMNode> temp;
@@ -1288,18 +1275,17 @@ nsWSRunObject::GetPreviousWSNode(nsIDOMN
 nsresult 
 nsWSRunObject::GetNextWSNode(nsIDOMNode *aStartNode, 
                              nsIDOMNode *aBlockParent, 
                              nsCOMPtr<nsIDOMNode> *aNextNode)
 {
   // can't really recycle various getnext/prior routines because we
   // have special needs here.  Need to step into inline containers but
   // not block containers.
-  if (!aStartNode || !aBlockParent || !aNextNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStartNode && aBlockParent && aNextNode, NS_ERROR_NULL_POINTER);
   
   *aNextNode = 0;
   nsresult res = aStartNode->GetNextSibling(getter_AddRefs(*aNextNode));
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsIDOMNode> temp, curNode = aStartNode;
   while (!*aNextNode)
   {
     // we have exhausted nodes in parent of aStartNode.
@@ -1347,18 +1333,17 @@ nsWSRunObject::GetNextWSNode(DOMPoint aP
 nsresult 
 nsWSRunObject::GetNextWSNode(nsIDOMNode *aStartNode,
                              PRInt16 aOffset, 
                              nsIDOMNode *aBlockParent, 
                              nsCOMPtr<nsIDOMNode> *aNextNode)
 {
   // can't really recycle various getnext/prior routines because we have special needs
   // here.  Need to step into inline containers but not block containers.
-  if (!aStartNode || !aBlockParent || !aNextNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStartNode && aBlockParent && aNextNode, NS_ERROR_NULL_POINTER);
   *aNextNode = 0;
 
   if (mHTMLEditor->IsTextNode(aStartNode))
     return GetNextWSNode(aStartNode, aBlockParent, aNextNode);
   if (!mHTMLEditor->IsContainer(aStartNode))
     return GetNextWSNode(aStartNode, aBlockParent, aNextNode);
   
   nsCOMPtr<nsIContent> startContent( do_QueryInterface(aStartNode) );
@@ -1398,18 +1383,17 @@ nsWSRunObject::PrepareToDeleteRangePriv(
 {
   // this routine adjust whitespace before *this* and after aEndObject
   // in preperation for the two areas to become adjacent after the 
   // intervening content is deleted.  It's overly agressive right
   // now.  There might be a block boundary remaining between them after
   // the deletion, in which case these adjstments are unneeded (though
   // I don't think they can ever be harmful?)
   
-  if (!aEndObject)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aEndObject, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   
   // get the runs before and after selection
   WSFragment *beforeRun, *afterRun;
   res = FindRun(mNode, mOffset, &beforeRun, PR_FALSE);
   NS_ENSURE_SUCCESS(res, res);
   res = aEndObject->FindRun(aEndObject->mNode, aEndObject->mOffset, &afterRun, PR_TRUE);
   NS_ENSURE_SUCCESS(res, res);
@@ -1533,18 +1517,17 @@ nsWSRunObject::PrepareToSplitAcrossBlock
 
 nsresult 
 nsWSRunObject::DeleteChars(nsIDOMNode *aStartNode, PRInt32 aStartOffset, 
                            nsIDOMNode *aEndNode, PRInt32 aEndOffset,
                            AreaRestriction aAR)
 {
   // MOOSE: this routine needs to be modified to preserve the integrity of the
   // wsFragment info.
-  if (!aStartNode || !aEndNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStartNode && aEndNode, NS_ERROR_NULL_POINTER);
 
   if (aAR == eOutsideUserSelectAll)
   {
     nsCOMPtr<nsIDOMNode> san = mHTMLEditor->FindUserSelectAllNode(aStartNode);
     if (san)
       return NS_OK;
     
     if (aStartNode != aEndNode)
@@ -1634,18 +1617,17 @@ nsWSRunObject::DeleteChars(nsIDOMNode *a
     idx++;
   }
   return res;
 }
 
 nsresult 
 nsWSRunObject::GetCharAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint)
 {
-  if (!aNode || !outPoint)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outPoint, NS_ERROR_NULL_POINTER);
 
   PRInt32 idx = mNodeArray.IndexOf(aNode);
   if (idx == -1) 
   {
     // use range comparisons to get right ws node
     return GetWSPointAfter(aNode, aOffset, outPoint);
   }
   else
@@ -1656,18 +1638,17 @@ nsWSRunObject::GetCharAfter(nsIDOMNode *
   }
   
   return NS_ERROR_FAILURE;
 }
 
 nsresult 
 nsWSRunObject::GetCharBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint)
 {
-  if (!aNode || !outPoint)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outPoint, NS_ERROR_NULL_POINTER);
 
   PRInt32 idx = mNodeArray.IndexOf(aNode);
   if (idx == -1) 
   {
     // use range comparisons to get right ws node
     return GetWSPointBefore(aNode, aOffset, outPoint);
   }
   else
@@ -1678,18 +1659,17 @@ nsWSRunObject::GetCharBefore(nsIDOMNode 
   }
   
   return NS_ERROR_FAILURE;
 }
 
 nsresult 
 nsWSRunObject::GetCharAfter(WSPoint &aPoint, WSPoint *outPoint)
 {
-  if (!aPoint.mTextNode || !outPoint)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aPoint.mTextNode && outPoint, NS_ERROR_NULL_POINTER);
   
   outPoint->mTextNode = nsnull;
   outPoint->mOffset = 0;
   outPoint->mChar = 0;
 
   nsCOMPtr<nsIDOMNode> pointTextNode(do_QueryInterface(aPoint.mTextNode));
   PRInt32 idx = mNodeArray.IndexOf(pointTextNode);
   if (idx == -1) return NS_OK;  // can't find point, but it's not an error
@@ -1714,18 +1694,17 @@ nsWSRunObject::GetCharAfter(WSPoint &aPo
     outPoint->mChar = GetCharAt(outPoint->mTextNode, 0);
   }
   return NS_OK;
 }
 
 nsresult 
 nsWSRunObject::GetCharBefore(WSPoint &aPoint, WSPoint *outPoint)
 {
-  if (!aPoint.mTextNode || !outPoint)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aPoint.mTextNode && outPoint, NS_ERROR_NULL_POINTER);
   
   outPoint->mTextNode = nsnull;
   outPoint->mOffset = 0;
   outPoint->mChar = 0;
   
   nsCOMPtr<nsIDOMNode> pointTextNode(do_QueryInterface(aPoint.mTextNode));
   PRInt32 idx = mNodeArray.IndexOf(pointTextNode);
   if (idx == -1) return NS_OK;  // can't find point, but it's not an error
@@ -1753,33 +1732,31 @@ nsWSRunObject::GetCharBefore(WSPoint &aP
   return NS_OK;
 }
 
 nsresult 
 nsWSRunObject::ConvertToNBSP(WSPoint aPoint, AreaRestriction aAR)
 {
   // MOOSE: this routine needs to be modified to preserve the integrity of the
   // wsFragment info.
-  if (!aPoint.mTextNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aPoint.mTextNode, NS_ERROR_NULL_POINTER);
 
   if (aAR == eOutsideUserSelectAll)
   {
     nsCOMPtr<nsIDOMNode> domnode = do_QueryInterface(aPoint.mTextNode);
     if (domnode)
     {
       nsCOMPtr<nsIDOMNode> san = mHTMLEditor->FindUserSelectAllNode(domnode);
       if (san)
         return NS_OK;
     }
   }
 
   nsCOMPtr<nsIDOMCharacterData> textNode(do_QueryInterface(aPoint.mTextNode));
-  if (!textNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(textNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(textNode));
   
   // first, insert an nbsp
   nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
   nsAutoString nbspStr(nbsp);
   nsresult res = mHTMLEditor->InsertTextIntoTextNodeImpl(nbspStr, textNode, aPoint.mOffset, PR_TRUE);
   NS_ENSURE_SUCCESS(res, res);
   
@@ -1800,18 +1777,17 @@ nsWSRunObject::ConvertToNBSP(WSPoint aPo
   return res;
 }
 
 nsresult
 nsWSRunObject::GetAsciiWSBounds(PRInt16 aDir, nsIDOMNode *aNode, PRInt32 aOffset,
                                 nsCOMPtr<nsIDOMNode> *outStartNode, PRInt32 *outStartOffset,
                                 nsCOMPtr<nsIDOMNode> *outEndNode, PRInt32 *outEndOffset)
 {
-  if (!aNode || !outStartNode || !outEndNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outStartNode && outEndNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> startNode, endNode;
   PRInt32 startOffset=0, endOffset=0;
   
   nsresult res = NS_OK;
   
   if (aDir & eAfter)
   {
@@ -1870,18 +1846,17 @@ nsWSRunObject::GetAsciiWSBounds(PRInt16 
 
   return NS_OK;
 }
 
 nsresult
 nsWSRunObject::FindRun(nsIDOMNode *aNode, PRInt32 aOffset, WSFragment **outRun, PRBool after)
 {
   // given a dompoint, find the ws run that is before or after it, as caller needs
-  if (!aNode || !outRun)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outRun, NS_ERROR_NULL_POINTER);
     
   nsresult res = NS_OK;
   WSFragment *run = mStartRun;
   while (run)
   {
     PRInt16 comp = mHTMLEditor->sRangeHelper->ComparePoints(aNode, aOffset, run->mStartNode, run->mStartOffset);
     if (comp <= 0)
     {
@@ -1932,18 +1907,17 @@ nsWSRunObject::FindRun(nsIDOMNode *aNode
   }
   return res;
 }
 
 PRUnichar 
 nsWSRunObject::GetCharAt(nsIContent *aTextNode, PRInt32 aOffset)
 {
   // return 0 if we can't get a char, for whatever reason
-  if (!aTextNode)
-    return 0;
+  NS_ENSURE_TRUE(aTextNode, 0);
 
   PRUint32 len = aTextNode->TextLength();
   if (aOffset < 0 || aOffset >= PRUint32(len)) 
     return 0;
     
   return aTextNode->GetText()->CharAt(aOffset);
 }
 
@@ -1951,18 +1925,17 @@ nsresult
 nsWSRunObject::GetWSPointAfter(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint)
 {
   // Note: only to be called if aNode is not a ws node.  
   
   // binary search on wsnodes
   PRInt32 numNodes, firstNum, curNum, lastNum;
   numNodes = mNodeArray.Count();
   
-  if (!numNodes) 
-    return NS_OK; // do nothing if there are no nodes to search
+  NS_ENSURE_TRUE(numNodes, NS_OK); // do nothing if there are no nodes to search
 
   firstNum = 0;
   curNum = numNodes/2;
   lastNum = numNodes;
   PRInt16 cmp=0;
   nsCOMPtr<nsIDOMNode>  curNode;
   
   // begin binary search
@@ -2001,18 +1974,17 @@ nsresult
 nsWSRunObject::GetWSPointBefore(nsIDOMNode *aNode, PRInt32 aOffset, WSPoint *outPoint)
 {
   // Note: only to be called if aNode is not a ws node.  
   
   // binary search on wsnodes
   PRInt32 numNodes, firstNum, curNum, lastNum;
   numNodes = mNodeArray.Count();
   
-  if (!numNodes) 
-    return NS_OK; // do nothing if there are no nodes to search
+  NS_ENSURE_TRUE(numNodes, NS_OK); // do nothing if there are no nodes to search
   
   firstNum = 0;
   curNum = numNodes/2;
   lastNum = numNodes;
   PRInt16 cmp=0;
   nsCOMPtr<nsIDOMNode>  curNode;
   
   // begin binary search
@@ -2116,18 +2088,17 @@ nsWSRunObject::CheckTrailingNBSPOfRun(WS
         rightCheck = PR_TRUE;
       }
     }
     if (leftCheck && rightCheck)
     {
       // now replace nbsp with space
       // first, insert a space
       nsCOMPtr<nsIDOMCharacterData> textNode(do_QueryInterface(thePoint.mTextNode));
-      if (!textNode)
-        return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(textNode, NS_ERROR_NULL_POINTER);
       nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
       nsAutoString spaceStr(PRUnichar(32));
       res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset, PR_TRUE);
       NS_ENSURE_SUCCESS(res, res);
   
       // finally, delete that nbsp
       nsCOMPtr<nsIDOMNode> delNode(do_QueryInterface(thePoint.mTextNode));
       res = DeleteChars(delNode, thePoint.mOffset+1, delNode, thePoint.mOffset+2);
@@ -2184,18 +2155,17 @@ nsWSRunObject::CheckTrailingNBSP(WSFragm
     }
     else if (aRun->mLeftType == eText)    canConvert = PR_TRUE;
     else if (aRun->mLeftType == eSpecial) canConvert = PR_TRUE;
   }
   if (canConvert)
   {
     // first, insert a space
     nsCOMPtr<nsIDOMCharacterData> textNode(do_QueryInterface(thePoint.mTextNode));
-    if (!textNode)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(textNode, NS_ERROR_NULL_POINTER);
     nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
     nsAutoString spaceStr(PRUnichar(32));
     res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset, PR_TRUE);
     NS_ENSURE_SUCCESS(res, res);
   
     // finally, delete that nbsp
     nsCOMPtr<nsIDOMNode> delNode(do_QueryInterface(thePoint.mTextNode));
     res = DeleteChars(delNode, thePoint.mOffset+1, delNode, thePoint.mOffset+2);
@@ -2226,18 +2196,17 @@ nsWSRunObject::CheckLeadingNBSP(WSFragme
     else if (aRun->mRightType == eText)    canConvert = PR_TRUE;
     else if (aRun->mRightType == eSpecial) canConvert = PR_TRUE;
     else if (aRun->mRightType == eBreak)   canConvert = PR_TRUE;
   }
   if (canConvert)
   {
     // first, insert a space
     nsCOMPtr<nsIDOMCharacterData> textNode(do_QueryInterface(thePoint.mTextNode));
-    if (!textNode)
-      return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(textNode, NS_ERROR_NULL_POINTER);
     nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
     nsAutoString spaceStr(PRUnichar(32));
     res = mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, textNode, thePoint.mOffset, PR_TRUE);
     NS_ENSURE_SUCCESS(res, res);
   
     // finally, delete that nbsp
     nsCOMPtr<nsIDOMNode> delNode(do_QueryInterface(thePoint.mTextNode));
     res = DeleteChars(delNode, thePoint.mOffset+1, delNode, thePoint.mOffset+2);
@@ -2247,18 +2216,17 @@ nsWSRunObject::CheckLeadingNBSP(WSFragme
 }
 
 
 nsresult
 nsWSRunObject::ScrubBlockBoundaryInner(nsHTMLEditor *aHTMLEd, 
                                        nsCOMPtr<nsIDOMNode> *aBlock,
                                        BlockBoundary aBoundary)
 {
-  if (!aBlock || !aHTMLEd)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBlock && aHTMLEd, NS_ERROR_NULL_POINTER);
   PRInt32 offset=0;
   if (aBoundary == kBlockEnd)
   {
     PRUint32 uOffset;
     aHTMLEd->GetLengthOfDOMNode(*aBlock, uOffset); 
     offset = uOffset;
   }
   nsWSRunObject theWSObj(aHTMLEd, *aBlock, offset);
--- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp
@@ -297,18 +297,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertF
     rv = InsertTextFromTransferable(trans, newSelectionParent, newSelectionOffset, deleteSelection);
   }
 
   return rv;
 }
 
 NS_IMETHODIMP nsPlaintextEditor::CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDrag)
 {
-  if (!aCanDrag)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCanDrag, NS_ERROR_NULL_POINTER);
   /* we really should be checking the XY coordinates of the mouseevent and ensure that
    * that particular point is actually within the selection (not just that there is a selection)
    */
   *aCanDrag = PR_FALSE;
  
   // KLUDGE to work around bug 50703
   // After double click and object property editing, 
   //  we get a spurious drag event
@@ -366,18 +365,17 @@ NS_IMETHODIMP nsPlaintextEditor::DoDrag(
  /* get the drag service */
   nsCOMPtr<nsIDragService> dragService = 
            do_GetService("@mozilla.org/widget/dragservice;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   /* create an array of transferables */
   nsCOMPtr<nsISupportsArray> transferableArray;
   NS_NewISupportsArray(getter_AddRefs(transferableArray));
-  if (!transferableArray)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(transferableArray, NS_ERROR_OUT_OF_MEMORY);
 
   /* add the transferable to the array */
   rv = transferableArray->AppendElement(trans);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // check our transferable hooks (if any)
   nsCOMPtr<nsIDOMDocument> domdoc;
   GetDocument(getter_AddRefs(domdoc));
@@ -534,18 +532,17 @@ nsPlaintextEditor::SetupDocEncoder(nsIDo
     docEncoderFlags |= nsIDocumentEncoder::OutputBodyOnly | nsIDocumentEncoder::OutputPreformatted;
     mimeType.AssignLiteral(kUnicodeMime);
   }
   else
     mimeType.AssignLiteral(kHTMLMime);
 
   // set up docEncoder
   nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(NS_HTMLCOPY_ENCODER_CONTRACTID);
-  if (!encoder)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(encoder, NS_ERROR_OUT_OF_MEMORY);
 
   rv = encoder->Init(domDoc, mimeType, docEncoderFlags);
   NS_ENSURE_SUCCESS(rv, rv);
     
   /* get the selection to be dragged */
   nsCOMPtr<nsISelection> selection;
   rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -144,18 +144,17 @@ NS_INTERFACE_MAP_END_INHERITING(nsEditor
 
 
 NS_IMETHODIMP nsPlaintextEditor::Init(nsIDOMDocument *aDoc, 
                                  nsIPresShell   *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags)
 {
   NS_TIME_FUNCTION;
 
   NS_PRECONDITION(aDoc && aPresShell, "bad arg");
-  if (!aDoc || !aPresShell)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDoc && aPresShell, NS_ERROR_NULL_POINTER);
   
   nsresult res = NS_OK, rulesRes = NS_OK;
   
   if (1)
   {
     // block to scope nsAutoEditInitRulesTrigger
     nsAutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
   
@@ -664,18 +663,17 @@ nsPlaintextEditor::ExtendSelectionForDel
   NS_ENSURE_SUCCESS(result, result);
 
   if (*aAction == eNextWord || *aAction == ePreviousWord
       || (*aAction == eNext && bCollapsed)
       || (*aAction == ePrevious && bCollapsed)
       || *aAction == eToBeginningOfLine || *aAction == eToEndOfLine)
   {
     nsCOMPtr<nsISelectionController> selCont (do_QueryReferent(mSelConWeak));
-    if (!selCont)
-      return NS_ERROR_NO_INTERFACE;
+    NS_ENSURE_TRUE(selCont, NS_ERROR_NO_INTERFACE);
 
     switch (*aAction)
     {
       case eNextWord:
         result = selCont->WordExtendForDelete(PR_TRUE);
         // DeleteSelectionImpl doesn't handle these actions
         // because it's inside batching, so don't confuse it:
         *aAction = eNone;
@@ -947,21 +945,19 @@ nsPlaintextEditor::BeginComposition()
   }
 
   return nsEditor::BeginComposition();
 }
 
 NS_IMETHODIMP
 nsPlaintextEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
 {
-  if (!aDocumentIsEmpty)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDocumentIsEmpty, NS_ERROR_NULL_POINTER);
   
-  if (!mRules)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
   
   return mRules->DocumentIsEmpty(aDocumentIsEmpty);
 }
 
 NS_IMETHODIMP
@@ -1008,30 +1004,28 @@ nsPlaintextEditor::SetMaxTextLength(PRIn
 {
   mMaxTextLength = aMaxTextLength;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPlaintextEditor::GetMaxTextLength(PRInt32* aMaxTextLength)
 {
-  if (!aMaxTextLength)
-    return NS_ERROR_INVALID_POINTER;
+  NS_ENSURE_TRUE(aMaxTextLength, NS_ERROR_INVALID_POINTER);
   *aMaxTextLength = mMaxTextLength;
   return NS_OK;
 }
 
 //
 // Get the wrap width
 //
 NS_IMETHODIMP 
 nsPlaintextEditor::GetWrapWidth(PRInt32 *aWrapColumn)
 {
-  if (! aWrapColumn)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE( aWrapColumn, NS_ERROR_NULL_POINTER);
 
   *aWrapColumn = mWrapColumn;
   return NS_OK;
 }
 
 //
 // See if the style value includes this attribute, and if it does,
 // cut out everything from the attribute to the next semicolon.
@@ -1061,18 +1055,17 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 
   // Make sure we're a plaintext editor, otherwise we shouldn't
   // do the rest of this.
   if (!IsPlaintextEditor())
     return NS_OK;
 
   // Ought to set a style sheet here ...
   // Probably should keep around an mPlaintextStyleSheet for this purpose.
   nsIDOMElement *rootElement = GetRoot();
-  if (!rootElement)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
 
   // Get the current style for this root element:
   NS_NAMED_LITERAL_STRING(styleName, "style");
   nsAutoString styleValue;
   nsresult res = rootElement->GetAttribute(styleName, styleValue);
   NS_ENSURE_SUCCESS(res, res);
 
   // We'll replace styles for these values:
@@ -1536,18 +1529,17 @@ nsPlaintextEditor::InsertAsCitedQuotatio
 nsresult
 nsPlaintextEditor::SharedOutputString(PRUint32 aFlags,
                                       PRBool* aIsCollapsed,
                                       nsAString& aResult)
 {
   nsCOMPtr<nsISelection> selection;
   nsresult rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!selection)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
 
   rv = selection->GetIsCollapsed(aIsCollapsed);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!*aIsCollapsed)
     aFlags |= nsIDocumentEncoder::OutputSelectionOnly;
   // If the selection isn't collapsed, we'll use the whole document.
 
@@ -1642,18 +1634,17 @@ nsPlaintextEditor::SetCompositionString(
 {
   if (!aTextRangeList && !aCompositionString.IsEmpty())
   {
     NS_ERROR("aTextRangeList is null but the composition string is not null");
     return NS_ERROR_NULL_POINTER;
   }
 
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) 
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsISelection> selection;
   nsresult result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
 
   nsRefPtr<nsCaret> caretP = ps->GetCaret();
 
   // We should return caret position if it is possible. Because this event
@@ -1739,18 +1730,17 @@ nsPlaintextEditor::SelectEntireDocument(
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   // is doc empty?
   PRBool bDocIsEmpty;
   if (NS_SUCCEEDED(mRules->DocumentIsEmpty(&bDocIsEmpty)) && bDocIsEmpty)
   {
     // get root node
     nsIDOMElement *rootElement = GetRoot();
-    if (!rootElement)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
 
     // if it's empty don't select entire doc - that would select the bogus node
     return aSelection->Collapse(rootElement, 0);
   }
 
   return nsEditor::SelectEntireDocument(aSelection);
 }
 
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -349,18 +349,17 @@ nsTextEditRules::WillDoAction(nsISelecti
 NS_IMETHODIMP 
 nsTextEditRules::DidDoAction(nsISelection *aSelection,
                              nsRulesInfo *aInfo, nsresult aResult)
 {
   // don't let any txns in here move the selection around behind our back.
   // Note that this won't prevent explicit selection setting from working.
   nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);
 
-  if (!aSelection || !aInfo) 
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection && aInfo, NS_ERROR_NULL_POINTER);
     
   // my kingdom for dynamic cast
   nsTextRulesInfo *info = static_cast<nsTextRulesInfo*>(aInfo);
 
   switch (info->action)
   {
    case kInsertBreak:
      return DidInsertBreak(aSelection, aResult);
@@ -383,33 +382,31 @@ nsTextEditRules::DidDoAction(nsISelectio
   // Don't fail on transactions we don't handle here!
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsTextEditRules::DocumentIsEmpty(PRBool *aDocumentIsEmpty)
 {
-  if (!aDocumentIsEmpty)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDocumentIsEmpty, NS_ERROR_NULL_POINTER);
   
   *aDocumentIsEmpty = (mBogusNode != nsnull);
   return NS_OK;
 }
 
 /********************************************************
  *  Protected methods 
  ********************************************************/
 
 
 nsresult
 nsTextEditRules::WillInsert(nsISelection *aSelection, PRBool *aCancel)
 {
-  if (!aSelection || !aCancel)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection && aCancel, NS_ERROR_NULL_POINTER);
   
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
 
   // initialize out param
   *aCancel = PR_FALSE;
   
   // check for the magic content node and delete it if it exists
   if (mBogusNode)
@@ -1210,18 +1207,17 @@ nsTextEditRules::ReplaceNewlines(nsIDOMR
   NS_ENSURE_SUCCESS(res, res);
   
   nsCOMArray<nsIDOMCharacterData> arrayOfNodes;
   
   // gather up a list of editable preformatted text nodes
   while (!iter->IsDone())
   {
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(iter->GetCurrentNode());
-    if (!node)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
     if (mEditor->IsTextNode(node) && mEditor->IsEditable(node))
     {
       PRBool isPRE;
       res = mEditor->IsPreformatted(node, &isPRE);
       NS_ENSURE_SUCCESS(res, res);
       if (isPRE)
       {
@@ -1272,18 +1268,17 @@ nsTextEditRules::ReplaceNewlines(nsIDOMR
 
 nsresult
 nsTextEditRules::CreateTrailingBRIfNeeded()
 {
   // but only if we aren't a single line edit field
   if (IsSingleLineEditor())
     return NS_OK;
   nsIDOMNode *body = mEditor->GetRoot();
-  if (!body)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(body, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> lastChild;
   nsresult res = body->GetLastChild(getter_AddRefs(lastChild));
   // assuming CreateBogusNodeIfNeeded() has been called first
   NS_ENSURE_SUCCESS(res, res);  
   NS_ENSURE_TRUE(lastChild, NS_ERROR_NULL_POINTER);
 
   if (!nsTextEditUtils::IsBreak(lastChild))
   {
@@ -1464,22 +1459,20 @@ nsresult nsTextEditRules::HideLastPWInpu
   nsCOMPtr<nsISelection> selection;
   PRUint32 start, end;
   nsresult res = mEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   res = mEditor->GetTextSelectionOffsets(selection, start, end);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMNode> selNode = GetTextNode(selection, mEditor);
-  if (!selNode)
-    return NS_OK;
+  NS_ENSURE_TRUE(selNode, NS_OK);
   
   nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(selNode));
-  if (!nodeAsText)
-    return NS_OK;
+  NS_ENSURE_TRUE(nodeAsText, NS_OK);
   
   nodeAsText->ReplaceData(mLastStart, mLastLength, hiddenText);
   selection->Collapse(selNode, start);
   if (start != end)
     selection->Extend(selNode, end);
   return NS_OK;
 }
 
--- a/editor/libeditor/text/nsTextEditRulesBidi.cpp
+++ b/editor/libeditor/text/nsTextEditRulesBidi.cpp
@@ -55,41 +55,36 @@ nsTextEditRules::CheckBidiLevelForDeleti
 {
   NS_ENSURE_ARG_POINTER(aCancel);
   *aCancel = PR_FALSE;
 
   nsCOMPtr<nsIPresShell> shell;
   nsresult res = mEditor->GetPresShell(getter_AddRefs(shell));
   if (NS_FAILED(res))
     return res;
-  if (!shell)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(shell, NS_ERROR_NULL_POINTER);
   
   nsPresContext *context = shell->GetPresContext();
-  if (!context)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
   
   if (!context->BidiEnabled())
     return NS_OK;
   
   nsCOMPtr<nsIContent> content = do_QueryInterface(aSelNode);
-  if (!content)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
 
   PRUint8 levelBefore;
   PRUint8 levelAfter;
 
   nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(aSelection));
-  if (!privateSelection)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(privateSelection, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsFrameSelection> frameSelection;
   privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
-  if (!frameSelection)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
   
   nsPrevNextBidiLevels levels = frameSelection->
     GetPrevNextBidiLevels(content, aSelOffset, PR_TRUE);
     
   levelBefore = levels.mLevelBefore;
   levelAfter = levels.mLevelAfter;
 
   PRUint8 currentCaretLevel = frameSelection->GetCaretBidiLevel();
--- a/editor/libeditor/text/nsTextEditUtils.cpp
+++ b/editor/libeditor/text/nsTextEditUtils.cpp
@@ -99,18 +99,17 @@ nsTextEditUtils::HasMozAttr(nsIDOMNode *
 
 
 ///////////////////////////////////////////////////////////////////////////
 // InBody: true if node is a descendant of the body
 //                  
 PRBool 
 nsTextEditUtils::InBody(nsIDOMNode *node, nsIEditor *editor)
 {
-  if (!node)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(node, PR_FALSE);
 
   nsCOMPtr<nsIDOMElement> rootElement;
   editor->GetRootElement(getter_AddRefs(rootElement));
 
   nsCOMPtr<nsIDOMNode> tmp;
   nsCOMPtr<nsIDOMNode> p = node;
   while (p != rootElement)
   {
--- a/editor/txmgr/src/nsTransactionItem.cpp
+++ b/editor/txmgr/src/nsTransactionItem.cpp
@@ -100,59 +100,54 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTransactionItem, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTransactionItem, Release)
 
 nsresult
 nsTransactionItem::AddChild(nsTransactionItem *aTransactionItem)
 {
-  if (!aTransactionItem)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransactionItem, NS_ERROR_NULL_POINTER);
 
   if (!mUndoStack) {
     mUndoStack = new nsTransactionStack();
-    if (!mUndoStack)
-      return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(mUndoStack, NS_ERROR_OUT_OF_MEMORY);
   }
 
   mUndoStack->Push(aTransactionItem);
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetTransaction(nsITransaction **aTransaction)
 {
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   NS_IF_ADDREF(*aTransaction = mTransaction);
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetIsBatch(PRBool *aIsBatch)
 {
-  if (!aIsBatch)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER);
 
   *aIsBatch = !mTransaction;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetNumberOfChildren(PRInt32 *aNumChildren)
 {
   nsresult result;
 
-  if (!aNumChildren)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
 
   *aNumChildren = 0;
 
   PRInt32 ui = 0;
   PRInt32 ri = 0;
 
   result = GetNumberOfUndoItems(&ui);
 
@@ -167,18 +162,17 @@ nsTransactionItem::GetNumberOfChildren(P
   *aNumChildren = ui + ri;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetChild(PRInt32 aIndex, nsTransactionItem **aChild)
 {
-  if (!aChild)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aChild, NS_ERROR_NULL_POINTER);
 
   *aChild = 0;
 
   PRInt32 numItems = 0;
   nsresult result = GetNumberOfChildren(&numItems);
 
   if (NS_FAILED(result))
     return result;
@@ -192,33 +186,31 @@ nsTransactionItem::GetChild(PRInt32 aInd
   // be at the top of the redo stack.
 
   result = GetNumberOfUndoItems(&numItems);
 
   if (NS_FAILED(result))
     return result;
 
   if (numItems > 0 && aIndex < numItems) {
-    if (!mUndoStack)
-      return NS_ERROR_FAILURE;
+    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;
 
-  if (!mRedoStack || numItems == 0 || aIndex >= numItems)
-      return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mRedoStack && numItems != 0 && aIndex < numItems, NS_ERROR_FAILURE);
 
   return mRedoStack->GetItem(numItems - aIndex - 1, aChild);
 }
 
 nsresult
 nsTransactionItem::DoTransaction()
 {
   if (mTransaction)
@@ -231,18 +223,17 @@ nsTransactionItem::UndoTransaction(nsTra
 {
   nsresult result = UndoChildren(aTxMgr);
 
   if (NS_FAILED(result)) {
     RecoverFromUndoError(aTxMgr);
     return result;
   }
 
-  if (!mTransaction)
-    return NS_OK;
+  NS_ENSURE_TRUE(mTransaction, NS_OK);
 
   result = mTransaction->UndoTransaction();
 
   if (NS_FAILED(result)) {
     RecoverFromUndoError(aTxMgr);
     return result;
   }
 
@@ -254,18 +245,17 @@ nsTransactionItem::UndoChildren(nsTransa
 {
   nsRefPtr<nsTransactionItem> item;
   nsresult result = NS_OK;
   PRInt32 sz = 0;
 
   if (mUndoStack) {
     if (!mRedoStack && mUndoStack) {
       mRedoStack = new nsTransactionRedoStack();
-      if (!mRedoStack)
-        return NS_ERROR_OUT_OF_MEMORY;
+      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;
 
@@ -346,18 +336,17 @@ nsTransactionItem::RedoTransaction(nsTra
 
 nsresult
 nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
 {
   nsRefPtr<nsTransactionItem> item;
   nsresult result = NS_OK;
   PRInt32 sz = 0;
 
-  if (!mRedoStack)
-    return NS_OK;
+  NS_ENSURE_TRUE(mRedoStack, NS_OK);
 
   /* Redo all of the transaction items children! */
   result = mRedoStack->GetSize(&sz);
 
   if (NS_FAILED(result))
     return result;
 
 
@@ -409,32 +398,30 @@ nsTransactionItem::RedoChildren(nsTransa
   }
 
   return result;
 }
 
 nsresult
 nsTransactionItem::GetNumberOfUndoItems(PRInt32 *aNumItems)
 {
-  if (!aNumItems)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   if (!mUndoStack) {
     *aNumItems = 0;
     return NS_OK;
   }
 
   return mUndoStack->GetSize(aNumItems);
 }
 
 nsresult
 nsTransactionItem::GetNumberOfRedoItems(PRInt32 *aNumItems)
 {
-  if (!aNumItems)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   if (!mRedoStack) {
     *aNumItems = 0;
     return NS_OK;
   }
 
   return mRedoStack->GetSize(aNumItems);
 }
@@ -463,14 +450,13 @@ nsTransactionItem::RecoverFromRedoError(
   nsresult result;
 
   result = UndoChildren(aTxMgr);
 
   if (NS_FAILED(result)) {
     return result;
   }
 
-  if (!mTransaction)
-    return NS_OK;
+  NS_ENSURE_TRUE(mTransaction, NS_OK);
 
   return mTransaction->UndoTransaction();
 }
 
--- a/editor/txmgr/src/nsTransactionList.cpp
+++ b/editor/txmgr/src/nsTransactionList.cpp
@@ -62,159 +62,144 @@ nsTransactionList::~nsTransactionList()
 {
   mTxnStack = 0;
   mTxnItem  = 0;
 }
 
 /* readonly attribute long numItems; */
 NS_IMETHODIMP nsTransactionList::GetNumItems(PRInt32 *aNumItems)
 {
-  if (!aNumItems)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   *aNumItems = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
-  if (!txMgr)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   nsresult result = NS_ERROR_FAILURE;
 
   if (mTxnStack)
     result = mTxnStack->GetSize(aNumItems);
   else if (mTxnItem)
     result = mTxnItem->GetNumberOfChildren(aNumItems);
 
   return result;
 }
 
 /* boolean itemIsBatch (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::ItemIsBatch(PRInt32 aIndex, PRBool *aIsBatch)
 {
-  if (!aIsBatch)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER);
 
   *aIsBatch = PR_FALSE;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
-  if (!txMgr)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   nsRefPtr<nsTransactionItem> item;
 
   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;
 
-  if (!item)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetIsBatch(aIsBatch);
 }
 
 /* nsITransaction getItem (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::GetItem(PRInt32 aIndex, nsITransaction **aItem)
 {
-  if (!aItem)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aItem, NS_ERROR_NULL_POINTER);
 
   *aItem = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
-  if (!txMgr)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   nsRefPtr<nsTransactionItem> item;
 
   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;
 
-  if (!item)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetTransaction(aItem);
 }
 
 /* long getNumChildrenForItem (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(PRInt32 aIndex, PRInt32 *aNumChildren)
 {
-  if (!aNumChildren)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
 
   *aNumChildren = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
-  if (!txMgr)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   nsRefPtr<nsTransactionItem> item;
 
   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;
 
-  if (!item)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetNumberOfChildren(aNumChildren);
 }
 
 /* nsITransactionList getChildListForItem (in long aIndex); */
 NS_IMETHODIMP nsTransactionList::GetChildListForItem(PRInt32 aIndex, nsITransactionList **aTxnList)
 {
-  if (!aTxnList)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTxnList, NS_ERROR_NULL_POINTER);
 
   *aTxnList = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
-  if (!txMgr)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   nsRefPtr<nsTransactionItem> item;
 
   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;
 
-  if (!item)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   *aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item);
 
-  if (!*aTxnList)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxnList, NS_ERROR_OUT_OF_MEMORY);
 
   NS_ADDREF(*aTxnList);
 
   return NS_OK;
 }
 
--- a/editor/txmgr/src/nsTransactionManager.cpp
+++ b/editor/txmgr/src/nsTransactionManager.cpp
@@ -92,18 +92,17 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOU
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsTransactionManager,
                                            nsITransactionManager)
 
 NS_IMETHODIMP
 nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
 {
   nsresult result;
 
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   LOCK_TX_MANAGER(this);
 
   PRBool doInterrupt = PR_FALSE;
 
   result = WillDoNotify(aTransaction, &doInterrupt);
 
   if (NS_FAILED(result)) {
@@ -440,18 +439,17 @@ nsTransactionManager::GetNumberOfRedoIte
   UNLOCK_TX_MANAGER(this);
 
   return result;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::GetMaxTransactionCount(PRInt32 *aMaxCount)
 {
-  if (!aMaxCount)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMaxCount, NS_ERROR_NULL_POINTER);
 
   LOCK_TX_MANAGER(this);
   *aMaxCount = mMaxTransactionCount;
   UNLOCK_TX_MANAGER(this);
 
   return NS_OK;
 }
 
@@ -553,18 +551,17 @@ nsTransactionManager::SetMaxTransactionC
 }
 
 NS_IMETHODIMP
 nsTransactionManager::PeekUndoStack(nsITransaction **aTransaction)
 {
   nsRefPtr<nsTransactionItem> tx;
   nsresult result;
 
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   *aTransaction = 0;
 
   LOCK_TX_MANAGER(this);
 
   result = mUndoStack.Peek(getter_AddRefs(tx));
 
   if (NS_FAILED(result) || !tx) {
@@ -580,18 +577,17 @@ nsTransactionManager::PeekUndoStack(nsIT
 }
 
 NS_IMETHODIMP
 nsTransactionManager::PeekRedoStack(nsITransaction **aTransaction)
 {
   nsRefPtr<nsTransactionItem> tx;
   nsresult result;
 
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   *aTransaction = 0;
 
   LOCK_TX_MANAGER(this);
 
   result = mRedoStack.Peek(getter_AddRefs(tx));
 
   if (NS_FAILED(result) || !tx) {
@@ -604,59 +600,55 @@ nsTransactionManager::PeekRedoStack(nsIT
   UNLOCK_TX_MANAGER(this);
 
   return result;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::GetUndoList(nsITransactionList **aTransactionList)
 {
-  if (!aTransactionList)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransactionList, NS_ERROR_NULL_POINTER);
 
   *aTransactionList = (nsITransactionList *)new nsTransactionList(this, &mUndoStack);
 
   NS_IF_ADDREF(*aTransactionList);
 
   return (! *aTransactionList) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::GetRedoList(nsITransactionList **aTransactionList)
 {
-  if (!aTransactionList)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransactionList, NS_ERROR_NULL_POINTER);
 
   *aTransactionList = (nsITransactionList *)new nsTransactionList(this, &mRedoStack);
 
   NS_IF_ADDREF(*aTransactionList);
 
   return (! *aTransactionList) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::AddListener(nsITransactionListener *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   LOCK_TX_MANAGER(this);
 
   nsresult rv = mListeners.AppendObject(aListener) ? NS_OK : NS_ERROR_FAILURE;
 
   UNLOCK_TX_MANAGER(this);
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::RemoveListener(nsITransactionListener *aListener)
 {
-  if (!aListener)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
 
   LOCK_TX_MANAGER(this);
 
   nsresult rv = mListeners.RemoveObject(aListener) ? NS_OK : NS_ERROR_FAILURE;
 
   UNLOCK_TX_MANAGER(this);
 
   return rv;
@@ -689,18 +681,17 @@ nsTransactionManager::ClearRedoStack()
 nsresult
 nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, PRBool *aInterrupt)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->WillDo(this, aTransaction, aInterrupt);
     
     if (NS_FAILED(result) || *aInterrupt)
       break;
   }
 
   return result;
@@ -709,18 +700,17 @@ nsTransactionManager::WillDoNotify(nsITr
 nsresult
 nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResult)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->DidDo(this, aTransaction, aDoResult);
     
     if (NS_FAILED(result))
       break;
   }
 
   return result;
@@ -729,18 +719,17 @@ nsTransactionManager::DidDoNotify(nsITra
 nsresult
 nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, PRBool *aInterrupt)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->WillUndo(this, aTransaction, aInterrupt);
     
     if (NS_FAILED(result) || *aInterrupt)
       break;
   }
 
   return result;
@@ -749,18 +738,17 @@ nsTransactionManager::WillUndoNotify(nsI
 nsresult
 nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->DidUndo(this, aTransaction, aUndoResult);
     
     if (NS_FAILED(result))
       break;
   }
 
   return result;
@@ -769,18 +757,17 @@ nsTransactionManager::DidUndoNotify(nsIT
 nsresult
 nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, PRBool *aInterrupt)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->WillRedo(this, aTransaction, aInterrupt);
     
     if (NS_FAILED(result) || *aInterrupt)
       break;
   }
 
   return result;
@@ -789,18 +776,17 @@ nsTransactionManager::WillRedoNotify(nsI
 nsresult
 nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->DidRedo(this, aTransaction, aRedoResult);
     
     if (NS_FAILED(result))
       break;
   }
 
   return result;
@@ -809,18 +795,17 @@ nsTransactionManager::DidRedoNotify(nsIT
 nsresult
 nsTransactionManager::WillBeginBatchNotify(PRBool *aInterrupt)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->WillBeginBatch(this, aInterrupt);
     
     if (NS_FAILED(result) || *aInterrupt)
       break;
   }
 
   return result;
@@ -829,18 +814,17 @@ nsTransactionManager::WillBeginBatchNoti
 nsresult
 nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->DidBeginBatch(this, aResult);
     
     if (NS_FAILED(result))
       break;
   }
 
   return result;
@@ -849,18 +833,17 @@ nsTransactionManager::DidBeginBatchNotif
 nsresult
 nsTransactionManager::WillEndBatchNotify(PRBool *aInterrupt)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->WillEndBatch(this, aInterrupt);
     
     if (NS_FAILED(result) || *aInterrupt)
       break;
   }
 
   return result;
@@ -869,18 +852,17 @@ nsTransactionManager::WillEndBatchNotify
 nsresult
 nsTransactionManager::DidEndBatchNotify(nsresult aResult)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->DidEndBatch(this, aResult);
     
     if (NS_FAILED(result))
       break;
   }
 
   return result;
@@ -889,18 +871,17 @@ nsTransactionManager::DidEndBatchNotify(
 nsresult
 nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTransaction, PRBool *aInterrupt)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
     
     if (NS_FAILED(result) || *aInterrupt)
       break;
   }
 
   return result;
@@ -912,18 +893,17 @@ nsTransactionManager::DidMergeNotify(nsI
                                      PRBool aDidMerge,
                                      nsresult aMergeResult)
 {
   nsresult result = NS_OK;
   for (PRInt32 i = 0, lcount = mListeners.Count(); i < lcount; i++)
   {
     nsITransactionListener *listener = mListeners[i];
 
-    if (!listener)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
     result = listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
     
     if (NS_FAILED(result))
       break;
   }
 
   return result;
--- a/editor/txmgr/src/nsTransactionStack.cpp
+++ b/editor/txmgr/src/nsTransactionStack.cpp
@@ -50,77 +50,72 @@ nsTransactionStack::nsTransactionStack()
 nsTransactionStack::~nsTransactionStack()
 {
   Clear();
 }
 
 nsresult
 nsTransactionStack::Push(nsTransactionItem *aTransaction)
 {
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   /* nsDeque's Push() method adds new items at the back
    * of the deque.
    */
   NS_ADDREF(aTransaction);
   mQue.Push(aTransaction);
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionStack::Pop(nsTransactionItem **aTransaction)
 {
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   /* nsDeque is a FIFO, so the top of our stack is actually
    * the back of the deque.
    */
   *aTransaction = (nsTransactionItem *)mQue.Pop();
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionStack::PopBottom(nsTransactionItem **aTransaction)
 {
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   /* nsDeque is a FIFO, so the bottom of our stack is actually
    * the front of the deque.
    */
   *aTransaction = (nsTransactionItem *)mQue.PopFront();
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionStack::Peek(nsTransactionItem **aTransaction)
 {
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   if (!mQue.GetSize()) {
     *aTransaction = 0;
     return NS_OK;
   }
 
   NS_IF_ADDREF(*aTransaction = static_cast<nsTransactionItem*>(mQue.Last()));
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionStack::GetItem(PRInt32 aIndex, nsTransactionItem **aTransaction)
 {
-  if (!aTransaction)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   if (aIndex < 0 || aIndex >= mQue.GetSize())
     return NS_ERROR_FAILURE;
 
   NS_IF_ADDREF(*aTransaction =
                static_cast<nsTransactionItem*>(mQue.ObjectAt(aIndex)));
 
   return NS_OK;
@@ -147,18 +142,17 @@ nsTransactionStack::Clear(void)
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionStack::GetSize(PRInt32 *aStackSize)
 {
-  if (!aStackSize)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStackSize, NS_ERROR_NULL_POINTER);
 
   *aStackSize = mQue.GetSize();
 
   return NS_OK;
 }
 
 void
 nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb)
--- a/editor/txtsvc/src/nsFilteredContentIterator.cpp
+++ b/editor/txtsvc/src/nsFilteredContentIterator.cpp
@@ -249,26 +249,24 @@ ContentToParentOffset(nsIContent *aConte
 // ContentIsInTraversalRange: returns true if content is visited during
 // the traversal of the range in the specified mode.
 //
 static PRBool
 ContentIsInTraversalRange(nsIContent *aContent,   PRBool aIsPreMode,
                           nsIDOMNode *aStartNode, PRInt32 aStartOffset,
                           nsIDOMNode *aEndNode,   PRInt32 aEndOffset)
 {
-  if (!aStartNode || !aEndNode || !aContent)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(aStartNode && aEndNode && aContent, PR_FALSE);
 
   nsCOMPtr<nsIDOMNode> parentNode;
   PRInt32 indx = 0;
 
   ContentToParentOffset(aContent, getter_AddRefs(parentNode), &indx);
 
-  if (!parentNode)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(parentNode, PR_FALSE);
 
   if (!aIsPreMode)
     ++indx;
 
   PRInt32 startRes;
   PRInt32 endRes;
   nsresult rv = nsTextServicesDocument::ComparePoints(aStartNode, aStartOffset, parentNode, indx, &startRes);
   NS_ENSURE_SUCCESS(rv, PR_FALSE);
@@ -279,18 +277,17 @@ ContentIsInTraversalRange(nsIContent *aC
   return (startRes <= 0) && (endRes >= 0);
 }
 
 static PRBool
 ContentIsInTraversalRange(nsIDOMNSRange *aRange, nsIDOMNode* aNextNode, PRBool aIsPreMode)
 {
   nsCOMPtr<nsIContent>  content(do_QueryInterface(aNextNode));
   nsCOMPtr<nsIDOMRange> range(do_QueryInterface(aRange));
-  if (!content || !range)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(content && range, PR_FALSE);
 
 
 
   nsCOMPtr<nsIDOMNode> sNode;
   nsCOMPtr<nsIDOMNode> eNode;
   PRInt32 sOffset;
   PRInt32 eOffset;
   range->GetStartContainer(getter_AddRefs(sNode));
--- a/editor/txtsvc/src/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/src/nsTextServicesDocument.cpp
@@ -164,18 +164,17 @@ NS_IMPL_CYCLE_COLLECTION_7(nsTextService
 
 NS_IMETHODIMP
 nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor)
 {
   nsresult result = NS_OK;
   nsCOMPtr<nsISelectionController> selCon;
   nsCOMPtr<nsIDOMDocument> doc;
 
-  if (!aEditor)
-    return NS_ERROR_NULL_POINTER;
+  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));
 
@@ -241,22 +240,20 @@ nsTextServicesDocument::InitWithEditor(n
   UNLOCK_DOC(this);
 
   return result;
 }
 
 NS_IMETHODIMP 
 nsTextServicesDocument::GetDocument(nsIDOMDocument **aDoc)
 {
-  if (!aDoc)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
 
   *aDoc = nsnull; // init out param
-  if (!mDOMDocument)
-    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mDOMDocument, NS_ERROR_NOT_INITIALIZED);
 
   *aDoc = mDOMDocument;
   NS_ADDREF(*aDoc);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -476,23 +473,21 @@ nsTextServicesDocument::SetFilter(nsITex
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::GetCurrentTextBlock(nsString *aStr)
 {
   nsresult result;
 
-  if (!aStr)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStr, NS_ERROR_NULL_POINTER);
 
   aStr->Truncate();
 
-  if (!mIterator)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
                              mExtent, aStr);
 
   UNLOCK_DOC(this);
 
@@ -537,18 +532,17 @@ nsTextServicesDocument::FirstBlock()
 
 NS_IMETHODIMP
 nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus,
                                           PRInt32 *aSelOffset,
                                           PRInt32 *aSelLength)
 {
   nsresult result = NS_OK;
 
-  if (!aSelStatus || !aSelOffset || !aSelLength)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
 
   LOCK_DOC(this);
 
   mIteratorStatus = nsTextServicesDocument::eIsDone;
 
   *aSelStatus = nsITextServicesDocument::eBlockNotFound;
   *aSelOffset = *aSelLength = -1;
 
@@ -1010,18 +1004,17 @@ nsTextServicesDocument::LastSelectedBloc
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::PrevBlock()
 {
   nsresult result = NS_OK;
 
-  if (!mIterator)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone)
     return NS_OK;
 
   switch (mIteratorStatus)
   {
@@ -1082,18 +1075,17 @@ nsTextServicesDocument::PrevBlock()
   return result;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::NextBlock()
 {
   nsresult result = NS_OK;
 
-  if (!mIterator)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone)
     return NS_OK;
 
   switch (mIteratorStatus)
   {
@@ -1160,40 +1152,37 @@ nsTextServicesDocument::NextBlock()
   UNLOCK_DOC(this);
 
   return result;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::IsDone(PRBool *aIsDone)
 {
-  if (!aIsDone)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIsDone, NS_ERROR_NULL_POINTER);
 
   *aIsDone = PR_FALSE;
 
-  if (!mIterator)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   *aIsDone = (mIteratorStatus == nsTextServicesDocument::eIsDone) ? PR_TRUE : PR_FALSE;
 
   UNLOCK_DOC(this);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::SetSelection(PRInt32 aOffset, PRInt32 aLength)
 {
   nsresult result;
 
-  if (!mSelCon || aOffset < 0 || aLength < 0)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   result = SetSelectionInternal(aOffset, aLength, PR_TRUE);
 
   UNLOCK_DOC(this);
 
   //**** KDEBUG ****
@@ -1203,18 +1192,17 @@ nsTextServicesDocument::SetSelection(PRI
   return result;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::ScrollSelectionIntoView()
 {
   nsresult result;
 
-  if (!mSelCon)
-    return NS_ERROR_FAILURE;
+  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, PR_TRUE);
 
   UNLOCK_DOC(this);
@@ -1529,18 +1517,17 @@ nsTextServicesDocument::InsertText(const
   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;
 
-  if (!aText)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aText, NS_ERROR_NULL_POINTER);
 
   // If the selection is not collapsed, we need to save
   // off the selection offsets so we can restore the
   // selection and delete the selected content after we've
   // inserted the new text. This is necessary to try and
   // retain as much of the original style of the content
   // being deleted.
 
@@ -2037,18 +2024,17 @@ nsTextServicesDocument::DidJoinNodes(nsI
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::CreateContentIterator(nsIDOMRange *aRange, nsIContentIterator **aIterator)
 {
   nsresult result;
 
-  if (!aRange || !aIterator)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRange && aIterator, NS_ERROR_NULL_POINTER);
 
   *aIterator = 0;
 
   // Create a nsFilteredContentIterator
   // This class wraps the ContentIterator in order to give itself a chance 
   // to filter out certain content nodes
   nsFilteredContentIterator* filter = new nsFilteredContentIterator(mTxtSvcFilter);
   *aIterator = static_cast<nsIContentIterator *>(filter);
@@ -2056,18 +2042,17 @@ nsTextServicesDocument::CreateContentIte
     NS_IF_ADDREF(*aIterator);
     result = filter ? NS_OK : NS_ERROR_FAILURE;
   } else {
     delete filter;
     result = NS_ERROR_FAILURE;
   }
   NS_ENSURE_SUCCESS(result, result);
 
-  if (!*aIterator)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aIterator, NS_ERROR_NULL_POINTER);
 
   result = (*aIterator)->Init(aRange);
 
   if (NS_FAILED(result))
   {
     NS_RELEASE((*aIterator));
     *aIterator = 0;
     return result;
@@ -2076,88 +2061,81 @@ nsTextServicesDocument::CreateContentIte
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::GetDocumentContentRootNode(nsIDOMNode **aNode)
 {
   nsresult result;
 
-  if (!aNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   *aNode = 0;
 
-  if (!mDOMDocument)
-    return NS_ERROR_FAILURE;
+  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));
 
     if (NS_FAILED(result))
       return result;
 
-    if (!bodyElement)
-      return NS_ERROR_FAILURE;
+    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;
 
-    if (!docElement)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(docElement, NS_ERROR_FAILURE);
 
     result = docElement->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aNode);
   }
 
   return result;
 }
 
 nsresult
 nsTextServicesDocument::CreateDocumentContentRange(nsIDOMRange **aRange)
 {
   nsresult result;
 
-  if (!aRange)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRange, NS_ERROR_NULL_POINTER);
 
   *aRange = 0;
 
   nsCOMPtr<nsIDOMNode>node;
 
   result = GetDocumentContentRootNode(getter_AddRefs(node));
 
   if (NS_FAILED(result))
     return result;
 
-  if (!node)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
 
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
   if (NS_FAILED(result))
     return result;
 
-  if (!*aRange)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SelectNodeContents(node);
 
   if (NS_FAILED(result))
   {
     NS_RELEASE((*aRange));
     *aRange = 0;
     return result;
@@ -2166,35 +2144,33 @@ nsTextServicesDocument::CreateDocumentCo
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::CreateDocumentContentRootToNodeOffsetRange(nsIDOMNode *aParent, PRInt32 aOffset, PRBool aToStart, nsIDOMRange **aRange)
 {
   nsresult result;
 
-  if (!aParent || !aRange)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aParent && aRange, NS_ERROR_NULL_POINTER);
 
   *aRange = 0;
 
   NS_ASSERTION(aOffset >= 0, "Invalid offset!");
 
   if (aOffset < 0)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMNode> bodyNode; 
 
   result = GetDocumentContentRootNode(getter_AddRefs(bodyNode));
 
   if (NS_FAILED(result))
     return result;
 
-  if (!bodyNode)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(bodyNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> startNode;
   nsCOMPtr<nsIDOMNode> endNode;
   PRInt32 startOffset, endOffset;
 
   if (aToStart)
   {
     // The range should begin at the start of the document
@@ -2233,18 +2209,17 @@ nsTextServicesDocument::CreateDocumentCo
       endOffset = (PRInt32)nodeListLength;
     }
   }
 
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
   if (NS_FAILED(result))
     return result;
 
-  if (!*aRange)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SetStart(startNode, startOffset);
 
   if (NS_SUCCEEDED(result))
     result = (*aRange)->SetEnd(endNode, endOffset);
 
   if (NS_FAILED(result))
   {
@@ -2255,18 +2230,17 @@ nsTextServicesDocument::CreateDocumentCo
   return result;
 }
 
 nsresult
 nsTextServicesDocument::CreateDocumentContentIterator(nsIContentIterator **aIterator)
 {
   nsresult result;
 
-  if (!aIterator)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMRange> range;
 
   result = CreateDocumentContentRange(getter_AddRefs(range));
 
   if (NS_FAILED(result))
     return result;
 
@@ -2275,38 +2249,35 @@ nsTextServicesDocument::CreateDocumentCo
   return result;
 }
 
 nsresult
 nsTextServicesDocument::AdjustContentIterator()
 {
   nsresult result = NS_OK;
 
-  if (!mIterator)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(mIterator->GetCurrentNode()));
 
-  if (!node)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
   nsIDOMNode *nodePtr = node.get();
   PRInt32 tcount      = mOffsetTable.Length();
 
   nsIDOMNode *prevValidNode = 0;
   nsIDOMNode *nextValidNode = 0;
   PRBool foundEntry = PR_FALSE;
   OffsetEntry *entry;
 
   for (PRInt32 i = 0; i < tcount && !nextValidNode; i++)
   {
     entry = mOffsetTable[i];
 
-    if (!entry)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
 
     if (entry->mNode == nodePtr)
     {
       if (entry->mIsValid)
       {
         // The iterator is still pointing to something valid!
         // Do nothing!
 
@@ -2470,47 +2441,44 @@ nsTextServicesDocument::HasSameBlockNode
   }
 
   return p1 == p2;
 }
 
 PRBool
 nsTextServicesDocument::IsTextNode(nsIContent *aContent)
 {
-  if (!aContent)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(aContent, PR_FALSE);
 
   nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aContent);
 
   return IsTextNode(node);
 }
 
 PRBool
 nsTextServicesDocument::IsTextNode(nsIDOMNode *aNode)
 {
-  if (!aNode)
-    return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
 
   PRUint16 type;
 
   nsresult result = aNode->GetNodeType(&type);
 
   if (NS_FAILED(result))
     return PR_FALSE;
 
   return nsIDOMNode::TEXT_NODE == type;
 }
 
 nsresult
 nsTextServicesDocument::SetSelectionInternal(PRInt32 aOffset, PRInt32 aLength, PRBool aDoUpdate)
 {
   nsresult result = NS_OK;
 
-  if (!mSelCon || aOffset < 0 || aLength < 0)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
 
   nsIDOMNode *sNode = 0, *eNode = 0;
   PRInt32 i, sOffset = 0, eOffset = 0;
   OffsetEntry *entry;
 
   // Find start of selection in node offset terms:
 
   for (i = 0; !sNode && i < PRInt32(mOffsetTable.Length()); i++)
@@ -2567,18 +2535,17 @@ nsTextServicesDocument::SetSelectionInte
       if (sNode)
       {
         mSelStartIndex  = i;
         mSelStartOffset = aOffset;
       }
     }
   }
 
-  if (!sNode)
-    return NS_ERROR_FAILURE;
+  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)
   {
@@ -2657,39 +2624,36 @@ nsTextServicesDocument::SetSelectionInte
   return result;
 }
 
 nsresult
 nsTextServicesDocument::GetSelection(nsITextServicesDocument::TSDBlockSelectionStatus *aSelStatus, PRInt32 *aSelOffset, PRInt32 *aSelLength)
 {
   nsresult result;
 
-  if (!aSelStatus || !aSelOffset || !aSelLength)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
 
   *aSelStatus = nsITextServicesDocument::eBlockNotFound;
   *aSelOffset = -1;
   *aSelLength = -1;
 
-  if (!mDOMDocument || !mSelCon)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mDOMDocument && mSelCon, NS_ERROR_FAILURE);
 
   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;
 
-  if (!selection)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   result = selection->GetIsCollapsed(&isCollapsed);
 
   if (NS_FAILED(result))
     return result;
 
   // XXX: If we expose this method publicly, we need to
   //      add LOCK_DOC/UNLOCK_DOC calls!
@@ -2712,18 +2676,17 @@ nsTextServicesDocument::GetCollapsedSele
   nsresult result;
   nsCOMPtr<nsISelection> selection;
 
   result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
 
   if (NS_FAILED(result))
     return result;
 
-  if (!selection)
-    return NS_ERROR_FAILURE;
+  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;
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset, tableCount, i;
@@ -2792,18 +2755,17 @@ nsTextServicesDocument::GetCollapsedSele
     // Good news, the caret is in a text node. Look
     // through the offset table for the entry that
     // matches it's parent and offset.
 
     for (i = 0; i < tableCount; i++)
     {
       entry = mOffsetTable[i];
 
-      if (!entry)
-        return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
 
       if (entry->mNode == parent.get() &&
           entry->mNodeOffset <= offset && offset <= (entry->mNodeOffset + entry->mLength))
       {
         *aSelStatus = nsITextServicesDocument::eBlockContains;
         *aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset);
         *aSelLength = 0;
 
@@ -2854,18 +2816,17 @@ nsTextServicesDocument::GetCollapsedSele
 
     PRUint32 childIndex = (PRUint32)offset;
 
     result = parent->GetChildNodes(getter_AddRefs(children));
 
     if (NS_FAILED(result))
       return result;
 
-    if (!children)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(children, NS_ERROR_FAILURE);
 
     if (childIndex > 0)
     {
       PRUint32 numChildren;
 
       result = children->GetLength(&numChildren);
 
       if (NS_FAILED(result))
@@ -2881,33 +2842,31 @@ nsTextServicesDocument::GetCollapsedSele
 
     result = children->Item(childIndex, getter_AddRefs(saveNode));
 
     if (NS_FAILED(result))
       return result;
 
     nsCOMPtr<nsIContent> content(do_QueryInterface(saveNode));
 
-    if (!content)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
     result = iter->PositionAt(content);
 
     if (NS_FAILED(result))
       return result;
   }
   else
   {
     // The parent has no children, so position the iterator
     // on the parent.
 
     nsCOMPtr<nsIContent> content(do_QueryInterface(parent));
 
-    if (!content)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
     result = iter->PositionAt(content);
 
     if (NS_FAILED(result))
       return result;
 
     saveNode = parent;
   }
@@ -2919,18 +2878,17 @@ nsTextServicesDocument::GetCollapsedSele
   while (!iter->IsDone())
   {
     nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
 
     if (IsTextNode(content))
     {
       node = do_QueryInterface(content);
 
-      if (!node)
-        return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
       break;
     }
 
     node = nsnull;
 
     iter->Prev();
   }
@@ -2968,42 +2926,39 @@ nsTextServicesDocument::GetCollapsedSele
     while (!iter->IsDone())
     {
       nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
 
       if (IsTextNode(content))
       {
         node = do_QueryInterface(content);
 
-        if (!node)
-          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
         break;
       }
 
       node = nsnull;
 
       iter->Next();
     }
 
-    if (!node)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
     // We found a text node, so set the offset to
     // the begining of the node.
 
     offset = 0;
   }
 
   for (i = 0; i < tableCount; i++)
   {
     entry = mOffsetTable[i];
 
-    if (!entry)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
 
     if (entry->mNode == node.get() &&
         entry->mNodeOffset <= offset && offset <= (entry->mNodeOffset + entry->mLength))
     {
       *aSelStatus = nsITextServicesDocument::eBlockContains;
       *aSelOffset = entry->mStrOffset + (offset - entry->mNodeOffset);
       *aSelLength = 0;
 
@@ -3031,18 +2986,17 @@ nsTextServicesDocument::GetUncollapsedSe
   nsCOMPtr<nsIDOMRange> range;
   OffsetEntry *entry;
 
   result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
 
   if (NS_FAILED(result))
     return result;
 
-  if (!selection)
-    return NS_ERROR_FAILURE;
+  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;
   PRInt32 startOffset, endOffset;
   PRInt32 rangeCount, tableCount, i;
@@ -3217,30 +3171,28 @@ nsTextServicesDocument::GetUncollapsedSe
     while (!iter->IsDone())
     {
       content = do_QueryInterface(iter->GetCurrentNode());
 
       if (IsTextNode(content))
       {
         p1 = do_QueryInterface(content);
 
-        if (!p1)
-          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(p1, NS_ERROR_FAILURE);
 
         o1 = 0;
         found = PR_TRUE;
 
         break;
       }
 
       iter->Next();
     }
 
-    if (!found)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(found, NS_ERROR_FAILURE);
   }
 
   // Find the last text node in the range.
 
   iter->Last();
 
   if (! IsTextNode(p2))
   {
@@ -3249,18 +3201,17 @@ nsTextServicesDocument::GetUncollapsedSe
     while (!iter->IsDone())
     {
       content = do_QueryInterface(iter->GetCurrentNode());
 
       if (IsTextNode(content))
       {
         p2 = do_QueryInterface(content);
 
-        if (!p2)
-          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(p2, NS_ERROR_FAILURE);
 
         nsString str;
 
         result = p2->GetNodeValue(str);
 
         if (NS_FAILED(result))
           return result;
 
@@ -3268,29 +3219,27 @@ nsTextServicesDocument::GetUncollapsedSe
         found = PR_TRUE;
 
         break;
       }
 
       iter->Prev();
     }
 
-    if (!found)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(found, NS_ERROR_FAILURE);
   }
 
   found    = PR_FALSE;
   *aSelLength = 0;
 
   for (i = 0; i < tableCount; i++)
   {
     entry = mOffsetTable[i];
 
-    if (!entry)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
 
     if (!found)
     {
       if (entry->mNode == p1.get() &&
           entry->mNodeOffset <= o1 && o1 <= (entry->mNodeOffset + entry->mLength))
       {
         *aSelOffset = entry->mStrOffset + (o1 - entry->mNodeOffset);
 
@@ -3354,55 +3303,51 @@ nsTextServicesDocument::ComparePoints(ns
                                       nsIDOMNode* aParent2, PRInt32 aOffset2,
                                       PRInt32 *aResult)
 {
   nsresult result;
   
   if (!sRangeHelper) {
     result = CallGetService("@mozilla.org/content/range-utils;1",
                             &sRangeHelper);
-    if (!sRangeHelper)
-      return result;
+    NS_ENSURE_TRUE(sRangeHelper, result);
   }
 
   *aResult = sRangeHelper->ComparePoints(aParent1, aOffset1,
                                          aParent2, aOffset2);
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::GetRangeEndPoints(nsIDOMRange *aRange,
                                           nsIDOMNode **aStartParent, PRInt32 *aStartOffset,
                                           nsIDOMNode **aEndParent, PRInt32 *aEndOffset)
 {
   nsresult result;
 
-  if (!aRange || !aStartParent || !aStartOffset || !aEndParent || !aEndOffset)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRange && aStartParent && aStartOffset && aEndParent && aEndOffset, NS_ERROR_NULL_POINTER);
 
   result = aRange->GetStartContainer(aStartParent);
 
   if (NS_FAILED(result))
     return result;
 
-  if (!aStartParent)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aStartParent, NS_ERROR_FAILURE);
 
   result = aRange->GetStartOffset(aStartOffset);
 
   if (NS_FAILED(result))
     return result;
 
   result = aRange->GetEndContainer(aEndParent);
 
   if (NS_FAILED(result))
     return result;
 
-  if (!aEndParent)
-    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(aEndParent, NS_ERROR_FAILURE);
 
   result = aRange->GetEndOffset(aEndOffset);
 
   return result;
 }
 
 
 nsresult
@@ -3411,18 +3356,17 @@ nsTextServicesDocument::CreateRange(nsID
                                     nsIDOMRange **aRange)
 {
   nsresult result;
 
   result = CallCreateInstance("@mozilla.org/content/range;1", aRange);
   if (NS_FAILED(result))
     return result;
 
-  if (!*aRange)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aRange, NS_ERROR_NULL_POINTER);
 
   result = (*aRange)->SetStart(aStartParent, aStartOffset);
 
   if (NS_SUCCEEDED(result))
     result = (*aRange)->SetEnd(aEndParent, aEndOffset);
 
   if (NS_FAILED(result))
   {
@@ -3483,18 +3427,17 @@ nsTextServicesDocument::LastTextNode(nsI
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::FirstTextNodeInCurrentBlock(nsIContentIterator *iter)
 {
-  if (!iter)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
 
   ClearDidSkip(iter);
 
   nsCOMPtr<nsIContent> last;
 
   // Walk backwards over adjacent text nodes until
   // we hit a block boundary:
 
@@ -3531,18 +3474,17 @@ nsTextServicesDocument::FirstTextNodeInC
 }
 
 nsresult
 nsTextServicesDocument::FirstTextNodeInPrevBlock(nsIContentIterator *aIterator)
 {
   nsCOMPtr<nsIContent> content;
   nsresult result;
 
-  if (!aIterator)
-    return NS_ERROR_NULL_POINTER;
+  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);
 
@@ -3562,18 +3504,17 @@ nsTextServicesDocument::FirstTextNodeInP
 }
 
 nsresult
 nsTextServicesDocument::FirstTextNodeInNextBlock(nsIContentIterator *aIterator)
 {
   nsCOMPtr<nsIContent> prev;
   PRBool crossedBlockBoundary = PR_FALSE;
 
-  if (!aIterator)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   ClearDidSkip(aIterator);
 
   while (!aIterator->IsDone())
   {
     nsCOMPtr<nsIContent> content = do_QueryInterface(aIterator->GetCurrentNode());
 
     if (IsTextNode(content))
@@ -3595,18 +3536,17 @@ nsTextServicesDocument::FirstTextNodeInN
   return NS_OK;
 }
 
 nsresult
 nsTextServicesDocument::GetFirstTextNodeInPrevBlock(nsIContent **aContent)
 {
   nsresult result;
 
-  if (!aContent)
-    return NS_ERROR_NULL_POINTER;
+  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();
 
@@ -3630,18 +3570,17 @@ nsTextServicesDocument::GetFirstTextNode
   return mIterator->PositionAt(node);
 }
 
 nsresult
 nsTextServicesDocument::GetFirstTextNodeInNextBlock(nsIContent **aContent)
 {
   nsresult result;
 
-  if (!aContent)
-    return NS_ERROR_NULL_POINTER;
+  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();
 
@@ -3671,18 +3610,17 @@ nsTextServicesDocument::CreateOffsetTabl
                                           nsIDOMRange *aIterRange,
                                           nsString *aStr)
 {
   nsresult result = NS_OK;
 
   nsCOMPtr<nsIContent> first;
   nsCOMPtr<nsIContent> prev;
 
-  if (!aIterator)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aIterator, NS_ERROR_NULL_POINTER);
 
   ClearOffsetTable(aOffsetTable);
 
   if (aStr)
     aStr->Truncate();
 
   if (*aIteratorStatus == nsTextServicesDocument::eIsDone)
     return NS_OK;
@@ -3734,18 +3672,17 @@ nsTextServicesDocument::CreateOffsetTabl
 
           if (NS_FAILED(result))
             return result;
 
           // Add an entry for this text node into the offset table:
 
           OffsetEntry *entry = new OffsetEntry(node, offset, str.Length());
 
-          if (!entry)
-            return NS_ERROR_OUT_OF_MEMORY;
+          NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
 
           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
           // only accounts for the portion of the text node that is
           // in the range.
 
@@ -3881,18 +3818,17 @@ nsTextServicesDocument::SplitOffsetEntry
     return NS_ERROR_FAILURE;
 
   PRInt32 oldLength = entry->mLength - aNewEntryLength;
 
   OffsetEntry *newEntry = new OffsetEntry(entry->mNode,
                                           entry->mStrOffset + oldLength,
                                           aNewEntryLength);
 
-  if (!newEntry)
-    return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(newEntry, NS_ERROR_OUT_OF_MEMORY);
 
   if (!mOffsetTable.InsertElementAt(aTableIndex + 1, newEntry))
   {
     delete newEntry;
     return NS_ERROR_FAILURE;
   }
 
    // Adjust entry fields:
@@ -3904,25 +3840,23 @@ nsTextServicesDocument::SplitOffsetEntry
 }
 
 nsresult
 nsTextServicesDocument::NodeHasOffsetEntry(nsTArray<OffsetEntry*> *aOffsetTable, nsIDOMNode *aNode, PRBool *aHasEntry, PRInt32 *aEntryIndex)
 {
   OffsetEntry *entry;
   PRUint32 i;
 
-  if (!aNode || !aHasEntry || !aEntryIndex)
-    return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aHasEntry && aEntryIndex, NS_ERROR_NULL_POINTER);
 
   for (i = 0; i < aOffsetTable->Length(); i++)
   {
     entry = (*aOffsetTable)[i];
 
-    if (!entry)
-      return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(entry, NS_ERROR_FAILURE);
 
     if (entry->mNode == aNode)
     {
       *aHasEntry   = PR_TRUE;
       *aEntryIndex = i;
 
       return NS_OK;
     }