Bug 572618 - Make debugging the editor easier - Part 2: Replace all if(!foo) return NS_ERROR_bar checks with NS_ENSURE_TRUE(foo, NS_ERROR_bar); r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 17 Jun 2010 15:41:16 -0400
changeset 43806 223b2b67edbd8da65198571534d75dd0c5431031
parent 43805 8d5a112a3091fc8b074dbac8dd9a2ac1b449ffca
child 43807 bebdf341352258d8aa5967b9325188e31731e1ad
push id13904
push usereakhgari@mozilla.com
push dateFri, 18 Jun 2010 17:14:53 +0000
treeherdermozilla-central@45dd34892448 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs572618
milestone1.9.3a6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 572618 - Make debugging the editor easier - Part 2: Replace all if(!foo) return NS_ERROR_bar checks with NS_ENSURE_TRUE(foo, NS_ERROR_bar); r=roc
editor/composer/src/nsComposerCommands.cpp
editor/composer/src/nsComposerCommandsUpdater.cpp
editor/composer/src/nsComposerController.cpp
editor/composer/src/nsComposerDocumentCommands.cpp
editor/composer/src/nsEditingSession.cpp
editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp
editor/libeditor/base/CreateElementTxn.cpp
editor/libeditor/base/DeleteElementTxn.cpp
editor/libeditor/base/DeleteRangeTxn.cpp
editor/libeditor/base/DeleteTextTxn.cpp
editor/libeditor/base/IMETextTxn.cpp
editor/libeditor/base/InsertElementTxn.cpp
editor/libeditor/base/InsertTextTxn.cpp
editor/libeditor/base/JoinElementTxn.cpp
editor/libeditor/base/PlaceholderTxn.cpp
editor/libeditor/base/SetDocTitleTxn.cpp
editor/libeditor/base/SplitElementTxn.cpp
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditorCommands.cpp
editor/libeditor/base/nsEditorController.cpp
editor/libeditor/base/nsEditorEventListener.cpp
editor/libeditor/base/nsEditorUtils.cpp
editor/libeditor/base/nsSelectionState.cpp
editor/libeditor/html/TypeInState.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/nsHTMLEditUtils.cpp
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/html/nsHTMLEditorEventListener.cpp
editor/libeditor/html/nsHTMLEditorStyle.cpp
editor/libeditor/html/nsHTMLInlineTableEditor.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
--- a/editor/composer/src/nsComposerCommands.cpp
+++ b/editor/composer/src/nsComposerCommands.cpp
@@ -114,17 +114,17 @@ nsBaseStateUpdatingCommand::IsCommandEna
 }
 
 
 NS_IMETHODIMP
 nsBaseStateUpdatingCommand::DoCommand(const char *aCommandName,
                                       nsISupports *refCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (!editor) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(editor, NS_ERROR_NOT_INITIALIZED);
 
   return ToggleState(editor, mTagName);
 }
 
 NS_IMETHODIMP
 nsBaseStateUpdatingCommand::DoCommandParams(const char *aCommandName,
                                             nsICommandParams *aParams,
                                             nsISupports *refCon)
@@ -211,17 +211,17 @@ nsStyleUpdatingCommand::nsStyleUpdatingC
 
 nsresult
 nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, 
                                         const char* aTagName,
                                         nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_INITIALIZED);
   
   nsresult rv = NS_OK;
 
   PRBool firstOfSelectionHasProp = PR_FALSE;
   PRBool anyOfSelectionHasProp = PR_FALSE;
   PRBool allOfSelectionHasProp = PR_FALSE;
 
   nsCOMPtr<nsIAtom> styleAtom = do_GetAtom(aTagName);
@@ -396,17 +396,17 @@ nsListItemCommand::GetCurrentState(nsIEd
   return NS_OK;
 }
 
 nsresult
 nsListItemCommand::ToggleState(nsIEditor *aEditor, const char* aTagName)
 {
   NS_ASSERTION(aEditor, "Need editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_INITIALIZED);
 
   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;
@@ -694,17 +694,17 @@ nsParagraphStateCommand::nsParagraphStat
 
 nsresult
 nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor,
                                          nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   PRBool outMixed;
   nsAutoString outStateString;
   nsresult rv = htmlEditor->GetParagraphState(&outMixed, outStateString);
   if (NS_SUCCEEDED(rv))
   {
     nsCAutoString tOutStateString;
     tOutStateString.AssignWithConversion(outStateString);
@@ -715,17 +715,17 @@ nsParagraphStateCommand::GetCurrentState
 }
 
 
 nsresult
 nsParagraphStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   return htmlEditor->SetParagraphFormat(newState);
 }
 
 #ifdef XP_MAC
 #pragma mark -
 #endif
 
@@ -735,17 +735,17 @@ nsFontFaceStateCommand::nsFontFaceStateC
 }
 
 nsresult
 nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor,
                                         nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   nsAutoString outStateString;
   PRBool outMixed;
   nsresult rv = htmlEditor->GetFontFaceState(&outMixed, outStateString);
   if (NS_SUCCEEDED(rv))
   {
     aParams->SetBooleanValue(STATE_MIXED,outMixed);
     aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get());
@@ -754,17 +754,17 @@ nsFontFaceStateCommand::GetCurrentState(
 }
 
 
 nsresult
 nsFontFaceStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
   
   nsresult rv;
   nsCOMPtr<nsIAtom> ttAtom = do_GetAtom("tt");
   nsCOMPtr<nsIAtom> fontAtom = do_GetAtom("font");
 
   if (newState.EqualsLiteral("tt"))
   {
     // The old "teletype" attribute  
@@ -801,17 +801,17 @@ nsFontSizeStateCommand::nsFontSizeStateC
 //  nsCAutoString tOutStateString;
 //  tOutStateString.AssignWithConversion(outStateString);
 nsresult
 nsFontSizeStateCommand::GetCurrentState(nsIEditor *aEditor,
                                         nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_INVALID_ARG);
 
   nsAutoString outStateString;
   nsCOMPtr<nsIAtom> fontAtom = do_GetAtom("font");
   PRBool firstHas, anyHas, allHas;
   nsresult rv = htmlEditor->GetInlinePropertyWithAttrValue(fontAtom,
                                          NS_LITERAL_STRING("size"),
                                          EmptyString(),
                                          &firstHas, &anyHas, &allHas,
@@ -837,17 +837,17 @@ nsFontSizeStateCommand::GetCurrentState(
 //   +3
 //   medium
 //   normal
 nsresult
 nsFontSizeStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_INVALID_ARG);
 
   nsresult rv;
   nsCOMPtr<nsIAtom> fontAtom = do_GetAtom("font");
   if (newState.IsEmpty() || 
       newState.EqualsLiteral("normal") ||
       newState.EqualsLiteral("medium")) {
     // remove any existing font size, big or small
     rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("size"));  
@@ -879,17 +879,17 @@ nsFontColorStateCommand::nsFontColorStat
 
 nsresult
 nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor,
                                          nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   PRBool outMixed;
   nsAutoString outStateString;
   nsresult rv = htmlEditor->GetFontColorState(&outMixed, outStateString);
   if (NS_SUCCEEDED(rv))
   {
     nsCAutoString tOutStateString;
     tOutStateString.AssignWithConversion(outStateString);
@@ -899,17 +899,17 @@ nsFontColorStateCommand::GetCurrentState
   return rv;
 }
 
 nsresult
 nsFontColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
   
   nsresult rv;
   nsCOMPtr<nsIAtom> fontAtom = do_GetAtom("font");
 
   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
     rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("color"));
   } else {
     rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("color"), 
@@ -929,17 +929,17 @@ nsHighlightColorStateCommand::nsHighligh
 }
 
 nsresult
 nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor,
                                               nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   PRBool outMixed;
   nsAutoString outStateString;
   nsresult rv = htmlEditor->GetHighlightColorState(&outMixed, outStateString);
   if (NS_SUCCEEDED(rv))
   {
     nsCAutoString tOutStateString;
     tOutStateString.AssignWithConversion(outStateString);
@@ -949,17 +949,17 @@ nsHighlightColorStateCommand::GetCurrent
   return rv;
 }
 
 nsresult
 nsHighlightColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   nsresult rv;
   nsCOMPtr<nsIAtom> fontAtom = do_GetAtom("font");
 
   if (newState.IsEmpty() || newState.EqualsLiteral("normal")) {
 //    rv = RemoveOneProperty(htmlEditor, NS_LITERAL_STRING("font"), NS_LITERAL_STRING("bgcolor"));
     rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"));
   } else {
@@ -992,17 +992,17 @@ nsBackgroundColorStateCommand::nsBackgro
 
 nsresult
 nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor,
                                                nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   PRBool outMixed;
   nsAutoString outStateString;
   nsresult rv =  htmlEditor->GetBackgroundColorState(&outMixed, outStateString);
   if (NS_SUCCEEDED(rv))
   {
     nsCAutoString tOutStateString;
     tOutStateString.AssignWithConversion(outStateString);
@@ -1013,17 +1013,17 @@ nsBackgroundColorStateCommand::GetCurren
 }
 
 nsresult
 nsBackgroundColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   return htmlEditor->SetBackgroundColor(newState);
 }
 
 #ifdef XP_MAC
 #pragma mark -
 #endif
 
@@ -1033,17 +1033,17 @@ nsAlignCommand::nsAlignCommand()
 }
 
 nsresult
 nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
  
   nsIHTMLEditor::EAlignment firstAlign;
   PRBool outMixed;
   nsresult rv = htmlEditor->GetAlignment(&outMixed, &firstAlign);
   
   if (NS_FAILED(rv)) 
     return rv;
   
@@ -1075,17 +1075,17 @@ nsAlignCommand::GetCurrentState(nsIEdito
 }
 
 nsresult
 nsAlignCommand::SetState(nsIEditor *aEditor, nsString& newState)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   return htmlEditor->Align(newState);
 }
 
 
 #ifdef XP_MAC
 #pragma mark -
 #endif
@@ -1099,29 +1099,29 @@ nsAbsolutePositioningCommand::nsAbsolute
 NS_IMETHODIMP
 nsAbsolutePositioningCommand::IsCommandEnabled(const char * aCommandName,
                                                nsISupports *aCommandRefCon,
                                                PRBool *_retval)
 {
   NS_ASSERTION(aCommandRefCon, "Need an editor here");
   
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aCommandRefCon);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   htmlEditor->GetAbsolutePositioningEnabled(_retval);
   return NS_OK;
 }
 
 nsresult
 nsAbsolutePositioningCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   PRBool isEnabled;
   htmlEditor->GetAbsolutePositioningEnabled(&isEnabled);
   if (!isEnabled) {
     aParams->SetBooleanValue(STATE_MIXED,PR_FALSE);
     aParams->SetCStringValue(STATE_ATTRIBUTE, "");
     return NS_OK;
   }
@@ -1141,17 +1141,17 @@ nsAbsolutePositioningCommand::GetCurrent
 }
 
 nsresult
 nsAbsolutePositioningCommand::ToggleState(nsIEditor *aEditor, const char* aTagName)
 {
   NS_ASSERTION(aEditor, "Need an editor here");
   
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aEditor);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMElement>  elt;
   nsresult rv = htmlEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (elt) {
     // we have to remove positioning on an element
     rv = htmlEditor->AbsolutePositionSelection(PR_FALSE);
@@ -1168,17 +1168,17 @@ nsAbsolutePositioningCommand::ToggleStat
 #endif
 
 NS_IMETHODIMP
 nsDecreaseZIndexCommand::IsCommandEnabled(const char * aCommandName,
                                           nsISupports *refCon,
                                           PRBool *outCmdEnabled)
 {
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   htmlEditor->GetAbsolutePositioningEnabled(outCmdEnabled);
   if (!(*outCmdEnabled))
     return NS_OK;
 
   nsCOMPtr<nsIDOMElement> positionedElement;
   htmlEditor->GetPositionedElement(getter_AddRefs(positionedElement));
   *outCmdEnabled = PR_FALSE;
@@ -1230,17 +1230,17 @@ nsDecreaseZIndexCommand::GetCommandState
 #endif
 
 NS_IMETHODIMP
 nsIncreaseZIndexCommand::IsCommandEnabled(const char * aCommandName,
                                           nsISupports *refCon,
                                           PRBool *outCmdEnabled)
 {
   nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon);
-  if (!htmlEditor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   htmlEditor->GetAbsolutePositioningEnabled(outCmdEnabled);
   if (!(*outCmdEnabled))
     return NS_OK;
 
   nsCOMPtr<nsIDOMElement> positionedElement;
   htmlEditor->GetPositionedElement(getter_AddRefs(positionedElement));
   *outCmdEnabled = (nsnull != positionedElement);
--- a/editor/composer/src/nsComposerCommandsUpdater.cpp
+++ b/editor/composer/src/nsComposerCommandsUpdater.cpp
@@ -299,17 +299,17 @@ nsComposerCommandsUpdater::UpdateDirtySt
   
   return NS_OK;  
 }
 
 nsresult
 nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
 {
   nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater();
-  if (!commandUpdater) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
 
   
   // This hardcoded list of commands is temporary.
   // This code should use nsIControllerCommandGroup.
   if (aCommandGroup.EqualsLiteral("undo"))
   {
     commandUpdater->CommandStatusChanged("cmd_undo");
     commandUpdater->CommandStatusChanged("cmd_redo");
@@ -353,17 +353,17 @@ nsComposerCommandsUpdater::UpdateCommand
   }
   return NS_OK;  
 }
 
 nsresult
 nsComposerCommandsUpdater::UpdateOneCommand(const char *aCommand)
 {
   nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater();
-  if (!commandUpdater) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
 
   commandUpdater->CommandStatusChanged(aCommand);
 
   return NS_OK;  
 }
 
 PRBool
 nsComposerCommandsUpdater::SelectionIsCollapsed()
--- a/editor/composer/src/nsComposerController.cpp
+++ b/editor/composer/src/nsComposerController.cpp
@@ -41,50 +41,50 @@
 #include "nsIControllerCommandTable.h"
 #include "nsComposerController.h"
 #include "nsComposerCommands.h"
 
 #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName)                    \
   {                                                                     \
     _cmdClass* theCmd;                                                  \
     NS_NEWXPCOM(theCmd, _cmdClass);                                     \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
+    NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY);                         \
     rv = inCommandTable->RegisterCommand(_cmdName,                      \
                        static_cast<nsIControllerCommand *>(theCmd));    \
   }
 
 #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName)                  \
   {                                                                     \
     _cmdClass* theCmd;                                                  \
     NS_NEWXPCOM(theCmd, _cmdClass);                                     \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
+    NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY);                         \
     rv = inCommandTable->RegisterCommand(_cmdName,                      \
                        static_cast<nsIControllerCommand *>(theCmd));
 
 #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName)                   \
     rv = inCommandTable->RegisterCommand(_cmdName,                      \
                         static_cast<nsIControllerCommand *>(theCmd));
 
 #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName)                   \
     rv = inCommandTable->RegisterCommand(_cmdName,                      \
                        static_cast<nsIControllerCommand *>(theCmd));    \
   }
 
 #define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag)       \
   {                                                                     \
     _cmdClass* theCmd = new _cmdClass(_styleTag);                       \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
+    NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY);                         \
     rv = inCommandTable->RegisterCommand(_cmdName,                      \
                        static_cast<nsIControllerCommand *>(theCmd));    \
   }
   
 #define NS_REGISTER_TAG_COMMAND(_cmdClass, _cmdName, _tagName)          \
   {                                                                     \
     _cmdClass* theCmd = new _cmdClass(_tagName);                        \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
+    NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY);                         \
     rv = inCommandTable->RegisterCommand(_cmdName,                      \
                        static_cast<nsIControllerCommand *>(theCmd));    \
   }
   
 
 // static
 nsresult
 nsComposerController::RegisterEditorDocStateCommands(
--- a/editor/composer/src/nsComposerDocumentCommands.cpp
+++ b/editor/composer/src/nsComposerDocumentCommands.cpp
@@ -72,20 +72,20 @@ GetPresContextFromEditor(nsIEditor *aEdi
 {
   NS_ENSURE_ARG_POINTER(aResult);
   *aResult = nsnull;
   NS_ENSURE_ARG_POINTER(aEditor);
 
   nsCOMPtr<nsISelectionController> selCon;
   nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!selCon) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIPresShell> presShell = do_QueryInterface(selCon);
-  if (!presShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   NS_IF_ADDREF(*aResult = presShell->GetPresContext());
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSetDocumentOptionsCommand::IsCommandEnabled(const char * aCommandName,
                                               nsISupports *refCon,
@@ -107,42 +107,42 @@ nsSetDocumentOptionsCommand::DoCommand(c
 NS_IMETHODIMP
 nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName,
                                              nsICommandParams *aParams,
                                              nsISupports *refCon)
 {
   NS_ENSURE_ARG_POINTER(aParams);
 
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (!editor) return NS_ERROR_INVALID_ARG;
+  NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG);
 
   nsRefPtr<nsPresContext> presContext;
   nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!presContext) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
   PRInt32 animationMode; 
   rv = aParams->GetLongValue("imageAnimation", &animationMode);
   if (NS_SUCCEEDED(rv))
   {
     // for possible values of animation mode, see:
     // http://lxr.mozilla.org/seamonkey/source/modules/libpr0n/public/imgIContainer.idl
     presContext->SetImageAnimationMode(animationMode);
   }
 
   PRBool allowPlugins; 
   rv = aParams->GetBooleanValue("plugins", &allowPlugins);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsISupports> container = presContext->GetContainer();
-    if (!container) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!docShell) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
     rv = docShell->SetAllowPlugins(allowPlugins);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
@@ -151,29 +151,29 @@ nsSetDocumentOptionsCommand::GetCommandS
                                                    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);
 
   // get pres context
   nsRefPtr<nsPresContext> presContext;
   rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!presContext) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
 
   PRInt32 animationMode;
   rv = aParams->GetLongValue("imageAnimation", &animationMode);
   if (NS_SUCCEEDED(rv))
   {
     // for possible values of animation mode, see
     // http://lxr.mozilla.org/seamonkey/source/modules/libpr0n/public/imgIContainer.idl
     rv = aParams->SetLongValue("imageAnimation",
@@ -181,21 +181,21 @@ nsSetDocumentOptionsCommand::GetCommandS
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   PRBool allowPlugins; 
   rv = aParams->GetBooleanValue("plugins", &allowPlugins);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsISupports> container = presContext->GetContainer();
-    if (!container) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!docShell) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
     rv = docShell->GetAllowPlugins(&allowPlugins);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aParams->SetBooleanValue("plugins", allowPlugins);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
@@ -449,17 +449,17 @@ nsSetDocumentStateCommand::GetCommandSta
  *
  *  3. Add the observer by:
  *       commandManager.addObserver(observeobject, obs_documentCreated);
  *  4. In the appropriate location in editorSession, editor, or commands code, 
  *     trigger the notification of this observer by something like:
  *
  *  nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell);
  *  nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager);
- *  if (!commandUpdater) return NS_ERROR_FAILURE;
+ *  NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
  *    commandUpdater->CommandStatusChanged(obs_documentCreated);
  *
  *  5. Use GetCommandStateParams() to obtain state information
  *     e.g., any creation state codes when creating an editor are 
  *     supplied for "obs_documentCreated" command in the 
  *     "state_data" param's value
  *
  */
@@ -534,20 +534,20 @@ nsDocumentStateCommand::GetCommandStateP
   else if (!nsCRT::strcmp(aCommandName, "obs_documentLocationChanged"))
   {
     nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
     if (editor)
     {
       nsCOMPtr<nsIDOMDocument> domDoc;
       editor->GetDocument(getter_AddRefs(domDoc));
       nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-      if (!doc) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
       nsIURI *uri = doc->GetDocumentURI();
-      if (!uri) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
 
       return aParams->SetISupportsValue(STATE_DATA, (nsISupports*)uri);
     }
     return NS_OK;
   }  
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
--- a/editor/composer/src/nsEditingSession.cpp
+++ b/editor/composer/src/nsEditingSession.cpp
@@ -144,17 +144,17 @@ nsEditingSession::MakeWindowEditable(nsI
                                      PRBool aInteractive)
 {
   mEditorType.Truncate();
   mEditorFlags = 0;
   mWindowToBeEdited = do_GetWeakReference(aWindow);
 
   // disable plugins
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
-  if (!docShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   mInteractive = aInteractive;
   mMakeWholeDocumentEditable = aMakeWholeDocumentEditable;
 
   nsresult rv;
   if (!mInteractive) {
     rv = DisableJSAndPlugins(aWindow);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -214,17 +214,17 @@ nsEditingSession::MakeWindowEditable(nsI
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsEditingSession::DisableJSAndPlugins(nsIDOMWindow *aWindow)
 {
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
-  if (!docShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   PRBool tmp;
   nsresult rv = docShell->GetAllowJavascript(&tmp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mScriptsEnabled = tmp;
 
   rv = docShell->SetAllowJavascript(PR_FALSE);
@@ -248,17 +248,17 @@ NS_IMETHODIMP
 nsEditingSession::RestoreJSAndPlugins(nsIDOMWindow *aWindow)
 {
   if (!mDisabledJSAndPlugins)
     return NS_OK;
 
   mDisabledJSAndPlugins = PR_FALSE;
 
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
-  if (!docShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   nsresult rv = docShell->SetAllowJavascript(mScriptsEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Disable plugins in this document:
   return docShell->SetAllowPlugins(mPluginsEnabled);
 }
 
@@ -424,22 +424,22 @@ nsEditingSession::SetupEditorOnWindow(ns
   {
     mStateMaintainer->NotifyDocumentCreated();
     return NS_ERROR_FAILURE;
   }
 
   // Create editor and do other things 
   //  only if we haven't found some error above,
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
-  if (!docShell) return NS_ERROR_FAILURE;  
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);  
 
   if (!mInteractive) {
     // Disable animation of images in this document:
     nsCOMPtr<nsIDOMWindowUtils> utils(do_GetInterface(aWindow));
-    if (!utils) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);
 
     rv = utils->GetImageAnimationMode(&mImageAnimationMode);
     NS_ENSURE_SUCCESS(rv, rv);
     utils->SetImageAnimationMode(imgIContainer::kDontAnimMode);
   }
 
   // create and set editor
   nsCOMPtr<nsIEditorDocShell> editorDocShell = do_QueryInterface(docShell, &rv);
@@ -463,43 +463,43 @@ nsEditingSession::SetupEditorOnWindow(ns
 
   // Set mimetype on editor
   rv = editor->SetContentsMIMEType(mimeCType.get());
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIContentViewer> contentViewer;
   rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!contentViewer) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(contentViewer, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMDocument> domDoc;  
   rv = contentViewer->GetDOMDocument(getter_AddRefs(domDoc));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!domDoc) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
 
   // Set up as a doc state listener
   // Important! We must have this to broadcast the "obs_documentCreated" message
   rv = editor->AddDocumentStateListener(mStateMaintainer);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // XXXbz we really shouldn't need a presShell here!
   nsCOMPtr<nsIPresShell> presShell;
   rv = docShell->GetPresShell(getter_AddRefs(presShell));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!presShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(presShell);
   rv = editor->Init(domDoc, presShell, nsnull /* root content */,
                     selCon, mEditorFlags);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISelection> selection;
   editor->GetSelection(getter_AddRefs(selection));
   nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection);
-  if (!selPriv) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selPriv, NS_ERROR_FAILURE);
 
   rv = selPriv->AddSelectionListener(mStateMaintainer);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // and as a transaction listener
   nsCOMPtr<nsITransactionManager> txnMgr;
   editor->GetTransactionManager(getter_AddRefs(txnMgr));
   if (txnMgr)
@@ -839,29 +839,29 @@ nsEditingSession::OnLocationChange(nsIWe
   nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMDocument> domDoc;
   rv = domWindow->GetDocument(getter_AddRefs(domDoc));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-  if (!doc) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   doc->SetDocumentURI(aURI);
 
   // Notify the location-changed observer that
   //  the document URL has changed
   nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
-  if (!docShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShell);
   nsCOMPtr<nsPICommandUpdater> commandUpdater =
                                   do_QueryInterface(commandManager);
-  if (!commandUpdater) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
 
   return commandUpdater->CommandStatusChanged("obs_documentLocationChanged");
 }
 
 /*---------------------------------------------------------------------------
 
   OnStatusChange
 
@@ -948,17 +948,17 @@ nsEditingSession::StartDocumentLoad(nsIW
   
   // If we have an editor here, then we got a reload after making the editor.
   // We need to blow it away and make a new one at the end of the load.
   nsCOMPtr<nsIDOMWindow> domWindow;
   aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
   if (domWindow)
   {
     nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
-    if (!docShell) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
     docShell->DetachEditorFromWindow();
   }
     
   if (aIsToBeMadeEditable)
     mEditorStatus = eEditorCreationInProgress;
 
   return NS_OK;
 }
@@ -998,17 +998,17 @@ nsEditingSession::EndDocumentLoad(nsIWeb
   // Set the error state -- we will create an editor 
   // anyway and load empty doc later
   if (aIsToBeMadeEditable) {
     if (aStatus == NS_ERROR_FILE_NOT_FOUND)
       mEditorStatus = eEditorErrorFileNotFound;
   }
 
   nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
-  if (!docShell) return NS_ERROR_FAILURE;       // better error handling?
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);       // better error handling?
 
   // cancel refresh from meta tags
   // we need to make sure that all pages in editor (whether editable or not)
   // can't refresh contents being edited
   nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(docShell);
   if (refreshURI)
     refreshURI->CancelRefreshURITimers();
 
@@ -1129,17 +1129,17 @@ nsEditingSession::EndPageLoad(nsIWebProg
   // and load empty doc later
   if (aStatus == NS_ERROR_FILE_NOT_FOUND)
     mEditorStatus = eEditorErrorFileNotFound;
 
   nsCOMPtr<nsIDOMWindow> domWindow;
   aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
 
   nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
-  if (!docShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   // cancel refresh from meta tags
   // we need to make sure that all pages in editor (whether editable or not)
   // can't refresh contents being edited
   nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(docShell);
   if (refreshURI)
     refreshURI->CancelRefreshURITimers();
 
@@ -1179,17 +1179,17 @@ nsEditingSession::GetDocShellFromWindow(
   Utility method. This will always return an error if no docShell
   is returned.
 ----------------------------------------------------------------------------*/
 nsresult
 nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *aWindow,
                                               nsIEditorDocShell** outDocShell)
 {
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
-  if (!docShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
   
   return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell), 
                                   (void **)outDocShell);
 }
 
 /*---------------------------------------------------------------------------
 
   PrepareForEditing
@@ -1201,17 +1201,17 @@ nsEditingSession::PrepareForEditing(nsID
 {
   if (mProgressListenerRegistered)
     return NS_OK;
     
   nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
   
   // register callback
   nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
-  if (!webProgress) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(webProgress, NS_ERROR_FAILURE);
 
   nsresult rv =
     webProgress->AddProgressListener(this,
                                      (nsIWebProgress::NOTIFY_STATE_NETWORK  | 
                                       nsIWebProgress::NOTIFY_STATE_DOCUMENT |
                                       nsIWebProgress::NOTIFY_LOCATION));
 
   mProgressListenerRegistered = NS_SUCCEEDED(rv);
@@ -1323,17 +1323,17 @@ nsEditingSession::SetContextOnController
 
   // aContext can be null (when destroying editor)
   nsCOMPtr<nsIController> controller;    
   aControllers->GetControllerById(aID, getter_AddRefs(controller));
   
   // ok with nil controller
   nsCOMPtr<nsIControllerContext> editorController =
                                        do_QueryInterface(controller);
-  if (!editorController) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editorController, NS_ERROR_FAILURE);
 
   return editorController->SetCommandContext(aContext);
 }
 
 void
 nsEditingSession::RemoveEditorControllers(nsIDOMWindow *aWindow)
 {
   // Remove editor controllers from the aWindow, call when we're 
@@ -1479,17 +1479,17 @@ nsEditingSession::ReattachToWindow(nsIDO
   rv = GetEditorForWindow(aWindow, getter_AddRefs(editor));
   if (!editor)
     return NS_ERROR_FAILURE;
 
   if (!mInteractive)
   {
     // Disable animation of images in this document:
     nsCOMPtr<nsIDOMWindowUtils> utils(do_GetInterface(aWindow));
-    if (!utils) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(utils, NS_ERROR_FAILURE);
 
     rv = utils->GetImageAnimationMode(&mImageAnimationMode);
     NS_ENSURE_SUCCESS(rv, rv);
     utils->SetImageAnimationMode(imgIContainer::kDontAnimMode);
   }
 
   // The third controller takes an nsIEditor as the context
   rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1",
--- a/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp
+++ b/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp
@@ -171,22 +171,22 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::I
 }
 
 NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void)
 {
   NS_ASSERTION(mEditor && mElement, "bad state");
   if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
 
   nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(mElement);
-  if (!inlineStyles) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
   nsresult result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
   NS_ENSURE_SUCCESS(result, result);
-  if (!cssDecl) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(cssDecl, NS_ERROR_NULL_POINTER);
 
   nsAutoString propertyNameString;
   mProperty->ToString(propertyNameString);
 
   NS_NAMED_LITERAL_STRING(styleAttr, "style");
   result = mElement->HasAttribute(styleAttr, &mUndoAttributeWasSet);
   NS_ENSURE_SUCCESS(result, result);
 
@@ -268,21 +268,21 @@ nsresult ChangeCSSInlineStyleTxn::SetSty
 
   nsresult result;
   if (aAttributeWasSet) {
     // the style attribute was set and not empty, let's recreate the declaration
     nsAutoString propertyNameString;
     mProperty->ToString(propertyNameString);
 
     nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(mElement);
-    if (!inlineStyles) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
     result = inlineStyles->GetStyle(getter_AddRefs(cssDecl));
     NS_ENSURE_SUCCESS(result, result);
-    if (!cssDecl) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(cssDecl, NS_ERROR_NULL_POINTER);
 
     if (aValue.IsEmpty()) {
       // an empty value means we have to remove the property
       nsAutoString returnString;
       result = cssDecl->RemoveProperty(propertyNameString, returnString);
     }
     else {
       // let's recreate the declaration as it was
--- a/editor/libeditor/base/CreateElementTxn.cpp
+++ b/editor/libeditor/base/CreateElementTxn.cpp
@@ -104,31 +104,31 @@ NS_IMETHODIMP CreateElementTxn::DoTransa
     char* nodename = ToNewCString(mTag);
     printf("Do Create Element parent = %p <%s>, offset = %d\n", 
            static_cast<void*>(mParent.get()), nodename, mOffsetInParent);
     nsMemory::Free(nodename);
   }
 #endif
 
   NS_ASSERTION(mEditor && mParent, "bad state");
-  if (!mEditor || !mParent) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mParent, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIContent> newContent;
  
   //new call to use instead to get proper HTML element, bug# 39919
   nsresult result = mEditor->CreateHTMLContent(mTag, getter_AddRefs(newContent));
   NS_ENSURE_SUCCESS(result, result);
   nsCOMPtr<nsIDOMElement>newElement = do_QueryInterface(newContent);
-  if (!newElement) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(newElement, NS_ERROR_NULL_POINTER);
   mNewNode = do_QueryInterface(newElement);
   // Try to insert formatting whitespace for the new node:
   mEditor->MarkNodeDirty(mNewNode);
  
   NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewNode)), "could not create element.");
-  if (!mNewNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mNewNode, NS_ERROR_NULL_POINTER);
 
 #ifdef NS_DEBUG
   if (gNoisy)
   {
     printf("  newNode = %p\n", static_cast<void*>(mNewNode.get()));
   }
 #endif
 
@@ -157,17 +157,17 @@ NS_IMETHODIMP CreateElementTxn::DoTransa
       // only set selection to insertion point if editor gives permission
       PRBool bAdjustSelection;
       mEditor->ShouldTxnSetSelection(&bAdjustSelection);
       if (bAdjustSelection)
       {
         nsCOMPtr<nsISelection> selection;
         result = mEditor->GetSelection(getter_AddRefs(selection));
         NS_ENSURE_SUCCESS(result, result);
-        if (!selection) return NS_ERROR_NULL_POINTER;
+        NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
         PRInt32 offset=0;
         result = nsEditor::GetChildOffset(mNewNode, mParent, offset);
         NS_ENSURE_SUCCESS(result, result);
 
         result = selection->Collapse(mParent, offset+1);
         NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
        }
@@ -187,30 +187,30 @@ NS_IMETHODIMP CreateElementTxn::UndoTran
   {
     printf("Undo Create Element, mParent = %p, node = %p\n",
            static_cast<void*>(mParent.get()),
            static_cast<void*>(mNewNode.get()));
   }
 #endif
 
   NS_ASSERTION(mEditor && mParent, "bad state");
-  if (!mEditor || !mParent) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mParent, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIDOMNode> resultNode;
   return mParent->RemoveChild(mNewNode, getter_AddRefs(resultNode));
 }
 
 NS_IMETHODIMP CreateElementTxn::RedoTransaction(void)
 {
 #ifdef NS_DEBUG
   if (gNoisy) { printf("Redo Create Element\n"); }
 #endif
 
   NS_ASSERTION(mEditor && mParent, "bad state");
-  if (!mEditor || !mParent) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mEditor && mParent, NS_ERROR_NOT_INITIALIZED);
 
   // first, reset mNewNode so it has no attributes or content
   nsCOMPtr<nsIDOMCharacterData>nodeAsText = do_QueryInterface(mNewNode);
   if (nodeAsText)
   {
     nodeAsText->SetData(EmptyString());
   }
   
--- a/editor/libeditor/base/DeleteElementTxn.cpp
+++ b/editor/libeditor/base/DeleteElementTxn.cpp
@@ -74,17 +74,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteElementTxn)
 NS_INTERFACE_MAP_END_INHERITING(EditTxn)
 
 NS_IMETHODIMP DeleteElementTxn::Init(nsIEditor *aEditor,
                                      nsIDOMNode *aElement,
                                      nsRangeUpdater *aRangeUpdater)
 {
-  if (!aEditor || !aElement) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aEditor && aElement, NS_ERROR_NULL_POINTER);
   mEditor = aEditor;
   mElement = do_QueryInterface(aElement);
   nsresult result = mElement->GetParentNode(getter_AddRefs(mParent));
   if (NS_FAILED(result)) { return result; }
 
   // do nothing if the parent is read-only
   if (mParent && !mEditor->IsModifiableNode(mParent)) {
     return NS_ERROR_FAILURE;
@@ -101,17 +101,17 @@ NS_IMETHODIMP DeleteElementTxn::DoTransa
   if (gNoisy)
   {
     printf("%p Do Delete Element element = %p\n",
            static_cast<void*>(this),
            static_cast<void*>(mElement.get()));
   }
 #endif
 
-  if (!mElement) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mElement, NS_ERROR_NOT_INITIALIZED);
 
   if (!mParent) { return NS_OK; }  // this is a no-op, there's no parent to delete mElement from
 
 #ifdef NS_DEBUG
   // begin debug output
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mElement);
   nsAutoString elementTag(NS_LITERAL_STRING("text node"));
   if (element)
--- a/editor/libeditor/base/DeleteRangeTxn.cpp
+++ b/editor/libeditor/base/DeleteRangeTxn.cpp
@@ -201,17 +201,17 @@ NS_IMETHODIMP DeleteRangeTxn::DoTransact
   // only set selection to deletion point if editor gives permission
   PRBool bAdjustSelection;
   mEditor->ShouldTxnSetSelection(&bAdjustSelection);
   if (bAdjustSelection)
   {
     nsCOMPtr<nsISelection> selection;
     result = mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(result, result);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     result = selection->Collapse(mStartParent, mStartOffset);
   }
   else
   {
     // do nothing - dom range gravity will adjust selection
   }
 
   return result;
@@ -270,30 +270,30 @@ DeleteRangeTxn::CreateTxnsToDeleteBetwee
     if (NS_SUCCEEDED(result))
       AppendChild(txn);
   }
   else
   {
     nsCOMPtr<nsIDOMNodeList> children;
     result = aStartParent->GetChildNodes(getter_AddRefs(children));
     NS_ENSURE_SUCCESS(result, result);
-    if (!children) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(children, NS_ERROR_NULL_POINTER);
 
 #ifdef DEBUG
     PRUint32 childCount;
     children->GetLength(&childCount);
     NS_ASSERTION(aEndOffset<=childCount, "bad aEndOffset");
 #endif
     PRUint32 i;
     for (i=aStartOffset; i<aEndOffset; i++)
     {
       nsCOMPtr<nsIDOMNode> child;
       result = children->Item(i, getter_AddRefs(child));
       NS_ENSURE_SUCCESS(result, result);
-      if (!child) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(child, NS_ERROR_NULL_POINTER);
 
       nsRefPtr<DeleteElementTxn> txn = new DeleteElementTxn();
       if (!txn)
         return NS_ERROR_OUT_OF_MEMORY;
 
       result = txn->Init(mEditor, child, mRangeUpdater);
       if (NS_SUCCEEDED(result))
         AppendChild(txn);
@@ -337,17 +337,17 @@ NS_IMETHODIMP DeleteRangeTxn::CreateTxns
   }
 
   return result;
 }
 
 NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteNodesBetween()
 {
   nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1");
-  if (!iter) return NS_ERROR_NULL_POINTER;
+  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)
--- a/editor/libeditor/base/DeleteTextTxn.cpp
+++ b/editor/libeditor/base/DeleteTextTxn.cpp
@@ -115,17 +115,17 @@ NS_IMETHODIMP DeleteTextTxn::DoTransacti
   // only set selection to deletion point if editor gives permission
   PRBool bAdjustSelection;
   mEditor->ShouldTxnSetSelection(&bAdjustSelection);
   if (bAdjustSelection)
   {
     nsCOMPtr<nsISelection> selection;
     result = mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(result, result);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     result = selection->Collapse(mElement, mOffset);
     NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of deletetext.");
   }
   else
   {
     // do nothing - dom range gravity will adjust selection
   }
   return result;
--- a/editor/libeditor/base/IMETextTxn.cpp
+++ b/editor/libeditor/base/IMETextTxn.cpp
@@ -96,17 +96,17 @@ NS_IMETHODIMP IMETextTxn::Init(nsIDOMCha
 NS_IMETHODIMP IMETextTxn::DoTransaction(void)
 {
 
 #ifdef DEBUG_IMETXN
   printf("Do IME Text element = %p replace = %d len = %d\n", mElement.get(), mReplaceLength, mStringToInsert.Length());
 #endif
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
-  if (!selCon) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
 
   // advance caret: This requires the presentation shell to get the selection.
   nsresult result;
   if (mReplaceLength == 0) {
     result = mElement->InsertData(mOffset, mStringToInsert);
   } else {
     result = mElement->ReplaceData(mOffset, mReplaceLength, mStringToInsert);
   }
@@ -119,17 +119,17 @@ NS_IMETHODIMP IMETextTxn::DoTransaction(
 
 NS_IMETHODIMP IMETextTxn::UndoTransaction(void)
 {
 #ifdef DEBUG_IMETXN
   printf("Undo IME Text element = %p\n", mElement.get());
 #endif
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
-  if (!selCon) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
 
   nsresult result = mElement->DeleteData(mOffset, mStringToInsert.Length());
   if (NS_SUCCEEDED(result))
   { // set the selection to the insertion point where the string was removed
     nsCOMPtr<nsISelection> selection;
     result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
     if (NS_SUCCEEDED(result) && selection) {
       result = selection->Collapse(mElement, mOffset);
@@ -262,17 +262,17 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSe
       else printf("unknown constant\n");
     }
 #endif
         
     //
     // run through the text range list, if any
     //
     nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
-    if (!selCon) return NS_ERROR_NOT_INITIALIZED;
+    NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
 
     PRUint16      textRangeListLength,selectionStart,selectionEnd,
                   textRangeType;
     
     textRangeListLength = mRangeList->GetLength();
     nsCOMPtr<nsISelection> selection;
     result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
     if(NS_SUCCEEDED(result))
--- a/editor/libeditor/base/InsertElementTxn.cpp
+++ b/editor/libeditor/base/InsertElementTxn.cpp
@@ -100,17 +100,17 @@ NS_IMETHODIMP InsertElementTxn::DoTransa
            static_cast<void*>(nodeAsContent.get()),
            nodename,
            static_cast<void*>(parentAsContent.get()),
            mOffset); 
     nsMemory::Free(nodename);
   }
 #endif
 
-  if (!mNode || !mParent) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mNode && mParent, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIDOMNodeList> childNodes;
   nsresult result = mParent->GetChildNodes(getter_AddRefs(childNodes));
   NS_ENSURE_SUCCESS(result, result);
   nsCOMPtr<nsIDOMNode>refNode;
   if (childNodes)
   {
     PRUint32 count;
@@ -123,27 +123,27 @@ NS_IMETHODIMP InsertElementTxn::DoTransa
     // note, it's ok for mRefNode to be null.  that means append
   }
 
   mEditor->MarkNodeDirty(mNode);
 
   nsCOMPtr<nsIDOMNode> resultNode;
   result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode));
   NS_ENSURE_SUCCESS(result, result);
-  if (!resultNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(resultNode, NS_ERROR_NULL_POINTER);
 
   // only set selection to insertion point if editor gives permission
   PRBool bAdjustSelection;
   mEditor->ShouldTxnSetSelection(&bAdjustSelection);
   if (bAdjustSelection)
   {
     nsCOMPtr<nsISelection> selection;
     result = mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(result, result);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     // place the selection just after the inserted element
     selection->Collapse(mParent, mOffset+1);
   }
   else
   {
     // do nothing - dom range gravity will adjust selection
   }
   return result;
@@ -157,17 +157,17 @@ NS_IMETHODIMP InsertElementTxn::UndoTran
     printf("%p Undo Insert Element of %p into parent %p at offset %d\n",
            static_cast<void*>(this),
            static_cast<void*>(mNode.get()),
            static_cast<void*>(mParent.get()),
            mOffset);
   }
 #endif
 
-  if (!mNode || !mParent) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mNode && mParent, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIDOMNode> resultNode;
   return mParent->RemoveChild(mNode, getter_AddRefs(resultNode));
 }
 
 NS_IMETHODIMP InsertElementTxn::GetTxnDescription(nsAString& aString)
 {
   aString.AssignLiteral("InsertElementTxn");
--- a/editor/libeditor/base/InsertTextTxn.cpp
+++ b/editor/libeditor/base/InsertTextTxn.cpp
@@ -76,17 +76,17 @@ NS_IMETHODIMP InsertTextTxn::Init(nsIDOM
       nsAutoString text;
       aElement->GetData(text);
       printf("InsertTextTxn: Offset to insert at = %d. Text of the node to insert into:\n", aOffset);
       wprintf(text.get());
       printf("\n");
 #endif
 
   NS_ASSERTION(aElement && aEditor, "bad args");
-  if (!aElement || !aEditor) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement && aEditor, NS_ERROR_NULL_POINTER);
 
   mElement = do_QueryInterface(aElement);
   mOffset = aOffset;
   mStringToInsert = aStringToInsert;
   mEditor = aEditor;
   return NS_OK;
 }
 
@@ -109,17 +109,17 @@ NS_IMETHODIMP InsertTextTxn::DoTransacti
   // only set selection to insertion point if editor gives permission
   PRBool bAdjustSelection;
   mEditor->ShouldTxnSetSelection(&bAdjustSelection);
   if (bAdjustSelection)
   {
     nsCOMPtr<nsISelection> selection;
     result = mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(result, result);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     result = selection->Collapse(mElement, mOffset+mStringToInsert.Length());
     NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert.");
   }
   else
   {
     // do nothing - dom range gravity will adjust selection
   }
 
--- a/editor/libeditor/base/JoinElementTxn.cpp
+++ b/editor/libeditor/base/JoinElementTxn.cpp
@@ -100,23 +100,23 @@ NS_IMETHODIMP JoinElementTxn::DoTransact
 
   NS_PRECONDITION((mEditor && mLeftNode && mRightNode), "null arg");
   if (!mEditor || !mLeftNode || !mRightNode) { return NS_ERROR_NOT_INITIALIZED; }
 
   // get the parent node
   nsCOMPtr<nsIDOMNode>leftParent;
   nsresult result = mLeftNode->GetParentNode(getter_AddRefs(leftParent));
   NS_ENSURE_SUCCESS(result, result);
-  if (!leftParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(leftParent, NS_ERROR_NULL_POINTER);
 
   // verify that mLeftNode and mRightNode have the same parent
   nsCOMPtr<nsIDOMNode>rightParent;
   result = mRightNode->GetParentNode(getter_AddRefs(rightParent));
   NS_ENSURE_SUCCESS(result, result);
-  if (!rightParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(rightParent, NS_ERROR_NULL_POINTER);
 
   if (leftParent==rightParent)
   {
     mParent= do_QueryInterface(leftParent); // set this instance mParent. 
                                             // Other methods will see a non-null mParent and know all is well
     nsCOMPtr<nsIDOMCharacterData> leftNodeAsText = do_QueryInterface(mLeftNode);
     if (leftNodeAsText) 
     {
--- a/editor/libeditor/base/PlaceholderTxn.cpp
+++ b/editor/libeditor/base/PlaceholderTxn.cpp
@@ -71,17 +71,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END_INHERITING(EditAggregateTxn)
 
 NS_IMPL_ADDREF_INHERITED(PlaceholderTxn, EditAggregateTxn)
 NS_IMPL_RELEASE_INHERITED(PlaceholderTxn, EditAggregateTxn)
 
 NS_IMETHODIMP PlaceholderTxn::Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor)
 {
-  if (!aEditor || !aSelState) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aEditor && aSelState, NS_ERROR_NULL_POINTER);
 
   mName = aName;
   mStartSel = aSelState;
   mEditor = aEditor;
   return NS_OK;
 }
 
 NS_IMETHODIMP PlaceholderTxn::DoTransaction(void)
@@ -90,62 +90,62 @@ NS_IMETHODIMP PlaceholderTxn::DoTransact
 }
 
 NS_IMETHODIMP PlaceholderTxn::UndoTransaction(void)
 {
   // undo txns
   nsresult res = EditAggregateTxn::UndoTransaction();
   NS_ENSURE_SUCCESS(res, res);
   
-  if (!mStartSel) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mStartSel, NS_ERROR_NULL_POINTER);
 
   // now restore selection
   nsCOMPtr<nsISelection> selection;
   res = mEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   return mStartSel->RestoreSelection(selection);
 }
 
 
 NS_IMETHODIMP PlaceholderTxn::RedoTransaction(void)
 {
   // redo txns
   nsresult res = EditAggregateTxn::RedoTransaction();
   NS_ENSURE_SUCCESS(res, res);
   
   // now restore selection
   nsCOMPtr<nsISelection> selection;
   res = mEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   return mEndSel.RestoreSelection(selection);
 }
 
 
 NS_IMETHODIMP PlaceholderTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
 {
-  if (!aDidMerge || !aTransaction) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aDidMerge && aTransaction, NS_ERROR_NULL_POINTER);
 
   // set out param default value
   *aDidMerge=PR_FALSE;
     
   if (mForwarding) 
   {
     NS_NOTREACHED("tried to merge into a placeholder that was in forwarding mode!");
     return NS_ERROR_FAILURE;
   }
 
   // check to see if aTransaction is one of the editor's
   // private transactions. If not, we want to avoid merging
   // the foreign transaction into our placeholder since we
   // don't know what it does.
 
   nsCOMPtr<nsPIEditorTransaction> pTxn = do_QueryInterface(aTransaction);
-  if (!pTxn) return NS_OK; // it's foreign so just bail!
+  NS_ENSURE_TRUE(pTxn, NS_OK); // it's foreign so just bail!
 
   EditTxn *editTxn = (EditTxn*)aTransaction;  //XXX: hack, not safe!  need nsIEditTransaction!
   // determine if this incoming txn is a placeholder txn
   nsCOMPtr<nsIAbsorbingTransaction> plcTxn;// = do_QueryInterface(editTxn);
   // can't do_QueryInterface() above due to our broken transaction interfaces.
   // instead have to brute it below. ugh. 
   editTxn->QueryInterface(NS_GET_IID(nsIAbsorbingTransaction), getter_AddRefs(plcTxn));
 
@@ -245,17 +245,17 @@ NS_IMETHODIMP PlaceholderTxn::GetTxnName
 {
   return GetName(aName);
 }
 
 NS_IMETHODIMP PlaceholderTxn::StartSelectionEquals(nsSelectionState *aSelState, PRBool *aResult)
 {
   // determine if starting selection matches the given selection state.
   // note that we only care about collapsed selections.
-  if (!aResult || !aSelState) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aResult && aSelState, NS_ERROR_NULL_POINTER);
   if (!mStartSel->IsCollapsed() || !aSelState->IsCollapsed())
   {
     *aResult = PR_FALSE;
     return NS_OK;
   }
   *aResult = mStartSel->IsEqual(aSelState);
   return NS_OK;
 }
@@ -286,12 +286,12 @@ NS_IMETHODIMP PlaceholderTxn::Commit()
   return NS_OK;
 }
 
 NS_IMETHODIMP PlaceholderTxn::RememberEndingSelection()
 {
   nsCOMPtr<nsISelection> selection;
   nsresult res = mEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   return mEndSel.SaveSelection(selection);
 }
 
--- a/editor/libeditor/base/SetDocTitleTxn.cpp
+++ b/editor/libeditor/base/SetDocTitleTxn.cpp
@@ -79,20 +79,20 @@ NS_IMETHODIMP SetDocTitleTxn::RedoTransa
 {
   // No extra work required; the DOM changes alone are enough
   return NS_OK;
 }
 
 nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
-  if (!editor) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
   nsCOMPtr<nsIDOMDocument> domDoc;
   nsresult res = editor->GetDocument(getter_AddRefs(domDoc));
-  if (!domDoc) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMNodeList> titleList;
   res = domDoc->GetElementsByTagName(NS_LITERAL_STRING("title"), getter_AddRefs(titleList));
   NS_ENSURE_SUCCESS(res, res);
 
   // First assume we will NOT really do anything
   // (transaction will not be pushed on stack)
   mIsTransient = PR_TRUE;
@@ -130,32 +130,32 @@ nsresult SetDocTitleTxn::SetDomTitle(con
 
   // We didn't return above, thus we really will be changing the title
   mIsTransient = PR_FALSE;
 
   // Get the <HEAD> node, create a <TITLE> and insert it under the HEAD
   nsCOMPtr<nsIDOMNodeList> headList;
   res = domDoc->GetElementsByTagName(NS_LITERAL_STRING("head"),getter_AddRefs(headList));
   NS_ENSURE_SUCCESS(res, res);
-  if (!headList) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(headList, NS_ERROR_FAILURE);
   
   nsCOMPtr<nsIDOMNode>headNode;
   headList->Item(0, getter_AddRefs(headNode));
-  if (!headNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(headNode, NS_ERROR_FAILURE);
 
   PRBool   newTitleNode = PR_FALSE;
   PRUint32 newTitleIndex = 0;
 
   if (!titleNode)
   {
     // Didn't find one above: Create a new one
     nsCOMPtr<nsIDOMElement>titleElement;
     res = domDoc->CreateElement(NS_LITERAL_STRING("title"), getter_AddRefs(titleElement));
     NS_ENSURE_SUCCESS(res, res);
-    if (!titleElement) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(titleElement, NS_ERROR_FAILURE);
 
     titleNode = do_QueryInterface(titleElement);
     newTitleNode = PR_TRUE;
 
     // Get index so we append new title node 
     // after all existing HEAD children
     nsCOMPtr<nsIDOMNodeList> children;
     res = headNode->GetChildNodes(getter_AddRefs(children));
@@ -167,17 +167,17 @@ nsresult SetDocTitleTxn::SetDomTitle(con
   // Append a text node under the TITLE
   //  only if the title text isn't empty
   if (titleNode && !aTitle.IsEmpty())
   {
     nsCOMPtr<nsIDOMText> textNode;
     res = domDoc->CreateTextNode(aTitle, getter_AddRefs(textNode));
     NS_ENSURE_SUCCESS(res, res);
     nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(textNode);
-    if (!newNode) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(newNode, NS_ERROR_FAILURE);
 
     if (newTitleNode)
     {
       // Not undoable: We will insert newTitleNode below
       nsCOMPtr<nsIDOMNode> resultNode;
       res = titleNode->AppendChild(newNode, getter_AddRefs(resultNode));
     } 
     else 
@@ -200,13 +200,13 @@ NS_IMETHODIMP SetDocTitleTxn::GetTxnDesc
 {
   aString.AssignLiteral("SetDocTitleTxn: ");
   aString += mValue;
   return NS_OK;
 }
 
 NS_IMETHODIMP SetDocTitleTxn::GetIsTransient(PRBool *aIsTransient)
 {
-  if (!aIsTransient) return NS_ERROR_NULL_POINTER;  
+  NS_ENSURE_TRUE(aIsTransient, NS_ERROR_NULL_POINTER);  
   *aIsTransient = mIsTransient;
   return NS_OK;
 }
 
--- a/editor/libeditor/base/SplitElementTxn.cpp
+++ b/editor/libeditor/base/SplitElementTxn.cpp
@@ -94,40 +94,40 @@ NS_IMETHODIMP SplitElementTxn::DoTransac
 
   NS_ASSERTION(mExistingRightNode && mEditor, "bad state");
   if (!mExistingRightNode || !mEditor) { return NS_ERROR_NOT_INITIALIZED; }
 
   // create a new node
   nsresult result = mExistingRightNode->CloneNode(PR_FALSE, getter_AddRefs(mNewLeftNode));
   NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewLeftNode)), "could not create element.");
   NS_ENSURE_SUCCESS(result, result);
-  if (!mNewLeftNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mNewLeftNode, NS_ERROR_NULL_POINTER);
   mEditor->MarkNodeDirty(mExistingRightNode);
 
 #ifdef NS_DEBUG
   if (gNoisy)
   {
     printf("  created left node = %p\n",
            static_cast<void*>(mNewLeftNode.get()));
   }
 #endif
 
   // get the parent node
   result = mExistingRightNode->GetParentNode(getter_AddRefs(mParent));
   NS_ENSURE_SUCCESS(result, result);
-  if (!mParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mParent, NS_ERROR_NULL_POINTER);
 
   // insert the new node
   result = mEditor->SplitNodeImpl(mExistingRightNode, mOffset, mNewLeftNode, mParent);
   if (NS_SUCCEEDED(result) && mNewLeftNode)
   {
     nsCOMPtr<nsISelection>selection;
     mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(result, result);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     result = selection->Collapse(mNewLeftNode, mOffset);
   }
   else {
     result = NS_ERROR_NOT_IMPLEMENTED;
   }
   return result;
 }
 
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -231,17 +231,17 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsI
   nsresult rv = SetFlags(aFlags);
   NS_ASSERTION(NS_SUCCEEDED(rv), "SetFlags() failed");
 
   mDocWeak = do_GetWeakReference(aDoc);  // weak reference to doc
   mPresShellWeak = do_GetWeakReference(aPresShell);   // weak reference to pres shell
   mSelConWeak = do_GetWeakReference(aSelCon);   // weak reference to selectioncontroller
 
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
   
   //set up root element if we are passed one.  
   if (aRoot)
     mRootElement = do_QueryInterface(aRoot);
 
   mUpdateCount=0;
 
   /* initialize IME stuff */
@@ -485,31 +485,31 @@ nsEditor::GetIsDocumentEditable(PRBool *
 NS_IMETHODIMP 
 nsEditor::GetDocument(nsIDOMDocument **aDoc)
 {
   if (!aDoc)
     return 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);
-  if (!doc) return NS_ERROR_NOT_INITIALIZED;
+  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;
   *aPS = nsnull; // init out param
   NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak");
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
   NS_ADDREF(*aPS = ps);
   return NS_OK;
 }
 
 
 /* attribute string contentsMIMEType; */
 NS_IMETHODIMP
 nsEditor::GetContentsMIMEType(char * *aContentsMIMEType)
@@ -529,17 +529,17 @@ nsEditor::SetContentsMIMEType(const char
 NS_IMETHODIMP
 nsEditor::GetSelectionController(nsISelectionController **aSel)
 {
   if (!aSel)
     return NS_ERROR_NULL_POINTER;
   *aSel = nsnull; // init out param
   NS_PRECONDITION(mSelConWeak, "bad state, null mSelConWeak");
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
-  if (!selCon) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
   NS_ADDREF(*aSel = selCon);
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsEditor::DeleteSelection(EDirection aAction)
 {
@@ -550,17 +550,17 @@ nsEditor::DeleteSelection(EDirection aAc
 
 NS_IMETHODIMP
 nsEditor::GetSelection(nsISelection **aSelection)
 {
   if (!aSelection)
     return NS_ERROR_NULL_POINTER;
   *aSelection = nsnull;
   nsCOMPtr<nsISelectionController> selcon = do_QueryReferent(mSelConWeak);
-  if (!selcon) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(selcon, NS_ERROR_NOT_INITIALIZED);
   return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection);  // does an addref
 }
 
 NS_IMETHODIMP 
 nsEditor::DoTransaction(nsITransaction *aTxn)
 {
 #ifdef NS_DEBUG_EDITOR
   if (gNoisy) { printf("Editor::DoTransaction ----------\n"); }
@@ -941,17 +941,17 @@ nsEditor::EndPlaceHolderTransaction()
   mPlaceHolderBatch--;
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::ShouldTxnSetSelection(PRBool *aResult)
 {
-  if (!aResult) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aResult, NS_ERROR_NULL_POINTER);
   *aResult = mShouldTxnSetSelection;
   return NS_OK;
 }
 
 NS_IMETHODIMP  
 nsEditor::SetShouldTxnSetSelection(PRBool aShould)
 {
   mShouldTxnSetSelection = aShould;
@@ -978,17 +978,17 @@ nsEditor::GetDocumentIsEmpty(PRBool *aDo
 
 // XXX: the rule system should tell us which node to select all on (ie, the root, or the body)
 NS_IMETHODIMP nsEditor::SelectAll()
 {
   if (!mDocWeak || !mPresShellWeak) { return NS_ERROR_NOT_INITIALIZED; }
   ForceCompositionEnd();
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
-  if (!selCon) return NS_ERROR_NOT_INITIALIZED;
+  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)
   {
     result = SelectEntireDocument(selection);
   }
   return result;
 }
@@ -1045,17 +1045,17 @@ nsEditor::EndOfDocument()
 { 
   if (!mDocWeak || !mPresShellWeak) { return NS_ERROR_NOT_INITIALIZED; } 
   nsresult res; 
 
   // get selection 
   nsCOMPtr<nsISelection> selection; 
   res = GetSelection(getter_AddRefs(selection)); 
   NS_ENSURE_SUCCESS(res, res); 
-  if (!selection)   return NS_ERROR_NULL_POINTER; 
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); 
   
   // get the root element 
   nsIDOMElement *rootElement = GetRoot(); 
   if (!rootElement)
     return NS_ERROR_NULL_POINTER; 
 
   // get the length of the rot element 
   PRUint32 len; 
@@ -1545,17 +1545,17 @@ nsEditor::RemoveContainer(nsIDOMNode *in
   
   // loop through the child nodes of inNode and promote them
   // into inNode's parent.
   PRBool bHasMoreChildren;
   inNode->HasChildNodes(&bHasMoreChildren);
   nsCOMPtr<nsIDOMNodeList> nodeList;
   res = inNode->GetChildNodes(getter_AddRefs(nodeList));
   NS_ENSURE_SUCCESS(res, res);
-  if (!nodeList) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nodeList, NS_ERROR_NULL_POINTER);
   PRUint32 nodeOrigLen;
   nodeList->GetLength(&nodeOrigLen);
 
   // notify our internal selection state listener
   nsAutoRemoveContainerSelNotify selNotify(mRangeUpdater, inNode, parent, offset, nodeOrigLen);
                                    
   nsCOMPtr<nsIDOMNode> child;
   while (bHasMoreChildren)
@@ -1814,17 +1814,17 @@ nsEditor::DumpContentTree()
 }
 
 
 NS_IMETHODIMP
 nsEditor::DebugDumpContent()
 {
 #ifdef DEBUG
   nsCOMPtr<nsIDOMHTMLDocument> doc = do_QueryReferent(mDocWeak);
-  if (!doc) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIDOMHTMLElement>bodyElem;
   doc->GetBody(getter_AddRefs(bodyElem));
   nsCOMPtr<nsIContent> content = do_QueryInterface(bodyElem);
   if (content)
     content->List();
 #endif
   return NS_OK;
@@ -1897,17 +1897,17 @@ nsEditor::BeginComposition()
     mPhonetic->Truncate(0);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEditor::EndComposition(void)
 {
-  if (!mInIMEMode) return NS_OK; // nothing to do
+  NS_ENSURE_TRUE(mInIMEMode, NS_OK); // nothing to do
   
   nsresult result = NS_OK;
 
   // commit the IME transaction..we can get at it via the transaction mgr.
   // Note that this means IME won't work without an undo stack!
   if (mTxnMgr) 
   {
     nsCOMPtr<nsITransaction> txn;
@@ -2295,29 +2295,29 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(c
                                           nsCOMPtr<nsIDOMNode> *aInOutNode, 
                                           PRInt32 *aInOutOffset,
                                           nsIDOMDocument *aDoc)
 {
   // NOTE: caller *must* have already used nsAutoTxnsConserveSelection stack-based
   // class to turn off txn selection updating.  Caller also turned on rules sniffing
   // if desired.
   
-  if (!aInOutNode || !*aInOutNode || !aInOutOffset || !aDoc) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aInOutNode && *aInOutNode && aInOutOffset && aDoc, NS_ERROR_NULL_POINTER);
   if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK;
   nsCOMPtr<nsIDOMText> nodeAsText = do_QueryInterface(*aInOutNode);
   PRInt32 offset = *aInOutOffset;
   nsresult res;
   if (mInIMEMode)
   {
     if (!nodeAsText)
     {
       // create a text node
       res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText));
       NS_ENSURE_SUCCESS(res, res);
-      if (!nodeAsText) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
       nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText);
       // then we insert it into the dom tree
       res = InsertNode(newNode, *aInOutNode, offset);
       NS_ENSURE_SUCCESS(res, res);
       offset = 0;
     }
     res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
     NS_ENSURE_SUCCESS(res, res);
@@ -2332,17 +2332,17 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(c
       *aInOutOffset += aStringToInsert.Length();
     }
     else
     {
       // we are inserting text into a non-text node
       // first we have to create a textnode (this also populates it with the text)
       res = aDoc->CreateTextNode(aStringToInsert, getter_AddRefs(nodeAsText));
       NS_ENSURE_SUCCESS(res, res);
-      if (!nodeAsText) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
       nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText);
       // then we insert it into the dom tree
       res = InsertNode(newNode, *aInOutNode, offset);
       NS_ENSURE_SUCCESS(res, res);
       *aInOutNode = newNode;
       *aInOutOffset = aStringToInsert.Length();
     }
   }
@@ -2469,17 +2469,17 @@ NS_IMETHODIMP nsEditor::SelectEntireDocu
   if (!rootElement) { return NS_ERROR_NOT_INITIALIZED; }
 
   return aSelection->SelectAllChildren(rootElement);
 }
 
 
 nsresult nsEditor::GetFirstEditableNode(nsIDOMNode *aRoot, nsCOMPtr<nsIDOMNode> *outFirstNode)
 {
-  if (!aRoot || !outFirstNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRoot && outFirstNode, NS_ERROR_NULL_POINTER);
   nsresult rv = NS_OK;
   *outFirstNode = nsnull;
 
   nsCOMPtr<nsIDOMNode> node = GetLeftmostChild(aRoot);
   if (node && !IsEditable(node))
   {
     nsCOMPtr<nsIDOMNode> next;
     rv = GetNextNode(node, PR_TRUE, address_of(next));
@@ -2491,17 +2491,17 @@ nsresult nsEditor::GetFirstEditableNode(
 
   return rv;
 }
 
 #ifdef XXX_DEAD_CODE
 // jfrancis wants to keep this method around for reference
 nsresult nsEditor::GetLastEditableNode(nsIDOMNode *aRoot, nsCOMPtr<nsIDOMNode> *outLastNode)
 {
-  if (!aRoot || !outLastNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRoot && outLastNode, NS_ERROR_NULL_POINTER);
   nsresult rv = NS_OK;
   *outLastNode = nsnull;
 
   nsCOMPtr<nsIDOMNode> node = GetRightmostChild(aRoot);
   if (node && !IsEditable(node))
   {
     nsCOMPtr<nsIDOMNode> next;
     rv = GetPriorNode(node, PR_TRUE, address_of(next));
@@ -2575,21 +2575,21 @@ nsEditor::NotifyDocumentListeners(TDocum
 }
 
 
 NS_IMETHODIMP nsEditor::CreateTxnForInsertText(const nsAString & aStringToInsert,
                                                nsIDOMCharacterData *aTextNode,
                                                PRInt32 aOffset,
                                                InsertTextTxn ** aTxn)
 {
-  if (!aTextNode || !aTxn) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTextNode && aTxn, NS_ERROR_NULL_POINTER);
   nsresult result;
 
   *aTxn = new InsertTextTxn();
-  if (!*aTxn) return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
   NS_ADDREF(*aTxn);
   result = (*aTxn)->Init(aTextNode, aOffset, aStringToInsert, this);
   return result;
 }
 
 
 NS_IMETHODIMP nsEditor::DeleteText(nsIDOMCharacterData *aElement,
                               PRUint32             aOffset,
@@ -2693,17 +2693,17 @@ nsEditor::SplitNodeImpl(nsIDOMNode * aEx
   if ((nsnull!=aExistingRightNode) &&
       (nsnull!=aNewLeftNode) &&
       (nsnull!=aParent))
   {
     // get selection
     nsCOMPtr<nsISelection> selection;
     result = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(result, result);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
     // remember some selection points
     nsCOMPtr<nsIDOMNode> selStartNode, selEndNode;
     PRInt32 selStartOffset, selEndOffset;
     result = GetStartNodeAndOffset(selection, getter_AddRefs(selStartNode), &selStartOffset);
     if (NS_FAILED(result)) selStartNode = nsnull;  // if selection is cleared, remember that
     result = GetEndNodeAndOffset(selection, getter_AddRefs(selEndNode), &selEndOffset);
     if (NS_FAILED(result)) selStartNode = nsnull;  // if selection is cleared, remember that
@@ -2814,17 +2814,17 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNo
 {
   NS_ASSERTION(aNodeToKeep && aNodeToJoin && aParent, "null arg");
   nsresult result;
   if (aNodeToKeep && aNodeToJoin && aParent)
   {
     // get selection
     nsCOMPtr<nsISelection> selection;
     GetSelection(getter_AddRefs(selection));
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
     // remember some selection points
     nsCOMPtr<nsIDOMNode> selStartNode, selEndNode;
     PRInt32 selStartOffset, selEndOffset, joinOffset, keepOffset;
     result = GetStartNodeAndOffset(selection, getter_AddRefs(selStartNode), &selStartOffset);
     if (NS_FAILED(result)) selStartNode = nsnull;
     result = GetEndNodeAndOffset(selection, getter_AddRefs(selEndNode), &selEndOffset);
     // Joe or Kin should comment here on why the following line is not a copy/paste error
@@ -3401,17 +3401,17 @@ nsEditor::GetNextNodeImpl(nsIDOMNode  *a
   return result;
 }
 
 
 nsCOMPtr<nsIDOMNode>
 nsEditor::GetRightmostChild(nsIDOMNode *aCurrentNode, 
                             PRBool bNoBlockCrossing)
 {
-  if (!aCurrentNode) return nsnull;
+  NS_ENSURE_TRUE(aCurrentNode, nsnull);
   nsCOMPtr<nsIDOMNode> resultNode, temp=aCurrentNode;
   PRBool hasChildren;
   aCurrentNode->HasChildNodes(&hasChildren);
   while (hasChildren)
   {
     temp->GetLastChild(getter_AddRefs(resultNode));
     if (resultNode)
     {
@@ -3426,17 +3426,17 @@ nsEditor::GetRightmostChild(nsIDOMNode *
 
   return resultNode;
 }
 
 nsCOMPtr<nsIDOMNode>
 nsEditor::GetLeftmostChild(nsIDOMNode *aCurrentNode,
                            PRBool bNoBlockCrossing)
 {
-  if (!aCurrentNode) return nsnull;
+  NS_ENSURE_TRUE(aCurrentNode, nsnull);
   nsCOMPtr<nsIDOMNode> resultNode, temp=aCurrentNode;
   PRBool hasChildren;
   aCurrentNode->HasChildNodes(&hasChildren);
   while (hasChildren)
   {
     temp->GetFirstChild(getter_AddRefs(resultNode));
     if (resultNode)
     {
@@ -3461,17 +3461,17 @@ nsEditor::IsBlockNode(nsIDOMNode *aNode)
   // across both nsEditor/nsHTMLEditor.  
   return PR_FALSE;
 }
 
 PRBool 
 nsEditor::CanContainTag(nsIDOMNode* aParent, const nsAString &aChildTag)
 {
   nsCOMPtr<nsIDOMElement> parentElement = do_QueryInterface(aParent);
-  if (!parentElement) return PR_FALSE;
+  NS_ENSURE_TRUE(parentElement, PR_FALSE);
   
   nsAutoString parentStringTag;
   parentElement->GetTagName(parentStringTag);
   return TagCanContainTag(parentStringTag, aChildTag);
 }
 
 PRBool 
 nsEditor::TagCanContain(const nsAString &aParentTag, nsIDOMNode* aChild)
@@ -3480,17 +3480,17 @@ nsEditor::TagCanContain(const nsAString 
   
   if (IsTextNode(aChild)) 
   {
     childStringTag.AssignLiteral("#text");
   }
   else
   {
     nsCOMPtr<nsIDOMElement> childElement = do_QueryInterface(aChild);
-    if (!childElement) return PR_FALSE;
+    NS_ENSURE_TRUE(childElement, PR_FALSE);
     childElement->GetTagName(childStringTag);
   }
   return TagCanContainTag(aParentTag, childStringTag);
 }
 
 PRBool 
 nsEditor::TagCanContainTag(const nsAString &aParentTag, const nsAString &aChildTag)
 {
@@ -3508,19 +3508,19 @@ nsEditor::IsRootNode(nsIDOMNode *inNode)
   nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(rootElement);
 
   return inNode == rootNode;
 }
 
 PRBool 
 nsEditor::IsDescendantOfBody(nsIDOMNode *inNode) 
 {
-  if (!inNode) return PR_FALSE;
+  NS_ENSURE_TRUE(inNode, PR_FALSE);
   nsIDOMElement *rootElement = GetRoot();
-  if (!rootElement) return PR_FALSE;
+  NS_ENSURE_TRUE(rootElement, PR_FALSE);
   nsCOMPtr<nsIDOMNode> root = do_QueryInterface(rootElement);
 
   if (inNode == root.get()) return PR_TRUE;
   
   nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(inNode);
   
   do
   {
@@ -3547,17 +3547,17 @@ nsEditor::IsTextInDirtyFrameVisible(nsID
   // the best we can do is to assume it's visible.
 
   return PR_TRUE;
 }
 
 PRBool 
 nsEditor::IsEditable(nsIDOMNode *aNode)
 {
-  if (!aNode) return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
 
   if (IsMozEditorBogusNode(aNode) || !IsModifiableNode(aNode)) return PR_FALSE;
 
   // see if it has a frame.  If so, we'll edit it.
   // special case for textnodes: frame must have width.
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   if (content)
   {
@@ -3887,20 +3887,20 @@ nsEditor::GetEndNodeAndOffset(nsISelecti
 ///////////////////////////////////////////////////////////////////////////
 // IsPreformatted: checks the style info for the node for the preformatted
 //                 text style.
 nsresult 
 nsEditor::IsPreformatted(nsIDOMNode *aNode, PRBool *aResult)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   
-  if (!aResult || !content) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aResult && content, 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);
 
   nsRefPtr<nsStyleContext> elementStyle;
   if (content->IsElement()) {
     elementStyle = nsComputedDOMStyle::GetStyleContextForElement(content->AsElement(),
                                                                  nsnull,
                                                                  ps);
   }
 
@@ -3934,17 +3934,17 @@ nsresult
 nsEditor::SplitNodeDeep(nsIDOMNode *aNode, 
                         nsIDOMNode *aSplitPointParent, 
                         PRInt32 aSplitPointOffset,
                         PRInt32 *outOffset,
                         PRBool  aNoEmptyContainers,
                         nsCOMPtr<nsIDOMNode> *outLeftNode,
                         nsCOMPtr<nsIDOMNode> *outRightNode)
 {
-  if (!aNode || !aSplitPointParent || !outOffset) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aSplitPointParent && outOffset, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> tempNode, parentNode;  
   PRInt32 offset = aSplitPointOffset;
   nsresult res;
   
   if (outLeftNode)  *outLeftNode  = nsnull;
   if (outRightNode) *outRightNode = nsnull;
   
   nsCOMPtr<nsIDOMNode> nodeToSplit = do_QueryInterface(aSplitPointParent);
@@ -3968,17 +3968,17 @@ nsEditor::SplitNodeDeep(nsIDOMNode *aNod
       res = SplitNode(nodeToSplit, offset, getter_AddRefs(tempNode));
       NS_ENSURE_SUCCESS(res, res);
       if (outRightNode) *outRightNode = nodeToSplit;
       if (outLeftNode)  *outLeftNode  = tempNode;
     }
 
     res = nodeToSplit->GetParentNode(getter_AddRefs(parentNode));
     NS_ENSURE_SUCCESS(res, res);
-    if (!parentNode) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(parentNode, NS_ERROR_FAILURE);
 
     if (!bDoSplit && offset)  // must be "end of text node" case, we didn't split it, just move past it
     {
       offset = GetIndexOf(parentNode, nodeToSplit) +1;
       if (outLeftNode)  *outLeftNode  = nodeToSplit;
     }
     else
     {
@@ -4008,17 +4008,17 @@ nsEditor::SplitNodeDeep(nsIDOMNode *aNod
 // JoinNodeDeep:  this joins two like nodes "deeply", joining children as 
 //                appropriate.  
 nsresult
 nsEditor::JoinNodeDeep(nsIDOMNode *aLeftNode, 
                        nsIDOMNode *aRightNode,
                        nsCOMPtr<nsIDOMNode> *aOutJoinNode, 
                        PRInt32 *outOffset)
 {
-  if (!aLeftNode || !aRightNode || !aOutJoinNode || !outOffset) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aLeftNode && aRightNode && aOutJoinNode && outOffset, NS_ERROR_NULL_POINTER);
 
   // while the rightmost children and their descendants of the left node 
   // match the leftmost children and their descendants of the right node
   // join them up.  Can you say that three times fast?
   
   nsCOMPtr<nsIDOMNode> leftNodeToJoin = do_QueryInterface(aLeftNode);
   nsCOMPtr<nsIDOMNode> rightNodeToJoin = do_QueryInterface(aRightNode);
   nsCOMPtr<nsIDOMNode> parentNode,tmp;
@@ -4261,17 +4261,17 @@ nsEditor::DeleteSelectionAndCreateNode(c
   // XXX: ERROR_HANDLING  check result, and make sure aNewNode is set correctly in success/failure cases
   *aNewNode = newNode;
   NS_IF_ADDREF(*aNewNode);
 
   // we want the selection to be just after the new node
   nsCOMPtr<nsISelection> selection;
   result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   return selection->Collapse(parentSelectedNode, offsetOfNewNode+1);
 }
 
 
 /* Non-interface, protected methods */
 
 nsresult
 nsEditor::GetIMEBufferLength(PRInt32* length)
@@ -4317,17 +4317,17 @@ nsEditor::IsIMEComposing() {
 
 NS_IMETHODIMP
 nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parentSelectedNode, PRInt32& offsetOfNewNode)
 {
   nsresult result=NS_ERROR_NOT_INITIALIZED;
   nsCOMPtr<nsISelection> selection;
   result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   PRBool collapsed;
   result = selection->GetIsCollapsed(&collapsed);
   if (NS_SUCCEEDED(result) && !collapsed) 
   {
     result = DeleteSelection(nsIEditor::eNone);
     if (NS_FAILED(result)) {
       return result;
@@ -4579,17 +4579,17 @@ nsEditor::CreateTxnForDeleteSelection(ns
                                       PRInt32 *aOffset,
                                       PRInt32 *aLength)
 {
   if (!aTxn)
     return NS_ERROR_NULL_POINTER;
   *aTxn = nsnull;
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
-  if (!selCon) return NS_ERROR_NOT_INITIALIZED;
+  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)
   {
     // Check whether the selection is collapsed and we should do nothing:
     PRBool isCollapsed;
     result = (selection->GetIsCollapsed(&isCollapsed));
@@ -4897,45 +4897,45 @@ nsEditor::CreateRange(nsIDOMNode *aStart
     *aRange = 0;
   }
   return result;
 }
 
 nsresult 
 nsEditor::AppendNodeToSelectionAsRange(nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   if(!selection) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMNode> parentNode;
   res = aNode->GetParentNode(getter_AddRefs(parentNode));
   NS_ENSURE_SUCCESS(res, res);
-  if (!parentNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(parentNode, NS_ERROR_NULL_POINTER);
   
   PRInt32 offset;
   res = GetChildOffset(aNode, parentNode, offset);
   NS_ENSURE_SUCCESS(res, res);
   
   nsCOMPtr<nsIDOMRange> range;
   res = CreateRange(parentNode, offset, parentNode, offset+1, getter_AddRefs(range));
   NS_ENSURE_SUCCESS(res, res);
-  if (!range) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
 
   return selection->AddRange(range);
 }
 
 nsresult nsEditor::ClearSelection()
 {
   nsCOMPtr<nsISelection> selection;
   nsresult res = nsEditor::GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   return selection->RemoveAllRanges();  
 }
 
 nsresult
 nsEditor::CreateHTMLContent(const nsAString& aTag, nsIContent** aContent)
 {
   nsCOMPtr<nsIDOMDocument> tempDoc;
   GetDocument(getter_AddRefs(tempDoc));
@@ -5181,17 +5181,17 @@ nsEditor::DumpNode(nsIDOMNode *aNode, PR
       printf("<%s>\n", NS_LossyConvertUTF16toASCII(tag).get());
     }
     else
     {
       printf("<document fragment>\n");
     }
     nsCOMPtr<nsIDOMNodeList> childList;
     aNode->GetChildNodes(getter_AddRefs(childList));
-    if (!childList) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(childList, NS_ERROR_NULL_POINTER);
     PRUint32 numChildren;
     childList->GetLength(&numChildren);
     nsCOMPtr<nsIDOMNode> child, tmp;
     aNode->GetFirstChild(getter_AddRefs(child));
     for (i=0; i<numChildren; i++)
     {
       DumpNode(child, indent+1);
       child->GetNextSibling(getter_AddRefs(tmp));
--- a/editor/libeditor/base/nsEditorCommands.cpp
+++ b/editor/libeditor/base/nsEditorCommands.cpp
@@ -167,17 +167,17 @@ nsClearUndoCommand::IsCommandEnabled(con
   return NS_OK;
 }
   
 
 NS_IMETHODIMP
 nsClearUndoCommand::DoCommand(const char *aCommandName, nsISupports *refCon)
 { 
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
-  if (!editor) return NS_ERROR_NOT_IMPLEMENTED;
+  NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED);
   
   editor->EnableUndo(PR_FALSE);  // Turning off undo clears undo/redo stacks.
   editor->EnableUndo(PR_TRUE);   // This re-enables undo/redo.
   
   return NS_OK;
 }
                                   
 NS_IMETHODIMP                       
--- a/editor/libeditor/base/nsEditorController.cpp
+++ b/editor/libeditor/base/nsEditorController.cpp
@@ -44,26 +44,26 @@
 #include "nsIControllerCommandTable.h"
 
 
 
 #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName)                                      \
   {                                                                                       \
     _cmdClass* theCmd;                                                                    \
     NS_NEWXPCOM(theCmd, _cmdClass);                                                       \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                                           \
+    NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY);                                           \
     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
                                    static_cast<nsIControllerCommand *>(theCmd));          \
   }
 
 #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName)                                    \
   {                                                                                       \
     _cmdClass* theCmd;                                                                    \
     NS_NEWXPCOM(theCmd, _cmdClass);                                                       \
-    if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                                           \
+    NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY);                                           \
     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
                                    static_cast<nsIControllerCommand *>(theCmd));
 
 #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName)                                     \
     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
                                    static_cast<nsIControllerCommand *>(theCmd));
 
 #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName)                                     \
--- a/editor/libeditor/base/nsEditorEventListener.cpp
+++ b/editor/libeditor/base/nsEditorEventListener.cpp
@@ -736,17 +736,17 @@ nsEditorEventListener::CanDrop(nsIDOMDra
     PRBool isCollapsed;
     rv = selection->GetIsCollapsed(&isCollapsed);
     NS_ENSURE_SUCCESS(rv, PR_FALSE);
   
     // Don't bother if collapsed - can always drop
     if (!isCollapsed)
     {
       nsCOMPtr<nsIDOMNSUIEvent> nsuiEvent (do_QueryInterface(aEvent));
-      if (!nsuiEvent) return PR_FALSE;
+      NS_ENSURE_TRUE(nsuiEvent, PR_FALSE);
 
       nsCOMPtr<nsIDOMNode> parent;
       rv = nsuiEvent->GetRangeParent(getter_AddRefs(parent));
       if (NS_FAILED(rv) || !parent) return PR_FALSE;
 
       PRInt32 offset = 0;
       rv = nsuiEvent->GetRangeOffset(&offset);
       NS_ENSURE_SUCCESS(rv, PR_FALSE);
--- a/editor/libeditor/base/nsEditorUtils.cpp
+++ b/editor/libeditor/base/nsEditorUtils.cpp
@@ -101,27 +101,27 @@ nsDOMIterator::~nsDOMIterator()
 }
     
 nsresult
 nsDOMIterator::Init(nsIDOMRange* aRange)
 {
   nsresult res;
   mIter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
   NS_ENSURE_SUCCESS(res, res);
-  if (!mIter) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIter, NS_ERROR_FAILURE);
   return mIter->Init(aRange);
 }
 
 nsresult
 nsDOMIterator::Init(nsIDOMNode* aNode)
 {
   nsresult res;
   mIter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
   NS_ENSURE_SUCCESS(res, res);
-  if (!mIter) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIter, NS_ERROR_FAILURE);
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   return mIter->Init(content);
 }
 
 void
 nsDOMIterator::ForEach(nsDomIterFunctor& functor) const
 {
   nsCOMPtr<nsIDOMNode> node;
@@ -169,39 +169,39 @@ nsDOMSubtreeIterator::~nsDOMSubtreeItera
 }
     
 nsresult
 nsDOMSubtreeIterator::Init(nsIDOMRange* aRange)
 {
   nsresult res;
   mIter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
   NS_ENSURE_SUCCESS(res, res);
-  if (!mIter) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIter, NS_ERROR_FAILURE);
   return mIter->Init(aRange);
 }
 
 nsresult
 nsDOMSubtreeIterator::Init(nsIDOMNode* aNode)
 {
   nsresult res;
   mIter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
   NS_ENSURE_SUCCESS(res, res);
-  if (!mIter) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(mIter, NS_ERROR_FAILURE);
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
   return mIter->Init(content);
 }
 
 /******************************************************************************
  * some general purpose editor utils
  *****************************************************************************/
 
 PRBool 
 nsEditorUtils::IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 *aOffset) 
 {
-  if (!aNode && !aParent) return PR_FALSE;
+  NS_ENSURE_TRUE(aNode || aParent, PR_FALSE);
   if (aNode == aParent) return PR_FALSE;
   
   nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(aNode);
   nsresult res;
   
   do
   {
     res = node->GetParentNode(getter_AddRefs(parent));
@@ -238,22 +238,22 @@ nsEditorUtils::IsLeafNode(nsIDOMNode *aN
  * utility methods for drag/drop/copy/paste hooks
  *****************************************************************************/
 
 nsresult
 nsEditorHookUtils::GetHookEnumeratorFromDocument(nsIDOMDocument *aDoc,
                                                  nsISimpleEnumerator **aResult)
 {
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
-  if (!doc) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsISupports> container = doc->GetContainer();
   nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
   nsCOMPtr<nsIClipboardDragDropHookList> hookObj = do_GetInterface(docShell);
-  if (!hookObj) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(hookObj, NS_ERROR_FAILURE);
 
   return hookObj->GetHookEnumerator(aResult);
 }
 
 PRBool
 nsEditorHookUtils::DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aDropEvent,  
                                    nsITransferable *aTrans)
 {
--- a/editor/libeditor/base/nsSelectionState.cpp
+++ b/editor/libeditor/base/nsSelectionState.cpp
@@ -69,17 +69,17 @@ nsSelectionState::DoTraverse(nsCycleColl
                                        "selection state mArray[i].endNode");
     cb.NoteXPCOMChild(item.endNode);
   }
 }
 
 nsresult  
 nsSelectionState::SaveSelection(nsISelection *aSel)
 {
-  if (!aSel) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
   PRInt32 i,rangeCount, arrayCount = mArray.Length();
   aSel->GetRangeCount(&rangeCount);
   
   // if we need more items in the array, new them
   if (arrayCount<rangeCount)
   {
     PRInt32 count = rangeCount-arrayCount;
     for (i=0; i<count; i++)
@@ -107,63 +107,63 @@ nsSelectionState::SaveSelection(nsISelec
   }
   
   return res;
 }
 
 nsresult  
 nsSelectionState::RestoreSelection(nsISelection *aSel)
 {
-  if (!aSel) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
   nsresult res;
   PRUint32 i, arrayCount = mArray.Length();
 
   // clear out selection
   aSel->RemoveAllRanges();
   
   // set the selection ranges anew
   for (i=0; i<arrayCount; i++)
   {
     nsCOMPtr<nsIDOMRange> range;
     mArray[i].GetRange(address_of(range));
-    if (!range) return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(range, NS_ERROR_UNEXPECTED);
    
     res = aSel->AddRange(range);
     if(NS_FAILED(res)) return res;
 
   }
   return NS_OK;
 }
 
 PRBool
 nsSelectionState::IsCollapsed()
 {
   if (1 != mArray.Length()) return PR_FALSE;
   nsCOMPtr<nsIDOMRange> range;
   mArray[0].GetRange(address_of(range));
-  if (!range) return PR_FALSE;
+  NS_ENSURE_TRUE(range, PR_FALSE);
   PRBool bIsCollapsed;
   range->GetCollapsed(&bIsCollapsed);
   return bIsCollapsed;
 }
 
 PRBool
 nsSelectionState::IsEqual(nsSelectionState *aSelState)
 {
-  if (!aSelState) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelState, NS_ERROR_NULL_POINTER);
   PRUint32 i, myCount = mArray.Length(), itsCount = aSelState->mArray.Length();
   if (myCount != itsCount) return PR_FALSE;
   if (myCount < 1) return PR_FALSE;
 
   for (i=0; i<myCount; i++)
   {
     nsCOMPtr<nsIDOMRange> myRange, itsRange;
     mArray[i].GetRange(address_of(myRange));
     aSelState->mArray[i].GetRange(address_of(itsRange));
-    if (!myRange || !itsRange) return PR_FALSE;
+    NS_ENSURE_TRUE(myRange && itsRange, PR_FALSE);
   
     PRInt16 compResult;
     myRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, itsRange, &compResult);
     if (compResult) return PR_FALSE;
     myRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, itsRange, &compResult);
     if (compResult) return PR_FALSE;
   }
   // if we got here, they are equal
@@ -242,26 +242,26 @@ nsRangeUpdater::DropSelectionState(nsSel
 }
 
 // gravity methods:
 
 nsresult
 nsRangeUpdater::SelAdjCreateNode(nsIDOMNode *aParent, PRInt32 aPosition)
 {
   if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
-  if (!aParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aParent, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsRangeStore *item;
   
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if ((item->startNode.get() == aParent) && (item->startOffset > aPosition))
       item->startOffset++;
     if ((item->endNode.get() == aParent) && (item->endOffset > aPosition))
       item->endOffset++;
   }
   return NS_OK;
 }
@@ -272,32 +272,32 @@ nsRangeUpdater::SelAdjInsertNode(nsIDOMN
   return SelAdjCreateNode(aParent, aPosition);
 }
 
 
 nsresult
 nsRangeUpdater::SelAdjDeleteNode(nsIDOMNode *aNode)
 {
   if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset = 0;
   
   nsresult res = nsEditor::GetNodeLocation(aNode, address_of(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
   
   // check for range endpoints that are after aNode and in the same parent
   nsRangeStore *item;
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if ((item->startNode.get() == parent) && (item->startOffset > offset))
       item->startOffset--;
     if ((item->endNode.get() == parent) && (item->endOffset > offset))
       item->endOffset--;
       
     // check for range endpoints that are in aNode
     if (item->startNode == aNode)
@@ -330,36 +330,36 @@ nsRangeUpdater::SelAdjDeleteNode(nsIDOMN
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::SelAdjSplitNode(nsIDOMNode *aOldRightNode, PRInt32 aOffset, nsIDOMNode *aNewLeftNode)
 {
   if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
-  if (!aOldRightNode || !aNewLeftNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOldRightNode && aNewLeftNode, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   nsresult result = nsEditor::GetNodeLocation(aOldRightNode, address_of(parent), &offset);
   NS_ENSURE_SUCCESS(result, result);
   
   // first part is same as inserting aNewLeftnode
   result = SelAdjInsertNode(parent,offset-1);
   NS_ENSURE_SUCCESS(result, result);
 
   // next step is to check for range enpoints inside aOldRightNode
   nsRangeStore *item;
   
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if (item->startNode.get() == aOldRightNode)
     {
       if (item->startOffset > aOffset)
       {
         item->startOffset -= aOffset;
       }
       else
@@ -386,26 +386,26 @@ nsRangeUpdater::SelAdjSplitNode(nsIDOMNo
 nsresult
 nsRangeUpdater::SelAdjJoinNodes(nsIDOMNode *aLeftNode, 
                                   nsIDOMNode *aRightNode, 
                                   nsIDOMNode *aParent, 
                                   PRInt32 aOffset,
                                   PRInt32 aOldLeftNodeLength)
 {
   if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
-  if (!aLeftNode || !aRightNode || !aParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aLeftNode && aRightNode && aParent, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsRangeStore *item;
 
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if (item->startNode.get() == aParent)
     {
       // adjust start point in aParent
       if (item->startOffset > aOffset)
       {
         item->startOffset--;
       }
@@ -458,51 +458,51 @@ nsRangeUpdater::SelAdjJoinNodes(nsIDOMNo
 
 
 nsresult
 nsRangeUpdater::SelAdjInsertText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, const nsAString &aString)
 {
   if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
 
   PRUint32 count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aTextNode));
-  if (!node) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
   
   PRUint32 len=aString.Length(), i;
   nsRangeStore *item;
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if ((item->startNode.get() == node) && (item->startOffset > aOffset))
       item->startOffset += len;
     if ((item->endNode.get() == node) && (item->endOffset > aOffset))
       item->endOffset += len;
   }
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::SelAdjDeleteText(nsIDOMCharacterData *aTextNode, PRInt32 aOffset, PRInt32 aLength)
 {
   if (mLock) return NS_OK;  // lock set by Will/DidReplaceParent, etc...
 
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
   nsRangeStore *item;
   nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aTextNode));
-  if (!node) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
   
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if ((item->startNode.get() == node) && (item->startOffset > aOffset))
     {
       item->startOffset -= aLength;
       if (item->startOffset < 0) item->startOffset = 0;
     }
     if ((item->endNode.get() == node) && (item->endOffset > aOffset))
     {
@@ -521,29 +521,29 @@ nsRangeUpdater::WillReplaceContainer()
   mLock = PR_TRUE;
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::DidReplaceContainer(nsIDOMNode *aOriginalNode, nsIDOMNode *aNewNode)
 {
-  if (!mLock) return NS_ERROR_UNEXPECTED;  
+  NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);  
   mLock = PR_FALSE;
 
-  if (!aOriginalNode || !aNewNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOriginalNode && aNewNode, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsRangeStore *item;
   
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if (item->startNode.get() == aOriginalNode)
       item->startNode = aNewNode;
     if (item->endNode.get() == aOriginalNode)
       item->endNode = aNewNode;
   }
   return NS_OK;
 }
@@ -556,29 +556,29 @@ nsRangeUpdater::WillRemoveContainer()
   mLock = PR_TRUE;
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::DidRemoveContainer(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset, PRUint32 aNodeOrigLen)
 {
-  if (!mLock) return NS_ERROR_UNEXPECTED;  
+  NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);  
   mLock = PR_FALSE;
 
-  if (!aNode || !aParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aParent, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsRangeStore *item;
   
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     if (item->startNode.get() == aNode)
     {
       item->startNode = aParent;
       item->startOffset += aOffset;
     }
     else if ((item->startNode.get() == aParent) && (item->startOffset > aOffset))
       item->startOffset += (PRInt32)aNodeOrigLen-1;
@@ -602,17 +602,17 @@ nsRangeUpdater::WillInsertContainer()
   mLock = PR_TRUE;
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::DidInsertContainer()
 {
-  if (!mLock) return NS_ERROR_UNEXPECTED;  
+  NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);  
   mLock = PR_FALSE;
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::WillMoveNode()
 {
@@ -620,29 +620,29 @@ nsRangeUpdater::WillMoveNode()
   mLock = PR_TRUE;
   return NS_OK;
 }
 
 
 nsresult
 nsRangeUpdater::DidMoveNode(nsIDOMNode *aOldParent, PRInt32 aOldOffset, nsIDOMNode *aNewParent, PRInt32 aNewOffset)
 {
-  if (!mLock) return NS_ERROR_UNEXPECTED;  
+  NS_ENSURE_TRUE(mLock, NS_ERROR_UNEXPECTED);  
   mLock = PR_FALSE;
 
-  if (!aOldParent || !aNewParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOldParent && aNewParent, NS_ERROR_NULL_POINTER);
   PRUint32 i, count = mArray.Length();
-  if (!count) return NS_OK;
+  NS_ENSURE_TRUE(count, NS_OK);
 
   nsRangeStore *item;
   
   for (i=0; i<count; i++)
   {
     item = mArray[i];
-    if (!item) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
     
     // like a delete in aOldParent
     if ((item->startNode.get() == aOldParent) && (item->startOffset > aOldOffset))
       item->startOffset--;
     if ((item->endNode.get() == aOldParent) && (item->endOffset > aOldOffset))
       item->endOffset--;
       
     // and like an insert in aNewParent
@@ -668,27 +668,27 @@ nsRangeStore::nsRangeStore()
 }
 nsRangeStore::~nsRangeStore()
 {
   // DEBUG: n--;  printf("range store alloc count=%d\n", n); 
 }
 
 nsresult nsRangeStore::StoreRange(nsIDOMRange *aRange)
 {
-  if (!aRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRange, NS_ERROR_NULL_POINTER);
   aRange->GetStartContainer(getter_AddRefs(startNode));
   aRange->GetEndContainer(getter_AddRefs(endNode));
   aRange->GetStartOffset(&startOffset);
   aRange->GetEndOffset(&endOffset);
   return NS_OK;
 }
 
 nsresult nsRangeStore::GetRange(nsCOMPtr<nsIDOMRange> *outRange)
 {
-  if (!outRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outRange, NS_ERROR_NULL_POINTER);
   nsresult res;
   *outRange = do_CreateInstance("@mozilla.org/content/range;1", &res);
   if(NS_FAILED(res)) return res;
 
   res = (*outRange)->SetStart(startNode, startOffset);
   if(NS_FAILED(res)) return res;
 
   res = (*outRange)->SetEnd(endNode, endOffset);
--- a/editor/libeditor/html/TypeInState.cpp
+++ b/editor/libeditor/html/TypeInState.cpp
@@ -64,17 +64,17 @@ TypeInState::~TypeInState()
   // Call Reset() to release any data that may be in
   // mClearedArray and mSetArray.
 
   Reset();
 }
 
 nsresult TypeInState::UpdateSelState(nsISelection *aSelection)
 {
-  if (!aSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   
   PRBool isCollapsed = PR_FALSE;
   nsresult result = aSelection->GetIsCollapsed(&isCollapsed);
 
   NS_ENSURE_SUCCESS(result, result);
 
   if (isCollapsed)
   {
@@ -177,17 +177,17 @@ nsresult TypeInState::SetProp(nsIAtom *a
     // if it's already set, update the value
     item = mSetArray[index];
     item->value = aValue;
   }
   else 
   {
     // make a new propitem
     item = new PropItem(aProp,aAttr,aValue);
-    if (!item) return NS_ERROR_OUT_OF_MEMORY;
+    NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
     
     // add it to the list of set properties
     mSetArray.AppendElement(item);
     
     // remove it from the list of cleared properties, if we have a match
     RemovePropFromClearedList(aProp,aAttr);  
   }
     
@@ -208,17 +208,17 @@ nsresult TypeInState::ClearProp(nsIAtom 
 
 nsresult TypeInState::ClearProp(nsIAtom *aProp, const nsString &aAttr)
 {
   // if it's already cleared we are done
   if (IsPropCleared(aProp,aAttr)) return NS_OK;
   
   // make a new propitem
   PropItem *item = new PropItem(aProp,aAttr,EmptyString());
-  if (!item) return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(item, NS_ERROR_OUT_OF_MEMORY);
   
   // remove it from the list of set properties, if we have a match
   RemovePropFromSetList(aProp,aAttr);
   
   // add it to the list of cleared properties
   mClearedArray.AppendElement(item);
   
   return NS_OK;
@@ -226,17 +226,17 @@ nsresult TypeInState::ClearProp(nsIAtom 
 
 
 /***************************************************************************
  *    TakeClearProperty: hands back next property item on the clear list.
  *                       caller assumes ownership of PropItem and must delete it.
  */  
 nsresult TypeInState::TakeClearProperty(PropItem **outPropItem)
 {
-  if (!outPropItem) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outPropItem, NS_ERROR_NULL_POINTER);
   *outPropItem = nsnull;
   PRUint32 count = mClearedArray.Length();
   if (count)
   {
     count--; // indizes are zero based
     *outPropItem = mClearedArray[count];
     mClearedArray.RemoveElementAt(count);
   }
@@ -244,34 +244,34 @@ nsresult TypeInState::TakeClearProperty(
 }
 
 /***************************************************************************
  *    TakeSetProperty: hands back next poroperty item on the set list.
  *                     caller assumes ownership of PropItem and must delete it.
  */  
 nsresult TypeInState::TakeSetProperty(PropItem **outPropItem)
 {
-  if (!outPropItem) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outPropItem, NS_ERROR_NULL_POINTER);
   *outPropItem = nsnull;
   PRUint32 count = mSetArray.Length();
   if (count)
   {
     count--; // indizes are zero based
     *outPropItem = mSetArray[count];
     mSetArray.RemoveElementAt(count);
   }
   return NS_OK;
 }
 
 //**************************************************************************
 //    TakeRelativeFontSize: hands back relative font value, which is then
 //                          cleared out.
 nsresult TypeInState::TakeRelativeFontSize(PRInt32 *outRelSize)
 {
-  if (!outRelSize) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outRelSize, NS_ERROR_NULL_POINTER);
   *outRelSize = mRelativeFontSize;
   mRelativeFontSize = 0;
   return NS_OK;
 }
 
 nsresult TypeInState::GetTypingState(PRBool &isSet, PRBool &theSetting, nsIAtom *aProp)
 {
   return GetTypingState(isSet, theSetting, aProp, EmptyString(), nsnull);
--- a/editor/libeditor/html/nsHTMLAbsPosition.cpp
+++ b/editor/libeditor/html/nsHTMLAbsPosition.cpp
@@ -77,17 +77,17 @@ nsHTMLEditor::AbsolutePositionSelection(
                                             kOpRemoveAbsolutePosition,
                                  nsIEditor::eNext);
   
   // the line below does not match the code; should it be removed?
   // Find out if the selection is collapsed:
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(aEnabled ?
                            nsTextEditRules::kSetAbsolutePosition :
                            nsTextEditRules::kRemoveAbsolutePosition);
   PRBool cancel, handled;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (NS_FAILED(res) || cancel)
     return res;
@@ -193,17 +193,17 @@ nsHTMLEditor::RelativeChangeZIndex(PRInt
                                                  kOpIncreaseZIndex,
                                  nsIEditor::eNext);
   
   // brade: can we get rid of this comment?
   // Find out if the selection is collapsed:
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo((aChange < 0) ? nsTextEditRules::kDecreaseZIndex:
                                            nsTextEditRules::kIncreaseZIndex);
   PRBool cancel, handled;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(res))
     return res;
   
   return mRules->DidDoAction(selection, &ruleInfo, res);
@@ -317,17 +317,17 @@ nsHTMLEditor::HideGrabber()
   // are no document observers to notify, but we still want to
   // UnbindFromTree.
 
   nsCOMPtr<nsIDOMNode> parentNode;
   res = mGrabber->GetParentNode(getter_AddRefs(parentNode));
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIContent> parentContent = do_QueryInterface(parentNode);
-  if (!parentContent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(parentContent, NS_ERROR_NULL_POINTER);
 
   DeleteRefToAnonymousNode(mGrabber, parentContent, ps);
   mGrabber = nsnull;
   DeleteRefToAnonymousNode(mPositioningShadow, parentContent, ps);
   mPositioningShadow = nsnull;
 
   return NS_OK;
 }
@@ -424,24 +424,24 @@ nsHTMLEditor::GrabberClicked()
   return res;
 }
 
 nsresult
 nsHTMLEditor::EndMoving()
 {
   if (mPositioningShadow) {
     nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-    if (!ps) return NS_ERROR_NOT_INITIALIZED;
+    NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
     nsCOMPtr<nsIDOMNode> parentNode;
     nsresult res = mGrabber->GetParentNode(getter_AddRefs(parentNode));
     NS_ENSURE_SUCCESS(res, res);
 
     nsCOMPtr<nsIContent> parentContent( do_QueryInterface(parentNode) );
-    if (!parentContent) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(parentContent, NS_ERROR_FAILURE);
 
     DeleteRefToAnonymousNode(mPositioningShadow, parentContent, ps);
 
     mPositioningShadow = nsnull;
   }
   nsCOMPtr<nsPIDOMEventTarget> piTarget = GetPIDOMEventTarget();
 
   if (piTarget && mMouseMotionListenerP) {
@@ -552,17 +552,17 @@ nsHTMLEditor::AbsolutelyPositionElement(
     // container
     nsCOMPtr<nsIDOMNode> parentNode;
     res = aElement->GetParentNode(getter_AddRefs(parentNode));
     NS_ENSURE_SUCCESS(res, res);
 
     nsCOMPtr<nsIDOMNodeList> childNodes;
     res = parentNode->GetChildNodes(getter_AddRefs(childNodes));
     NS_ENSURE_SUCCESS(res, res);
-    if (!childNodes) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(childNodes, NS_ERROR_NULL_POINTER);
     PRUint32 childCount;
     res = childNodes->GetLength(&childCount);
     NS_ENSURE_SUCCESS(res, res);
 
     if (childCount == 1) {
       nsCOMPtr<nsIDOMNode> brNode;
       res = CreateBR(parentNode, 0, address_of(brNode));
     }
@@ -590,17 +590,17 @@ nsHTMLEditor::AbsolutelyPositionElement(
                                        EmptyString(), PR_FALSE);
     }
 
     PRBool hasStyleOrIdOrClass;
     res = HasStyleOrIdOrClass(aElement, &hasStyleOrIdOrClass);
     NS_ENSURE_SUCCESS(res, res);
     if (!hasStyleOrIdOrClass && nsHTMLEditUtils::IsDiv(aElement)) {
       nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
-      if (!htmlRules) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
       res = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement);
       NS_ENSURE_SUCCESS(res, res);
       res = RemoveContainer(aElement);
     }
   }
   return res;
 }
 
--- a/editor/libeditor/html/nsHTMLAnonymousUtils.cpp
+++ b/editor/libeditor/html/nsHTMLAnonymousUtils.cpp
@@ -149,21 +149,21 @@ nsHTMLEditor::CreateAnonymousElement(con
   nsCOMPtr<nsIContent> parentContent( do_QueryInterface(aParentNode) );
   if (!parentContent)
     return NS_OK;
 
   // Get the document
   nsCOMPtr<nsIDOMDocument> domDoc;
   GetDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-  if (!doc) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
 
   // Get the pres shell
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  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)
@@ -287,17 +287,17 @@ nsHTMLEditor::CheckSelectionStateForAnon
   // Don't change selection state if we're moving.
   if (mIsMoving) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMElement> focusElement;
   // let's get the containing element of the selection
   nsresult res  = GetSelectionContainer(getter_AddRefs(focusElement));
-  if (!focusElement) return NS_OK;
+  NS_ENSURE_TRUE(focusElement, NS_OK);
   NS_ENSURE_SUCCESS(res, res);
 
   // what's its tag?
   nsAutoString focusTagName;
   res = focusElement->GetTagName(focusTagName);
   NS_ENSURE_SUCCESS(res, res);
   ToLowerCase(focusTagName);
   nsCOMPtr<nsIAtom> focusTagAtom = do_GetAtom(focusTagName);
@@ -428,17 +428,17 @@ nsHTMLEditor::GetPositionAndDimensions(n
   }
 
   if (isPositioned) {
     // Yes, it is absolutely positioned
     mResizedObjectIsAbsolutelyPositioned = PR_TRUE;
 
     nsCOMPtr<nsIDOMViewCSS> viewCSS;
     res = mHTMLCSSUtils->GetDefaultViewCSS(aElement, getter_AddRefs(viewCSS));
-    if (!viewCSS) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(viewCSS, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
     // Get the all the computed css styles attached to the element node
     res = viewCSS->GetComputedStyle(aElement, EmptyString(), getter_AddRefs(cssDecl));
     NS_ENSURE_SUCCESS(res, res);
 
     aBorderLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-left-width"));
     aBorderTop  = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-top-width"));
--- a/editor/libeditor/html/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp
@@ -332,17 +332,17 @@ nsHTMLCSSUtils::IsCSSEditableProperty(ns
   NS_ASSERTION(aNode, "Shouldn't you pass aNode? - Bug 214025");
 
   nsCOMPtr<nsIDOMNode> node = aNode;
   // we need an element node here
   if (mHTMLEditor->IsTextNode(aNode)) {
     aNode->GetParentNode(getter_AddRefs(node));
   }
   nsCOMPtr<nsIContent> content = do_QueryInterface(node);
-  if (!content) return PR_FALSE;
+  NS_ENSURE_TRUE(content, PR_FALSE);
 
   nsIAtom *tagName = content->Tag();
   // brade: should the above use nsEditor::GetTag(aNode)?
   // brade: shouldn't some of the above go below the next block?
 
   // html inline styles B I TT U STRIKE and COLOR/FACE on FONT
   if (nsEditProperty::b == aProperty
       || nsEditProperty::i == aProperty
@@ -1378,20 +1378,20 @@ nsHTMLCSSUtils::ElementsSameStyle(nsIDOM
   return PR_TRUE;
 }
 
 nsresult
 nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement *aElement,
                                 nsIDOMCSSStyleDeclaration **aCssDecl,
                                 PRUint32 *aLength)
 {
-  if (!aElement || !aLength) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement && aLength, NS_ERROR_NULL_POINTER);
   *aLength = 0;
   nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(aElement);
-  if (!inlineStyles) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
   nsresult res = inlineStyles->GetStyle(aCssDecl);
   if (NS_FAILED(res) || !aCssDecl) return NS_ERROR_NULL_POINTER;
   (*aCssDecl)->GetLength(aLength);
   return NS_OK;
 }
 
 nsresult
 nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** aElement)
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -140,46 +140,46 @@ static NS_DEFINE_CID(kCParserCID,     NS
 // some little helpers
 static PRInt32 FindPositiveIntegerAfterString(const char *aLeadingString, nsCString &aCStr);
 static nsresult RemoveFragComments(nsCString &theStr);
 static void RemoveBodyAndHead(nsIDOMNode *aNode);
 static nsresult FindTargetNode(nsIDOMNode *aStart, nsCOMPtr<nsIDOMNode> &aResult);
 
 static nsCOMPtr<nsIDOMNode> GetListParent(nsIDOMNode* aNode)
 {
-  if (!aNode) return nsnull;
+  NS_ENSURE_TRUE(aNode, nsnull);
   nsCOMPtr<nsIDOMNode> parent, tmp;
   aNode->GetParentNode(getter_AddRefs(parent));
   while (parent)
   {
     if (nsHTMLEditUtils::IsList(parent)) return parent;
     parent->GetParentNode(getter_AddRefs(tmp));
     parent = tmp;
   }
   return nsnull;
 }
 
 static nsCOMPtr<nsIDOMNode> GetTableParent(nsIDOMNode* aNode)
 {
-  if (!aNode) return nsnull;
+  NS_ENSURE_TRUE(aNode, nsnull);
   nsCOMPtr<nsIDOMNode> parent, tmp;
   aNode->GetParentNode(getter_AddRefs(parent));
   while (parent)
   {
     if (nsHTMLEditUtils::IsTable(parent)) return parent;
     parent->GetParentNode(getter_AddRefs(tmp));
     parent = tmp;
   }
   return nsnull;
 }
 
 
 NS_IMETHODIMP nsHTMLEditor::LoadHTML(const nsAString & aInputString)
 {
-  if (!mRules) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // force IME commit; set up rules sniffing and batching
   ForceCompositionEnd();
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpLoadHTML, nsIEditor::eNext);
   
   // Get selection
   nsCOMPtr<nsISelection>selection;
@@ -258,17 +258,17 @@ nsHTMLEditor::InsertHTMLWithContext(cons
                                     const nsAString & aContextStr,
                                     const nsAString & aInfoStr,
                                     const nsAString & aFlavor,
                                     nsIDOMDocument *aSourceDoc,
                                     nsIDOMNode *aDestNode,
                                     PRInt32 aDestOffset,
                                     PRBool aDeleteSelection)
 {
-  if (!mRules) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // force IME commit; set up rules sniffing and batching
   ForceCompositionEnd();
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpHTMLPaste, nsIEditor::eNext);
   
   // Get selection
   nsresult res;
@@ -884,17 +884,17 @@ nsHTMLEditor::RelativizeURIForNode(nsIDO
   nsAutoString attributeToModify;
   GetAttributeToModifyOnNode(aNode, attributeToModify);
   if (attributeToModify.IsEmpty())
     return NS_OK;
 
   nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
   nsresult rv = aNode->GetAttributes(getter_AddRefs(attrMap));
   NS_ENSURE_SUCCESS(rv, NS_OK);
-  if (!attrMap) return NS_OK; // assume errors here shouldn't cancel insertion
+  NS_ENSURE_TRUE(attrMap, NS_OK); // assume errors here shouldn't cancel insertion
 
   nsCOMPtr<nsIDOMNode> attrNode;
   rv = attrMap->GetNamedItem(attributeToModify, getter_AddRefs(attrNode));
   NS_ENSURE_SUCCESS(rv, NS_OK); // assume errors here shouldn't cancel insertion
 
   if (attrNode)
   {
     nsAutoString oldValue;
@@ -925,20 +925,20 @@ nsHTMLEditor::RelativizeURIInFragmentLis
                                           const nsAString &aFlavor,
                                           nsIDOMDocument *aSourceDoc,
                                           nsIDOMNode *aTargetNode)
 {
   // determine destination URL
   nsCOMPtr<nsIDOMDocument> domDoc;
   GetDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> destDoc = do_QueryInterface(domDoc);
-  if (!destDoc) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(destDoc, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIURL> destURL = do_QueryInterface(destDoc->GetDocumentURI());
-  if (!destURL) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(destURL, NS_ERROR_FAILURE);
 
   // brade: eventually should look for a base url in the document if present
 
   nsresult rv;
   nsCOMPtr<nsIDOMDocumentTraversal> trav = do_QueryInterface(domDoc, &rv);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
   PRInt32 listCount = aNodeList.Count();
@@ -1484,33 +1484,33 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDr
   
   nsresult rv;
   nsCOMPtr<nsIDragService> dragService = 
            do_GetService("@mozilla.org/widget/dragservice;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDragSession> dragSession;
   dragService->GetCurrentSession(getter_AddRefs(dragSession)); 
-  if (!dragSession) return NS_OK;
+  NS_ENSURE_TRUE(dragSession, NS_OK);
 
   // transferable hooks here
   nsCOMPtr<nsIDOMDocument> domdoc;
   GetDocument(getter_AddRefs(domdoc));
 
   // find out if we have our internal html flavor on the clipboard.  We don't want to mess
   // around with cfhtml if we do.
   PRBool bHavePrivateHTMLFlavor = PR_FALSE;
   rv = dragSession->IsDataFlavorSupported(kHTMLContext, &bHavePrivateHTMLFlavor);
   NS_ENSURE_SUCCESS(rv, rv);
   
   // Get the nsITransferable interface for getting the data from the drop
   nsCOMPtr<nsITransferable> trans;
   rv = PrepareHTMLTransferable(getter_AddRefs(trans), bHavePrivateHTMLFlavor);
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!trans) return NS_OK;  // NS_ERROR_FAILURE; SHOULD WE FAIL?
+  NS_ENSURE_TRUE(trans, NS_OK);  // NS_ERROR_FAILURE; SHOULD WE FAIL?
 
   PRUint32 numItems = 0; 
   rv = dragSession->GetNumDropItems(&numItems);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Combine any deletion and drop insertion into one transaction
   nsAutoEditBatch beginBatching(this);
 
@@ -1525,17 +1525,17 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDr
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRUint32 i; 
   PRBool doPlaceCaret = PR_TRUE;
   for (i = 0; i < numItems; ++i)
   {
     rv = dragSession->GetData(trans, i);
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!trans) return NS_OK; // NS_ERROR_FAILURE; Should we fail?
+    NS_ENSURE_TRUE(trans, NS_OK); // NS_ERROR_FAILURE; Should we fail?
 
     // get additional html copy hints, if present
     nsAutoString contextStr, infoStr;
     nsCOMPtr<nsISupports> contextDataObj, infoDataObj;
     PRUint32 contextLen, infoLen;
     nsCOMPtr<nsISupportsString> textDataObj;
     
     nsCOMPtr<nsITransferable> contextTrans =
@@ -1572,17 +1572,17 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDr
 
     if (doPlaceCaret)
     {
       // check if the user pressed the key to force a copy rather than a move
       // if we run into problems here, we'll just assume the user doesn't want a copy
       PRBool userWantsCopy = PR_FALSE;
 
       nsCOMPtr<nsIDOMNSUIEvent> nsuiEvent(do_QueryInterface(aDropEvent));
-      if (!nsuiEvent) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(nsuiEvent, NS_ERROR_FAILURE);
 
       nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aDropEvent));
       if (mouseEvent)
 
 #if defined(XP_MAC) || defined(XP_MACOSX)
         mouseEvent->GetAltKey(&userWantsCopy);
 #else
         mouseEvent->GetCtrlKey(&userWantsCopy);
@@ -1591,26 +1591,26 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDr
       // Current doc is destination
       nsCOMPtr<nsIDOMDocument>destdomdoc; 
       rv = GetDocument(getter_AddRefs(destdomdoc)); 
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsISelection> selection;
       rv = GetSelection(getter_AddRefs(selection));
       NS_ENSURE_SUCCESS(rv, rv);
-      if (!selection) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
       PRBool isCollapsed;
       rv = selection->GetIsCollapsed(&isCollapsed);
       NS_ENSURE_SUCCESS(rv, rv);
       
       // Parent and offset under the mouse cursor
       rv = nsuiEvent->GetRangeParent(getter_AddRefs(newSelectionParent));
       NS_ENSURE_SUCCESS(rv, rv);
-      if (!newSelectionParent) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(newSelectionParent, NS_ERROR_FAILURE);
 
       rv = nsuiEvent->GetRangeOffset(&newSelectionOffset);
       NS_ENSURE_SUCCESS(rv, rv);
 
       // XXX: This userSelectNode code is a workaround for bug 195957.
       //
       // Check to see if newSelectionParent is part of a "-moz-user-select: all"
       // subtree. If it is, we need to make sure we don't drop into it!
@@ -1627,17 +1627,17 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDr
         //      current behavior when dropping on top of an image.
         //      The decision for dropping before or after the
         //      subtree should really be done based on coordinates.
 
         rv = GetNodeLocation(userSelectNode, address_of(newSelectionParent),
                              &newSelectionOffset);
 
         NS_ENSURE_SUCCESS(rv, rv);
-        if (!newSelectionParent) return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(newSelectionParent, NS_ERROR_FAILURE);
       }
 
       // We never have to delete if selection is already collapsed
       PRBool cursorIsInSelection = PR_FALSE;
 
       // Check if mouse is in the selection
       if (!isCollapsed)
       {
@@ -1821,17 +1821,17 @@ NS_IMETHODIMP nsHTMLEditor::DoDrag(nsIDO
   return nsPlaintextEditor::DoDrag(aDragEvent);
 }
 
 PRBool nsHTMLEditor::HavePrivateHTMLFlavor(nsIClipboard *aClipboard)
 {
   // check the clipboard for our special kHTMLContext flavor.  If that is there, we know
   // we have our own internal html format on clipboard.
   
-  if (!aClipboard) return PR_FALSE;
+  NS_ENSURE_TRUE(aClipboard, PR_FALSE);
   PRBool bHavePrivateHTMLFlavor = PR_FALSE;
   
   const char* flavArray[] = { kHTMLContext };
   
   if (NS_SUCCEEDED(aClipboard->HasDataMatchingFlavors(flavArray,
     NS_ARRAY_LENGTH(flavArray), nsIClipboard::kGlobalClipboard,
     &bHavePrivateHTMLFlavor )))
     return bHavePrivateHTMLFlavor;
@@ -2076,30 +2076,30 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCited
 {
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
 
   // get selection
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // give rules a chance to handle or cancel
   nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
   PRBool cancel, handled;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (cancel) return NS_OK; // rules canceled the operation
   if (!handled)
   {
     nsCOMPtr<nsIDOMNode> newNode;
     res = DeleteSelectionAndCreateNode(NS_LITERAL_STRING("blockquote"), getter_AddRefs(newNode));
     NS_ENSURE_SUCCESS(res, res);
-    if (!newNode) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(newNode, NS_ERROR_NULL_POINTER);
 
     // Try to set type=cite.  Ignore it if this fails.
     nsCOMPtr<nsIDOMElement> newElement (do_QueryInterface(newNode));
     if (newElement)
     {
       newElement->SetAttribute(NS_LITERAL_STRING("type"), NS_LITERAL_STRING("cite"));
     }
 
@@ -2300,17 +2300,20 @@ nsHTMLEditor::InsertAsPlaintextQuotation
   if (NS_SUCCEEDED(rv) && prefBranch)
     prefBranch->GetBoolPref("editor.quotesPreformatted", &quotesInPre);
 
   nsCOMPtr<nsIDOMNode> preNode;
   // get selection
   nsCOMPtr<nsISelection> selection;
   rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  if (!selection)
+  {
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
+  }
   else
   {
     nsAutoEditBatch beginBatching(this);
     nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
 
     // give rules a chance to handle or cancel
     nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
     PRBool cancel, handled;
@@ -2413,33 +2416,36 @@ nsHTMLEditor::InsertAsCitedQuotation(con
 
   nsCOMPtr<nsIDOMNode> newNode;
   nsresult res = NS_OK;
 
   // get selection
   nsCOMPtr<nsISelection> selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  if (!selection)
+  {
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
+  }
   else
   {
     nsAutoEditBatch beginBatching(this);
     nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
 
     // give rules a chance to handle or cancel
     nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
     PRBool cancel, handled;
     res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
     NS_ENSURE_SUCCESS(res, res);
     if (cancel) return NS_OK; // rules canceled the operation
     if (!handled)
     {
       res = DeleteSelectionAndCreateNode(NS_LITERAL_STRING("blockquote"), getter_AddRefs(newNode));
       NS_ENSURE_SUCCESS(res, res);
-      if (!newNode) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(newNode, NS_ERROR_NULL_POINTER);
 
       // Try to set type=cite.  Ignore it if this fails.
       nsCOMPtr<nsIDOMElement> newElement (do_QueryInterface(newNode));
       if (newElement)
       {
         NS_NAMED_LITERAL_STRING(citestr, "cite");
         newElement->SetAttribute(NS_LITERAL_STRING("type"), citestr);
 
@@ -2796,17 +2802,17 @@ nsresult nsHTMLEditor::CreateListOfNodes
     aStartNode = aFragmentAsNode;
     aStartOffset = 0;
     aEndNode = aFragmentAsNode;
     aEndOffset = fragLen;
   }
 
   nsCOMPtr<nsIDOMRange> docFragRange =
                           do_CreateInstance("@mozilla.org/content/range;1");
-  if (!docFragRange) return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(docFragRange, NS_ERROR_OUT_OF_MEMORY);
 
   res = docFragRange->SetStart(aStartNode, aStartOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = docFragRange->SetEnd(aEndNode, aEndOffset);
   NS_ENSURE_SUCCESS(res, res);
 
   // now use a subtree iterator over the range to create a list of nodes
   nsTrivialFunctor functor;
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -275,28 +275,28 @@ nsHTMLEditRules::Init(nsPlaintextEditor 
   }
   else
   {
     mReturnInEmptyLIKillsList = PR_TRUE; 
   }
   
   // make a utility range for use by the listenter
   mUtilRange = do_CreateInstance("@mozilla.org/content/range;1");
-  if (!mUtilRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mUtilRange, NS_ERROR_NULL_POINTER);
    
   // set up mDocChangeRange to be whole doc
   nsIDOMElement *rootElem = mHTMLEditor->GetRoot();
   if (rootElem)
   {
     // temporarily turn off rules sniffing
     nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this);
     if (!mDocChangeRange)
     {
       mDocChangeRange = do_CreateInstance("@mozilla.org/content/range;1");
-      if (!mDocChangeRange) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(mDocChangeRange, NS_ERROR_NULL_POINTER);
     }
     mDocChangeRange->SelectNode(rootElem);
     res = AdjustSpecialBreaks();
     NS_ENSURE_SUCCESS(res, res);
   }
 
   // add ourselves as a listener to edit actions
   res = mHTMLEditor->AddEditActionListener(this);
@@ -895,29 +895,29 @@ nsHTMLEditRules::GetAlignment(PRBool *aM
 
     // use these ranges to construct a list of nodes to act on.
     nsCOMArray<nsIDOMNode> arrayOfNodes;
     res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kAlign, PR_TRUE);
     NS_ENSURE_SUCCESS(res, res);                                 
     nodeToExamine = arrayOfNodes.SafeObjectAt(0);
   }
 
-  if (!nodeToExamine) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
 
   PRBool useCSS;
   mHTMLEditor->GetIsCSSEnabled(&useCSS);
   NS_NAMED_LITERAL_STRING(typeAttrName, "align");
   nsIAtom  *dummyProperty = nsnull;
   nsCOMPtr<nsIDOMNode> blockParent;
   if (mHTMLEditor->IsBlockNode(nodeToExamine))
     blockParent = nodeToExamine;
   else
     blockParent = mHTMLEditor->GetBlockNodeParent(nodeToExamine);
 
-  if (!blockParent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
 
   if (useCSS)
   {
     nsCOMPtr<nsIContent> blockParentContent = do_QueryInterface(blockParent);
     if (blockParentContent && 
         mHTMLEditor->mHTMLCSSUtils->IsCSSEditableProperty(blockParent, dummyProperty, &typeAttrName))
     {
       // we are in CSS mode and we know how to align this element with CSS
@@ -1061,24 +1061,24 @@ nsHTMLEditRules::GetIndentState(PRBool *
   {
     // if we haven't found something to outdent yet, also check the parents
     // of selection endpoints.  We might have a blockquote or list item 
     // in the parent hierarchy.
     
     // gather up info we need for test
     nsCOMPtr<nsIDOMNode> parent, tmp, root;
     nsIDOMElement *rootElem = mHTMLEditor->GetRoot();
-    if (!rootElem) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(rootElem, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsISelection> selection;
     PRInt32 selOffset;
     root = do_QueryInterface(rootElem);
-    if (!root) return NS_ERROR_NO_INTERFACE;
+    NS_ENSURE_TRUE(root, NS_ERROR_NO_INTERFACE);
     res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     
     // test start parent hierarchy
     res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &selOffset);
     NS_ENSURE_SUCCESS(res, res);
     while (parent && (parent!=root))
     {
       if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent))
       {
@@ -1150,24 +1150,24 @@ nsHTMLEditRules::GetParagraphState(PRBoo
   {
     nsCOMPtr<nsIDOMNode> selNode;
     PRInt32 selOffset;
     nsCOMPtr<nsISelection>selection;
     res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
     res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
     NS_ENSURE_SUCCESS(res, res);
-    if (!selNode) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selNode, NS_ERROR_NULL_POINTER);
     arrayOfNodes.AppendObject(selNode);
     listCount = 1;
   }
 
   // remember root node
   nsIDOMElement *rootElem = mHTMLEditor->GetRoot();
-  if (!rootElem) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(rootElem, NS_ERROR_NULL_POINTER);
 
   // loop through the nodes in selection and examine their paragraph format
   for (i=listCount-1; i>=0; i--)
   {
     nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[i];
     nsAutoString format;
     // if it is a known format node we have it easy
     if (nsHTMLEditUtils::IsFormatNode(curNode))
@@ -1217,23 +1217,23 @@ nsHTMLEditRules::GetParagraphState(PRBoo
   outFormat = formatStr;
   return res;
 }
 
 nsresult 
 nsHTMLEditRules::AppendInnerFormatNodes(nsCOMArray<nsIDOMNode>& aArray,
                                         nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNodeList> childList;
   nsCOMPtr<nsIDOMNode> child;
 
   aNode->GetChildNodes(getter_AddRefs(childList));
-  if (!childList)  return NS_OK;
+  NS_ENSURE_TRUE(childList, NS_OK);
   PRUint32 len, j=0;
   childList->GetLength(&len);
 
   // we only need to place any one inline inside this node onto 
   // the list.  They are all the same for purposes of determining
   // paragraph style.  We use foundInline to track this as we are 
   // going through the children in the loop below.
   PRBool foundInline = PR_FALSE;
@@ -1256,17 +1256,17 @@ nsHTMLEditRules::AppendInnerFormatNodes(
     j++;
   }
   return NS_OK;
 }
 
 nsresult 
 nsHTMLEditRules::GetFormatString(nsIDOMNode *aNode, nsAString &outFormat)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   if (nsHTMLEditUtils::IsFormatNode(aNode))
   {
     nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(aNode);
     atom->ToString(outFormat);
   }
   else
     outFormat.Truncate();
@@ -1286,17 +1286,17 @@ nsHTMLEditRules::WillInsert(nsISelection
   
   // Adjust selection to prevent insertion after a moz-BR.
   // this next only works for collapsed selections right now,
   // because selection is a pain to work with when not collapsed.
   // (no good way to extend start or end of selection)
   PRBool bCollapsed;
   res = aSelection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) return NS_OK;
+  NS_ENSURE_TRUE(bCollapsed, NS_OK);
 
   // if we are after a mozBR in the same block, then move selection
   // to be before it
   nsCOMPtr<nsIDOMNode> selNode, priorNode;
   PRInt32 selOffset;
   // get the (collapsed) selection location
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode),
                                            &selOffset);
@@ -1322,17 +1322,17 @@ nsHTMLEditRules::WillInsert(nsISelection
       NS_ENSURE_SUCCESS(res, res);
     }
   }
 
   // we need to get the doc
   nsCOMPtr<nsIDOMDocument>doc;
   res = mHTMLEditor->GetDocument(getter_AddRefs(doc));
   NS_ENSURE_SUCCESS(res, res);
-  if (!doc) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
     
   // for every property that is set, insert a new inline style node
   return CreateStyleForInsertText(aSelection, doc);
 }    
 
 #ifdef XXX_DEAD_CODE
 nsresult
 nsHTMLEditRules::DidInsert(nsISelection *aSelection, nsresult aResult)
@@ -1397,17 +1397,17 @@ nsHTMLEditRules::WillInsertText(PRInt32 
   if (!mHTMLEditor->IsTextNode(selNode) &&
       !mHTMLEditor->CanContainTag(selNode, NS_LITERAL_STRING("#text")))
     return NS_ERROR_FAILURE;
 
   // we need to get the doc
   nsCOMPtr<nsIDOMDocument>doc;
   res = mHTMLEditor->GetDocument(getter_AddRefs(doc));
   NS_ENSURE_SUCCESS(res, res);
-  if (!doc) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
     
   if (aAction == kInsertTextIME) 
   { 
     // Right now the nsWSRunObject code bails on empty strings, but IME needs 
     // the InsertTextImpl() call to still happen since empty strings are meaningful there.
     if (inString->IsEmpty())
     {
       res = mHTMLEditor->InsertTextImpl(*inString, address_of(selNode), &selOffset, doc);
@@ -1537,33 +1537,33 @@ nsHTMLEditRules::WillInsertText(PRInt32 
     nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
     selPriv->SetInterlinePosition(PR_FALSE);
     if (curNode) aSelection->Collapse(curNode, curOffset);
     // manually update the doc changed range so that AfterEdit will clean up
     // the correct portion of the document.
     if (!mDocChangeRange)
     {
       mDocChangeRange = do_CreateInstance("@mozilla.org/content/range;1");
-      if (!mDocChangeRange) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(mDocChangeRange, NS_ERROR_NULL_POINTER);
     }
     res = mDocChangeRange->SetStart(selNode, selOffset);
     NS_ENSURE_SUCCESS(res, res);
     if (curNode)
       res = mDocChangeRange->SetEnd(curNode, curOffset);
     else
       res = mDocChangeRange->SetEnd(selNode, selOffset);
     NS_ENSURE_SUCCESS(res, res);
   }
   return res;
 }
 
 nsresult
 nsHTMLEditRules::WillLoadHTML(nsISelection *aSelection, PRBool *aCancel)
 {
-  if (!aSelection || !aCancel) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection && aCancel, NS_ERROR_NULL_POINTER);
 
   *aCancel = PR_FALSE;
 
   // Delete mBogusNode if it exists. If we really need one,
   // it will be added during post-processing in AfterEditInner().
 
   if (mBogusNode)
   {
@@ -1609,27 +1609,27 @@ nsHTMLEditRules::WillInsertBreak(nsISele
   }
 
   // smart splitting rules
   nsCOMPtr<nsIDOMNode> node;
   PRInt32 offset;
   
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
   NS_ENSURE_SUCCESS(res, res);
-  if (!node) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
     
   // identify the block
   nsCOMPtr<nsIDOMNode> blockParent;
   
   if (IsBlockNode(node)) 
     blockParent = node;
   else 
     blockParent = mHTMLEditor->GetBlockNodeParent(node);
     
-  if (!blockParent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
   
   // do nothing if the node is read-only
   if (!mHTMLEditor->IsModifiableNode(blockParent))
   {
     *aCancel = PR_TRUE;
     return NS_OK;
   }
 
@@ -1937,21 +1937,21 @@ nsHTMLEditRules::WillDeleteSelection(nsI
       res = mHTMLEditor->DeleteTableCellContents();
       *aHandled = PR_TRUE;
       return res;
     }
   }
   
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
-  if (!startNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
     
   // get the root element  
   nsIDOMElement *rootNode = mHTMLEditor->GetRoot();
-  if (!rootNode) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(rootNode, NS_ERROR_UNEXPECTED);
 
   if (bCollapsed)
   {
     // if we are inside an empty block, delete it.
     res = CheckForEmptyBlock(startNode, rootNode, aSelection, aHandled);
     NS_ENSURE_SUCCESS(res, res);
     if (*aHandled) return NS_OK;
         
@@ -1965,17 +1965,17 @@ nsHTMLEditRules::WillDeleteSelection(nsI
 
     // We should delete nothing.
     if (aAction == nsIEditor::eNone)
       return NS_OK;
 
     // ExtendSelectionForDelete() may have changed the selection, update it
     res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
     NS_ENSURE_SUCCESS(res, res);
-    if (!startNode) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
     
     res = aSelection->GetIsCollapsed(&bCollapsed);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   if (bCollapsed)
   {
     // what's in the direction we are deleting?
@@ -2343,22 +2343,22 @@ nsHTMLEditRules::WillDeleteSelection(nsI
   NS_ENSURE_SUCCESS(res, res);
   
   // remember that we did a ranged delete for the benefit of AfterEditInner().
   mDidRangedDelete = PR_TRUE;
   
   // refresh start and end points
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
-  if (!startNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
   nsCOMPtr<nsIDOMNode> endNode;
   PRInt32 endOffset;
   res = mHTMLEditor->GetEndNodeAndOffset(aSelection, getter_AddRefs(endNode), &endOffset);
   NS_ENSURE_SUCCESS(res, res); 
-  if (!endNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
 
   // figure out if the endpoints are in nodes that can be merged  
   // adjust surrounding whitespace in preperation to delete selection
   if (!IsPlaintextEditor())
   {
     nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
     res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor,
                                             address_of(startNode), &startOffset, 
@@ -2460,26 +2460,26 @@ nsHTMLEditRules::WillDeleteSelection(nsI
         }
         
         // else blocks not same type, or not siblings.  Delete everything except
         // table elements.
         nsCOMPtr<nsIEnumerator> enumerator;
         nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(aSelection));
         res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
         NS_ENSURE_SUCCESS(res, res);
-        if (!enumerator) return NS_ERROR_UNEXPECTED;
+        NS_ENSURE_TRUE(enumerator, NS_ERROR_UNEXPECTED);
 
         join = PR_TRUE;
 
         for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next())
         {
           nsCOMPtr<nsISupports> currentItem;
           res = enumerator->CurrentItem(getter_AddRefs(currentItem));
           NS_ENSURE_SUCCESS(res, res);
-          if (!currentItem) return NS_ERROR_UNEXPECTED;
+          NS_ENSURE_TRUE(currentItem, NS_ERROR_UNEXPECTED);
 
           // build a list of nodes in the range
           nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
           nsCOMArray<nsIDOMNode> arrayOfNodes;
           nsTrivialFunctor functor;
           nsDOMSubtreeIterator iter;
           res = iter.Init(range);
           NS_ENSURE_SUCCESS(res, res);
@@ -2578,17 +2578,17 @@ nsHTMLEditRules::InsertBRIfNeeded(nsISel
   if (!aSelection)
     return 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);
-  if (!node) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
   // examine selection
   nsWSRunObject wsObj(mHTMLEditor, node, offset);
   if (((wsObj.mStartReason & nsWSRunObject::eBlock) || (wsObj.mStartReason & nsWSRunObject::eBreak))
       && (wsObj.mEndReason & nsWSRunObject::eBlock))
   {
     // if we are tucked between block boundaries then insert a br
     // first check that we are allowed to
@@ -2656,17 +2656,17 @@ nsHTMLEditRules::GetGoodSelPointForNode(
 *         nsCOMPtr<nsIDOMNode> *aRightBlock        pointer to the right block; will have contents moved to left block
 *         PRBool *aCanceled                        return TRUE if we had to cancel operation
 */
 nsresult
 nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsIDOMNode> *aLeftBlock, 
                             nsCOMPtr<nsIDOMNode> *aRightBlock, 
                             PRBool *aCanceled)
 {
-  if (!aLeftBlock || !aRightBlock || !*aLeftBlock || !*aRightBlock) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aLeftBlock && aRightBlock && *aLeftBlock  && *aRightBlock, NS_ERROR_NULL_POINTER);
   if (nsHTMLEditUtils::IsTableElement(*aLeftBlock) || nsHTMLEditUtils::IsTableElement(*aRightBlock))
   {
     // do not try to merge table elements
     *aCanceled = PR_TRUE;
     return NS_OK;
   }
 
   // make sure we don't try to move thing's into HR's, which look like blocks but aren't containers
@@ -2881,17 +2881,17 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *a
 *    inserted content.
 *         nsIDOMNode *aSource       the selection.  
 *         nsIDOMNode *aDest         parent to receive moved content
 *         PRInt32 *aOffset          offset in aDest to move content to
 */
 nsresult
 nsHTMLEditRules::MoveNodeSmart(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 *aOffset)
 {
-  if (!aSource || !aDest || !aOffset) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSource && aDest && aOffset, NS_ERROR_NULL_POINTER);
 
   nsAutoString tag;
   nsresult res;
   res = mHTMLEditor->GetTagString(aSource, tag);
   NS_ENSURE_SUCCESS(res, res);
   ToLowerCase(tag);
   // check if this node can go into the destination node
   if (mHTMLEditor->CanContainTag(aDest, tag))
@@ -2918,17 +2918,17 @@ nsHTMLEditRules::MoveNodeSmart(nsIDOMNod
 *    inserted content.  aSource is deleted.
 *         nsIDOMNode *aSource       the selection.  
 *         nsIDOMNode *aDest         parent to receive moved content
 *         PRInt32 *aOffset          offset in aDest to move content to
 */
 nsresult
 nsHTMLEditRules::MoveContents(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 *aOffset)
 {
-  if (!aSource || !aDest || !aOffset) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSource && aDest && aOffset, NS_ERROR_NULL_POINTER);
   if (aSource == aDest) return NS_ERROR_ILLEGAL_VALUE;
   NS_ASSERTION(!mHTMLEditor->IsTextNode(aSource), "#text does not have contents");
   
   nsCOMPtr<nsIDOMNode> child;
   nsAutoString tag;
   nsresult res;
   aSource->GetFirstChild(getter_AddRefs(child));
   while (child)
@@ -2939,27 +2939,27 @@ nsHTMLEditRules::MoveContents(nsIDOMNode
   }
   return NS_OK;
 }
 
 
 nsresult
 nsHTMLEditRules::DeleteNonTableElements(nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   if (nsHTMLEditUtils::IsTableElementButNotTable(aNode))
   {
     nsCOMPtr<nsIDOMNodeList> children;
     aNode->GetChildNodes(getter_AddRefs(children));
     if (children)
     {
       PRUint32 len;
       children->GetLength(&len);
-      if (!len) return NS_OK;
+      NS_ENSURE_TRUE(len, NS_OK);
       PRInt32 j;
       for (j=len-1; j>=0; j--)
       {
         nsCOMPtr<nsIDOMNode> node;
         children->Item(j,getter_AddRefs(node));
         res = DeleteNonTableElements(node);
         NS_ENSURE_SUCCESS(res, res);
 
@@ -2981,17 +2981,17 @@ nsHTMLEditRules::DidDeleteSelection(nsIS
 {
   if (!aSelection) { return NS_ERROR_NULL_POINTER; }
   
   // find where we are
   nsCOMPtr<nsIDOMNode> startNode;
   PRInt32 startOffset;
   nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
-  if (!startNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
   
   // find any enclosing mailcite
   nsCOMPtr<nsIDOMNode> citeNode;
   res = GetTopEnclosingMailCite(startNode, address_of(citeNode), 
                                 IsPlaintextEditor());
   NS_ENSURE_SUCCESS(res, res);
   if (citeNode)
   {
@@ -3464,17 +3464,17 @@ nsHTMLEditRules::WillMakeBasicBlock(nsIS
     NS_ENSURE_SUCCESS(res, res);
     if (tString.EqualsLiteral("normal") ||
         tString.IsEmpty() ) // we are removing blocks (going to "body text")
     {
       nsCOMPtr<nsIDOMNode> curBlock = parent;
       if (!IsBlockNode(curBlock))
         curBlock = mHTMLEditor->GetBlockNodeParent(parent);
       nsCOMPtr<nsIDOMNode> curBlockPar;
-      if (!curBlock) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(curBlock, NS_ERROR_NULL_POINTER);
       curBlock->GetParentNode(getter_AddRefs(curBlockPar));
       if (nsHTMLEditUtils::IsFormatNode(curBlock))
       {
         // if the first editable node after selection is a br, consume it.  Otherwise
         // it gets pushed into a following block after the split, which is visually bad.
         nsCOMPtr<nsIDOMNode> brNode;
         res = mHTMLEditor->GetNextHTMLNode(parent, offset, address_of(brNode));
         NS_ENSURE_SUCCESS(res, res);        
@@ -3548,22 +3548,22 @@ nsHTMLEditRules::WillMakeBasicBlock(nsIS
   }
   return res;
 }
 
 nsresult 
 nsHTMLEditRules::DidMakeBasicBlock(nsISelection *aSelection,
                                    nsRulesInfo *aInfo, nsresult aResult)
 {
-  if (!aSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // check for empty block.  if so, put a moz br in it.
   PRBool isCollapsed;
   nsresult res = aSelection->GetIsCollapsed(&isCollapsed);
   NS_ENSURE_SUCCESS(res, res);
-  if (!isCollapsed) return NS_OK;
+  NS_ENSURE_TRUE(isCollapsed, NS_OK);
 
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   res = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
   res = InsertMozBRIfNeeded(parent);
   return res;
 }
@@ -4370,17 +4370,17 @@ nsHTMLEditRules::OutdentPartOfBlock(nsID
 //                
 //                  
 nsresult 
 nsHTMLEditRules::ConvertListType(nsIDOMNode *aList, 
                                  nsCOMPtr<nsIDOMNode> *outList,
                                  const nsAString& aListType, 
                                  const nsAString& aItemType) 
 {
-  if (!aList || !outList) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aList && outList, NS_ERROR_NULL_POINTER);
   *outList = aList;  // we might not need to change the list
   nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> child, temp;
   aList->GetFirstChild(getter_AddRefs(child));
   while (child)
   {
     if (nsHTMLEditUtils::IsListItem(child) && !nsEditor::NodeIsTypeString(child, aItemType))
     {
@@ -4408,18 +4408,18 @@ nsHTMLEditRules::ConvertListType(nsIDOMN
 ///////////////////////////////////////////////////////////////////////////
 // CreateStyleForInsertText:  take care of clearing and setting appropriate
 //                            style nodes for text insertion.
 //                
 //                  
 nsresult 
 nsHTMLEditRules::CreateStyleForInsertText(nsISelection *aSelection, nsIDOMDocument *aDoc) 
 {
-  if (!aSelection || !aDoc) return NS_ERROR_NULL_POINTER;
-  if (!mHTMLEditor->mTypeInState) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection && aDoc, NS_ERROR_NULL_POINTER);
+  NS_ENSURE_TRUE(mHTMLEditor->mTypeInState, NS_ERROR_NULL_POINTER);
   
   PRBool weDidSometing = PR_FALSE;
   nsCOMPtr<nsIDOMNode> node, tmp;
   PRInt32 offset;
   nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
   NS_ENSURE_SUCCESS(res, res);
   nsAutoPtr<PropItem> item;
   
@@ -4499,17 +4499,17 @@ nsHTMLEditRules::CreateStyleForInsertTex
 
         secondSplitParent->GetParentNode(getter_AddRefs(tmp));
         secondSplitParent = tmp;
       }
       offset = 0;
       res = mHTMLEditor->SplitStyleAbovePoint(address_of(secondSplitParent), &offset, item->tag, &(item->attr), address_of(leftNode), address_of(rightNode));
       NS_ENSURE_SUCCESS(res, res);
       // should be impossible to not get a new leftnode here
-      if (!leftNode) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(leftNode, NS_ERROR_FAILURE);
       newSelParent = mHTMLEditor->GetLeftmostChild(leftNode);
       if (!newSelParent) newSelParent = leftNode;
       // if rightNode starts with a br, suck it out of right node and into leftNode.
       // This is so we you don't revert back to the previous style if you happen to click at the end of a line.
       if (savedBR)
       {
         res = mEditor->MoveNode(savedBR, newSelParent, 0);
         NS_ENSURE_SUCCESS(res, res);
@@ -4557,17 +4557,17 @@ nsHTMLEditRules::CreateStyleForInsertTex
       NS_ENSURE_SUCCESS(res, res);
       node->GetParentNode(getter_AddRefs(tmp));
       node = tmp;
     }
     nsCOMPtr<nsIDOMNode> newNode;
     nsCOMPtr<nsIDOMText> nodeAsText;
     res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText));
     NS_ENSURE_SUCCESS(res, res);
-    if (!nodeAsText) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
     newNode = do_QueryInterface(nodeAsText);
     res = mHTMLEditor->InsertNode(newNode, node, offset);
     NS_ENSURE_SUCCESS(res, res);
     node = newNode;
     offset = 0;
     weDidSometing = PR_TRUE;
 
     if (relFontSize)
@@ -4603,26 +4603,26 @@ nsHTMLEditRules::CreateStyleForInsertTex
 //               if the children are empty or non-editable.
 //                  
 nsresult 
 nsHTMLEditRules::IsEmptyBlock(nsIDOMNode *aNode, 
                               PRBool *outIsEmptyBlock, 
                               PRBool aMozBRDoesntCount,
                               PRBool aListItemsNotEmpty) 
 {
-  if (!aNode || !outIsEmptyBlock) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outIsEmptyBlock, NS_ERROR_NULL_POINTER);
   *outIsEmptyBlock = PR_TRUE;
   
 //  nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> nodeToTest;
   if (IsBlockNode(aNode)) nodeToTest = do_QueryInterface(aNode);
 //  else nsCOMPtr<nsIDOMElement> block;
 //  looks like I forgot to finish this.  Wonder what I was going to do?
 
-  if (!nodeToTest) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nodeToTest, NS_ERROR_NULL_POINTER);
   return mHTMLEditor->IsEmptyNode(nodeToTest, outIsEmptyBlock,
                      aMozBRDoesntCount, aListItemsNotEmpty);
 }
 
 
 nsresult
 nsHTMLEditRules::WillAlign(nsISelection *aSelection, 
                            const nsAString *alignType, 
@@ -4842,17 +4842,17 @@ nsHTMLEditRules::WillAlign(nsISelection 
 
 
 ///////////////////////////////////////////////////////////////////////////
 // AlignInnerBlocks: align inside table cells or list items
 //       
 nsresult
 nsHTMLEditRules::AlignInnerBlocks(nsIDOMNode *aNode, const nsAString *alignType)
 {
-  if (!aNode || !alignType) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && alignType, NS_ERROR_NULL_POINTER);
   nsresult res;
   
   // gather list of table cells or list items
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   nsTableCellAndListItemFunctor functor;
   nsDOMIterator iter;
   res = iter.Init(aNode);
   NS_ENSURE_SUCCESS(res, res);
@@ -4876,17 +4876,17 @@ nsHTMLEditRules::AlignInnerBlocks(nsIDOM
 
 
 ///////////////////////////////////////////////////////////////////////////
 // AlignBlockContents: align contents of a block element
 //                  
 nsresult
 nsHTMLEditRules::AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignType)
 {
-  if (!aNode || !alignType) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && alignType, NS_ERROR_NULL_POINTER);
   nsresult res;
   nsCOMPtr <nsIDOMNode> firstChild, lastChild, divNode;
   
   PRBool useCSS;
   mHTMLEditor->GetIsCSSEnabled(&useCSS);
 
   res = mHTMLEditor->GetFirstEditableChild(aNode, address_of(firstChild));
   NS_ENSURE_SUCCESS(res, res);
@@ -4969,31 +4969,31 @@ nsHTMLEditRules::CheckForEmptyBlock(nsID
   }
   
   if (emptyBlock)
   {
     nsCOMPtr<nsIDOMNode> blockParent;
     PRInt32 offset;
     res = nsEditor::GetNodeLocation(emptyBlock, address_of(blockParent), &offset);
     NS_ENSURE_SUCCESS(res, res);
-    if (!blockParent || offset < 0) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(blockParent && offset >= 0, NS_ERROR_FAILURE);
 
     if (nsHTMLEditUtils::IsListItem(emptyBlock))
     {
       // are we the first list item in the list?
       PRBool bIsFirst;
       res = mHTMLEditor->IsFirstEditableChild(emptyBlock, &bIsFirst);
       NS_ENSURE_SUCCESS(res, res);
       if (bIsFirst)
       {
         nsCOMPtr<nsIDOMNode> listParent;
         PRInt32 listOffset;
         res = nsEditor::GetNodeLocation(blockParent, address_of(listParent), &listOffset);
         NS_ENSURE_SUCCESS(res, res);
-        if (!listParent || listOffset < 0) return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(listParent && listOffset >= 0, NS_ERROR_FAILURE);
         // if we are a sublist, skip the br creation
         if (!nsHTMLEditUtils::IsList(listParent))
         {
           // create a br before list
           nsCOMPtr<nsIDOMNode> brNode;
           res = mHTMLEditor->CreateBR(listParent, listOffset, address_of(brNode));
           NS_ENSURE_SUCCESS(res, res);
           // adjust selection to be right before it
@@ -5016,17 +5016,17 @@ nsHTMLEditRules::CheckForEmptyBlock(nsID
 }
 
 nsresult
 nsHTMLEditRules::CheckForInvisibleBR(nsIDOMNode *aBlock, 
                                      BRLocation aWhere, 
                                      nsCOMPtr<nsIDOMNode> *outBRNode,
                                      PRInt32 aOffset)
 {
-  if (!aBlock || !outBRNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBlock && outBRNode, NS_ERROR_NULL_POINTER);
   *outBRNode = nsnull;
 
   nsCOMPtr<nsIDOMNode> testNode;
   PRInt32 testOffset = 0;
   PRBool runTest = PR_FALSE;
 
   if (aWhere == kBlockEnd)
   {
@@ -5077,17 +5077,17 @@ nsHTMLEditRules::CheckForInvisibleBR(nsI
 //                  supplied issupportsarray at offset aIndex.  
 //                  Similarly with aList and list content.
 //                  aIndex is updated to point past inserted elements.
 //                  
 nsresult
 nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsCOMArray<nsIDOMNode> &outArrayOfNodes, 
                                  PRInt32 *aIndex, PRBool aList, PRBool aTbl)
 {
-  if (!aNode || !aIndex) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aIndex, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> node;
   
   nsresult res = mHTMLEditor->GetFirstEditableChild(aNode, address_of(node));
   while (NS_SUCCEEDED(res) && node)
   {
     if (  ( aList && (nsHTMLEditUtils::IsList(node)     || 
                       nsHTMLEditUtils::IsListItem(node) ) )
@@ -5131,17 +5131,17 @@ nsHTMLEditRules::ExpandSelectionForDelet
   
   // we don't need to mess with cell selections, and we assume multirange selections are those.
   if (rangeCount != 1) return NS_OK;
   
   // find current sel start and end
   nsCOMPtr<nsIDOMRange> range;
   res = aSelection->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<nsIDOMNode> selStartNode, selEndNode, selCommon;
   PRInt32 selStartOffset, selEndOffset;
   
   res = range->GetStartContainer(getter_AddRefs(selStartNode));
   NS_ENSURE_SUCCESS(res, res);
   res = range->GetStartOffset(&selStartOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = range->GetEndContainer(getter_AddRefs(selEndNode));
@@ -5254,17 +5254,17 @@ nsHTMLEditRules::ExpandSelectionForDelet
     // find block node containing br
     nsCOMPtr<nsIDOMNode> brBlock = firstBRParent;
     if (!IsBlockNode(brBlock))
       brBlock = nsHTMLEditor::GetBlockNodeParent(brBlock);
     PRBool nodeBefore=PR_FALSE, nodeAfter=PR_FALSE;
     
     // create a range that represents expanded selection
     nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
-    if (!range) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
     res = range->SetStart(selStartNode, selStartOffset);
     NS_ENSURE_SUCCESS(res, res);
     res = range->SetEnd(selEndNode, selEndOffset);
     NS_ENSURE_SUCCESS(res, res);
     
     // check if block is entirely inside range
     nsCOMPtr<nsIContent> brContentBlock = do_QueryInterface(brBlock);
     res = mHTMLEditor->sRangeHelper->CompareNodeToRange(brContentBlock, range, &nodeBefore, &nodeAfter);
@@ -5294,17 +5294,17 @@ PRBool
 nsHTMLEditRules::AtStartOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aBlock)
 {
   nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
   if (nodeAsText && aOffset) return PR_FALSE;  // there are chars in front of us
   
   nsCOMPtr<nsIDOMNode> priorNode;
   nsresult  res = mHTMLEditor->GetPriorHTMLNode(aNode, aOffset, address_of(priorNode));
   NS_ENSURE_SUCCESS(res, PR_TRUE);
-  if (!priorNode) return PR_TRUE;
+  NS_ENSURE_TRUE(priorNode, PR_TRUE);
   nsCOMPtr<nsIDOMNode> blockParent = mHTMLEditor->GetBlockNodeParent(priorNode);
   if (blockParent && (blockParent == aBlock)) return PR_FALSE;
   return PR_TRUE;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // AtEndOfBlock: is node/offset at the end of the editable material in this block?
@@ -5317,30 +5317,30 @@ nsHTMLEditRules::AtEndOfBlock(nsIDOMNode
   {
     PRUint32 strLength;
     nodeAsText->GetLength(&strLength);
     if ((PRInt32)strLength > aOffset) return PR_FALSE;  // there are chars in after us
   }
   nsCOMPtr<nsIDOMNode> nextNode;
   nsresult  res = mHTMLEditor->GetNextHTMLNode(aNode, aOffset, address_of(nextNode));
   NS_ENSURE_SUCCESS(res, PR_TRUE);
-  if (!nextNode) return PR_TRUE;
+  NS_ENSURE_TRUE(nextNode, PR_TRUE);
   nsCOMPtr<nsIDOMNode> blockParent = mHTMLEditor->GetBlockNodeParent(nextNode);
   if (blockParent && (blockParent == aBlock)) return PR_FALSE;
   return PR_TRUE;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // CreateMozDiv: makes a div with type = _moz
 //                       
 nsresult
 nsHTMLEditRules::CreateMozDiv(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outDiv)
 {
-  if (!inParent || !outDiv) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inParent && outDiv, NS_ERROR_NULL_POINTER);
   nsAutoString divType= "div";
   *outDiv = nsnull;
   nsresult res = mHTMLEditor->CreateNode(divType, inParent, inOffset, getter_AddRefs(*outDiv));
   NS_ENSURE_SUCCESS(res, res);
   // give it special moz attr
   nsCOMPtr<nsIDOMElement> mozDivElem = do_QueryInterface(*outDiv);
   res = mHTMLEditor->SetAttribute(mozDivElem, "type", "_moz");
   NS_ENSURE_SUCCESS(res, res);
@@ -5355,17 +5355,17 @@ nsHTMLEditRules::CreateMozDiv(nsIDOMNode
 //    Idea here is to adjust selection endpoint so that they do not cross
 //    breaks or block boundaries unless something editable beyond that boundary
 //    is also selected.  This adjustment makes it much easier for the various
 //    block operations to determine what nodes to act on.
 //                       
 nsresult 
 nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
 {
-  if (!inSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
 
   // don't need to touch collapsed selections
   PRBool bCollapsed;
   nsresult res = inSelection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
   if (bCollapsed) return res;
 
   PRInt32 rangeCount;
@@ -5373,17 +5373,17 @@ nsHTMLEditRules::NormalizeSelection(nsIS
   NS_ENSURE_SUCCESS(res, res);
   
   // we don't need to mess with cell selections, and we assume multirange selections are those.
   if (rangeCount != 1) return NS_OK;
   
   nsCOMPtr<nsIDOMRange> range;
   res = inSelection->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<nsIDOMNode> startNode, endNode;
   PRInt32 startOffset, endOffset;
   nsCOMPtr<nsIDOMNode> newStartNode, newEndNode;
   PRInt32 newStartOffset, newEndOffset;
   
   res = range->GetStartContainer(getter_AddRefs(startNode));
   NS_ENSURE_SUCCESS(res, res);
   res = range->GetStartOffset(&startOffset);
@@ -5672,17 +5672,17 @@ nsHTMLEditRules::GetPromotedPoint(RulesE
 // GetPromotedRanges: run all the selection range endpoint through 
 //                    GetPromotedPoint()
 //                       
 nsresult 
 nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection, 
                                    nsCOMArray<nsIDOMRange> &outArrayOfRanges, 
                                    PRInt32 inOperationType)
 {
-  if (!inSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
 
   PRInt32 rangeCount;
   nsresult res = inSelection->GetRangeCount(&rangeCount);
   NS_ENSURE_SUCCESS(res, res);
   
   PRInt32 i;
   nsCOMPtr<nsIDOMRange> selectionRange;
   nsCOMPtr<nsIDOMRange> opRange;
@@ -5713,17 +5713,17 @@ nsHTMLEditRules::GetPromotedRanges(nsISe
 ///////////////////////////////////////////////////////////////////////////
 // PromoteRange: expand a range to include any parents for which all
 //               editable children are already in range. 
 //                       
 nsresult 
 nsHTMLEditRules::PromoteRange(nsIDOMRange *inRange, 
                               PRInt32 inOperationType)
 {
-  if (!inRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
   nsresult res;
   nsCOMPtr<nsIDOMNode> startNode, endNode;
   PRInt32 startOffset, endOffset;
   
   res = inRange->GetStartContainer(getter_AddRefs(startNode));
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->GetStartOffset(&startOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -5743,17 +5743,17 @@ nsHTMLEditRules::PromoteRange(nsIDOMRang
       block = startNode;
     else
       block = mHTMLEditor->GetBlockNodeParent(startNode);
     if (block)
     {
       PRBool bIsEmptyNode = PR_FALSE;
       // check for body
       nsIDOMElement *rootElement = mHTMLEditor->GetRoot();
-      if (!rootElement) return NS_ERROR_UNEXPECTED;
+      NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED);
       nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(rootElement);
       if (block != rootNode)
       {
         // ok, not body, check if empty
         res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, PR_TRUE, PR_FALSE);
       }
       if (bIsEmptyNode)
       {
@@ -5975,32 +5975,32 @@ nsHTMLEditRules::GetNodesForOperation(ns
 
 ///////////////////////////////////////////////////////////////////////////
 // GetChildNodesForOperation: 
 //                       
 nsresult 
 nsHTMLEditRules::GetChildNodesForOperation(nsIDOMNode *inNode, 
                                            nsCOMArray<nsIDOMNode>& outArrayOfNodes)
 {
-  if (!inNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inNode, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsIDOMNodeList> childNodes;
   nsresult res = inNode->GetChildNodes(getter_AddRefs(childNodes));
   NS_ENSURE_SUCCESS(res, res);
-  if (!childNodes) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(childNodes, NS_ERROR_NULL_POINTER);
   PRUint32 childCount;
   res = childNodes->GetLength(&childCount);
   NS_ENSURE_SUCCESS(res, res);
   
   PRUint32 i;
   nsCOMPtr<nsIDOMNode> node;
   for (i = 0; i < childCount; i++)
   {
     res = childNodes->Item( i, getter_AddRefs(node));
-    if (!node) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
     if (!outArrayOfNodes.AppendObject(node))
       return NS_ERROR_FAILURE;
   }
   return res;
 }
 
 
 
@@ -6022,24 +6022,24 @@ nsHTMLEditRules::GetListActionNodes(nsCO
     return 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);
-    if (!enumerator) return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(enumerator, NS_ERROR_UNEXPECTED);
 
     for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next())
     {
       nsCOMPtr<nsISupports> currentItem;
       res = enumerator->CurrentItem(getter_AddRefs(currentItem));
       NS_ENSURE_SUCCESS(res, res);
-      if (!currentItem) return NS_ERROR_UNEXPECTED;
+      NS_ENSURE_TRUE(currentItem, NS_ERROR_UNEXPECTED);
 
       nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
       nsCOMPtr<nsIDOMNode> commonParent, parent, tmp;
       range->GetCommonAncestorContainer(getter_AddRefs(commonParent));
       if (commonParent)
       {
         parent = commonParent;
         while (parent)
@@ -6150,17 +6150,17 @@ nsHTMLEditRules::LookInsideDivBQandList(
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetDefinitionListItemTypes: 
 //                       
 nsresult 
 nsHTMLEditRules::GetDefinitionListItemTypes(nsIDOMNode *aNode, PRBool &aDT, PRBool &aDD)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   aDT = aDD = PR_FALSE;
   nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> child, temp;
   res = aNode->GetFirstChild(getter_AddRefs(child));
   while (child && NS_SUCCEEDED(res))
   {
     if (nsEditor::NodeIsType(child, nsEditProperty::dt)) aDT = PR_TRUE;
     else if (nsEditor::NodeIsType(child, nsEditProperty::dd)) aDD = PR_TRUE;
@@ -6259,17 +6259,17 @@ nsHTMLEditRules::BustUpInlinesAtRangeEnd
 
 ///////////////////////////////////////////////////////////////////////////
 // BustUpInlinesAtBRs: 
 //                       
 nsresult 
 nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, 
                                     nsCOMArray<nsIDOMNode>& outArrayOfNodes)
 {
-  if (!inNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inNode, NS_ERROR_NULL_POINTER);
 
   // first step is to build up a list of all the break nodes inside 
   // the inline container.
   nsCOMArray<nsIDOMNode> arrayOfBreaks;
   nsBRNodeFunctor functor;
   nsDOMIterator iter;
   nsresult res = iter.Init(inNode);
   NS_ENSURE_SUCCESS(res, res);
@@ -6293,18 +6293,18 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsID
     nsCOMPtr<nsIDOMNode> splitDeepNode = inNode;
     nsCOMPtr<nsIDOMNode> splitParentNode;
     PRInt32 splitOffset, resultOffset, i;
     inNode->GetParentNode(getter_AddRefs(inlineParentNode));
     
     for (i=0; i< listCount; i++)
     {
       breakNode = arrayOfBreaks[i];
-      if (!breakNode) return NS_ERROR_NULL_POINTER;
-      if (!splitDeepNode) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(breakNode, NS_ERROR_NULL_POINTER);
+      NS_ENSURE_TRUE(splitDeepNode, NS_ERROR_NULL_POINTER);
       res = nsEditor::GetNodeLocation(breakNode, address_of(splitParentNode), &splitOffset);
       NS_ENSURE_SUCCESS(res, res);
       res = mHTMLEditor->SplitNodeDeep(splitDeepNode, splitParentNode, splitOffset,
                           &resultOffset, PR_FALSE, address_of(leftNode), address_of(rightNode));
       NS_ENSURE_SUCCESS(res, res);
       // put left node in node list
       if (leftNode)
       {
@@ -6331,17 +6331,17 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsID
   }
   return res;
 }
 
 
 nsCOMPtr<nsIDOMNode> 
 nsHTMLEditRules::GetHighestInlineParent(nsIDOMNode* aNode)
 {
-  if (!aNode) return nsnull;
+  NS_ENSURE_TRUE(aNode, nsnull);
   if (IsBlockNode(aNode)) return nsnull;
   nsCOMPtr<nsIDOMNode> inlineNode, node=aNode;
 
   while (node && IsInlineNode(node))
   {
     inlineNode = node;
     inlineNode->GetParentNode(getter_AddRefs(node));
   }
@@ -6395,17 +6395,17 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPo
 //                     of nodes from the selection that will be operated on. 
 //                       
 nsresult 
 nsHTMLEditRules::GetNodesFromSelection(nsISelection *selection,
                                        PRInt32 operation,
                                        nsCOMArray<nsIDOMNode>& arrayOfNodes,
                                        PRBool dontTouchContent)
 {
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsresult res;
   
   // promote selection ranges
   nsCOMArray<nsIDOMRange> arrayOfRanges;
   res = GetPromotedRanges(selection, arrayOfRanges, operation);
   NS_ENSURE_SUCCESS(res, res);
   
   // use these ranges to contruct a list of nodes to act on.
@@ -6457,17 +6457,17 @@ nsHTMLEditRules::MakeTransitionList(nsCO
 ///////////////////////////////////////////////////////////////////////////
 // IsInListItem: if aNode is the descendant of a listitem, return that li.
 //               But table element boundaries are stoppers on the search.
 //               Also test if aNode is an li itself.
 //                       
 nsCOMPtr<nsIDOMNode> 
 nsHTMLEditRules::IsInListItem(nsIDOMNode *aNode)
 {
-  if (!aNode) return nsnull;  
+  NS_ENSURE_TRUE(aNode, nsnull);  
   if (nsHTMLEditUtils::IsListItem(aNode)) return aNode;
   
   nsCOMPtr<nsIDOMNode> parent, tmp;
   aNode->GetParentNode(getter_AddRefs(parent));
   
   while (parent)
   {
     if (nsHTMLEditUtils::IsTableElement(parent)) return nsnull;
@@ -6482,17 +6482,17 @@ nsHTMLEditRules::IsInListItem(nsIDOMNode
 // ReturnInHeader: do the right thing for returns pressed in headers
 //                       
 nsresult 
 nsHTMLEditRules::ReturnInHeader(nsISelection *aSelection, 
                                 nsIDOMNode *aHeader, 
                                 nsIDOMNode *aNode, 
                                 PRInt32 aOffset)
 {
-  if (!aSelection || !aHeader || !aNode) return NS_ERROR_NULL_POINTER;  
+  NS_ENSURE_TRUE(aSelection && aHeader && aNode, NS_ERROR_NULL_POINTER);  
   
   // remeber where the header is
   nsCOMPtr<nsIDOMNode> headerParent;
   PRInt32 offset;
   nsresult res = nsEditor::GetNodeLocation(aHeader, address_of(headerParent), &offset);
   NS_ENSURE_SUCCESS(res, res);
 
   // get ws code to adjust any ws
@@ -6722,17 +6722,17 @@ nsHTMLEditRules::SplitParagraph(nsIDOMNo
 // ReturnInListItem: do the right thing for returns pressed in list items
 //                       
 nsresult 
 nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, 
                                   nsIDOMNode *aListItem, 
                                   nsIDOMNode *aNode, 
                                   PRInt32 aOffset)
 {
-  if (!aSelection || !aListItem || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection && aListItem && aNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelection> selection(aSelection);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
   nsresult res = NS_OK;
   
   nsCOMPtr<nsIDOMNode> listitem;
   
   // sanity check
   NS_PRECONDITION(PR_TRUE == nsHTMLEditUtils::IsListItem(aListItem),
@@ -7079,17 +7079,17 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMA
 //                       
 nsresult 
 nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsAString *aBlockTag)
 {
   // intent of this routine is to be used for converting to/from
   // headers, paragraphs, pre, and address.  Those blocks
   // that pretty much just contain inline things...
   
-  if (!aBlockTag) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aBlockTag, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   
   nsCOMPtr<nsIDOMNode> curNode, curParent, curBlock, newBlock;
   PRInt32 offset;
   PRInt32 listCount = arrayOfNodes.Count();
   nsString tString(*aBlockTag);////MJUDGE SCC NEED HELP
 
   // Remove all non-editable nodes.  Leave them be.
@@ -7236,18 +7236,18 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMAr
 // SplitAsNeeded:  given a tag name, split inOutParent up to the point   
 //                 where we can insert the tag.  Adjust inOutParent and
 //                 inOutOffset to pint to new location for tag.
 nsresult 
 nsHTMLEditRules::SplitAsNeeded(const nsAString *aTag, 
                                nsCOMPtr<nsIDOMNode> *inOutParent,
                                PRInt32 *inOutOffset)
 {
-  if (!aTag || !inOutParent || !inOutOffset) return NS_ERROR_NULL_POINTER;
-  if (!*inOutParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTag && inOutParent && inOutOffset, NS_ERROR_NULL_POINTER);
+  NS_ENSURE_TRUE(*inOutParent, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> tagParent, temp, splitNode, parent = *inOutParent;
   nsresult res = NS_OK;
    
   // check that we have a place that can legally contain the tag
   while (!tagParent)
   {
     // sniffing up the parent tree until we find 
     // a legal place for the block
@@ -7374,17 +7374,17 @@ nsHTMLEditRules::GetTopEnclosingMailCite
 
   return res;
 }
 
 
 nsresult 
 nsHTMLEditRules::CacheInlineStyles(nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   PRBool useCSS;
   mHTMLEditor->GetIsCSSEnabled(&useCSS);
 
   PRInt32 j;
   for (j=0; j<SIZE_STYLE_TABLE; j++)
   {
     PRBool isSet = PR_FALSE;
@@ -7528,37 +7528,37 @@ nsHTMLEditRules::AdjustWhitespace(nsISel
   
   // ask whitespace object to tweak nbsp's
   return nsWSRunObject(mHTMLEditor, selNode, selOffset).AdjustWhitespace();
 }
 
 nsresult 
 nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection)
 {
-  if (!aSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   PRBool bCollapsed;
   nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) return res;
+  NS_ENSURE_TRUE(bCollapsed, res);
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, temp;
   PRInt32 selOffset;
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   temp = selNode;
   
   // use ranges and sRangeHelper to compare sel point to new block
   nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1");
   res = range->SetStart(selNode, selOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = range->SetEnd(selNode, selOffset);
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsIContent> block (do_QueryInterface(mNewBlock));
-  if (!block) return NS_ERROR_NO_INTERFACE;
+  NS_ENSURE_TRUE(block, NS_ERROR_NO_INTERFACE);
   PRBool nodeBefore, nodeAfter;
   res = mHTMLEditor->sRangeHelper->CompareNodeToRange(block, range, &nodeBefore, &nodeAfter);
   NS_ENSURE_SUCCESS(res, res);
   
   if (nodeBefore && nodeAfter)
     return NS_OK;  // selection is inside block
   else if (nodeBefore)
   {
@@ -7596,25 +7596,25 @@ nsHTMLEditRules::PinSelectionToNewBlock(
     }
     return aSelection->Collapse(tmp, 0);
   }
 }
 
 nsresult 
 nsHTMLEditRules::CheckInterlinePosition(nsISelection *aSelection)
 {
-  if (!aSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelection> selection(aSelection);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   // if the selection isn't collapsed, do nothing.
   PRBool bCollapsed;
   nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) return res;
+  NS_ENSURE_TRUE(bCollapsed, res);
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, node;
   PRInt32 selOffset;
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   
   // are we after a block?  If so try set caret to following content
@@ -7638,59 +7638,59 @@ nsHTMLEditRules::CheckInterlinePosition(
   if (node && nsTextEditUtils::IsBreak(node))
       selPriv->SetInterlinePosition(PR_TRUE);
   return NS_OK;
 }
 
 nsresult 
 nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection aAction)
 {
-  if (!aSelection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelection> selection(aSelection);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
  
   // if the selection isn't collapsed, do nothing.
   // moose: one thing to do instead is check for the case of
   // only a single break selected, and collapse it.  Good thing?  Beats me.
   PRBool bCollapsed;
   nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) return res;
+  NS_ENSURE_TRUE(bCollapsed, res);
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, temp;
   PRInt32 selOffset;
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   temp = selNode;
   
   // are we in an editable node?
   while (!mHTMLEditor->IsEditable(selNode))
   {
     // scan up the tree until we find an editable place to be
     res = nsEditor::GetNodeLocation(temp, address_of(selNode), &selOffset);
     NS_ENSURE_SUCCESS(res, res);
-    if (!selNode) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(selNode, NS_ERROR_FAILURE);
     temp = selNode;
   }
   
   // make sure we aren't in an empty block - user will see no cursor.  If this
   // is happening, put a <br> in the block if allowed.
   nsCOMPtr<nsIDOMNode> theblock;
   if (IsBlockNode(selNode)) theblock = selNode;
   else theblock = mHTMLEditor->GetBlockNodeParent(selNode);
   if (theblock && mHTMLEditor->IsEditable(theblock)) {
     PRBool bIsEmptyNode;
     res = mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, PR_FALSE, PR_FALSE);
     NS_ENSURE_SUCCESS(res, res);
     // check if br can go into the destination node
     if (bIsEmptyNode && mHTMLEditor->CanContainTag(selNode, NS_LITERAL_STRING("br")))
     {
       nsIDOMElement *rootElement = mHTMLEditor->GetRoot();
-      if (!rootElement) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
       nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
       if (selNode == rootNode)
       {
         // Our root node is completely empty. Don't add a <br> here.
         // AfterEditInner() will add one for us when it calls
         // CreateBogusNodeIfNeeded()!
         return NS_OK;
       }
@@ -7801,17 +7801,17 @@ nsHTMLEditRules::AdjustSelection(nsISele
 
 
 nsresult
 nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, 
                                         PRInt32 aSelOffset, 
                                         nsIEditor::EDirection &aDirection,
                                         nsCOMPtr<nsIDOMNode> *outSelectableNode)
 {
-  if (!aSelNode || !outSelectableNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSelNode && outSelectableNode, NS_ERROR_NULL_POINTER);
   *outSelectableNode = nsnull;
   nsresult res = NS_OK;
   
   nsCOMPtr<nsIDOMNode> nearNode, curNode;
   if (aDirection == nsIEditor::ePrevious)
     res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
   else
     res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode));
@@ -7859,17 +7859,17 @@ nsHTMLEditRules::FindNearSelectableNode(
   return res;
 }
 
 
 nsresult
 nsHTMLEditRules::InDifferentTableElements(nsIDOMNode *aNode1, nsIDOMNode *aNode2, PRBool *aResult)
 {
   NS_ASSERTION(aNode1 && aNode2 && aResult, "null args");
-  if (!aNode1 || !aNode2 || !aResult) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode1 && aNode2 && aResult, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> tn1, tn2, node = aNode1, temp;
   *aResult = PR_FALSE;
   
   while (node && !nsHTMLEditUtils::IsTableElement(node))
   {
     node->GetParentNode(getter_AddRefs(temp));
     node = temp;
@@ -7917,17 +7917,17 @@ nsHTMLEditRules::RemoveEmptyNodes()
   // and thus put this parent node on the skiplist.
   // Unfortunately I can't use that strategy here, because the range may include 
   // some children of a node while excluding others.  Thus I could find all the 
   // _examined_ children empty, but still not have an empty parent.
   
   // need an iterator
   nsCOMPtr<nsIContentIterator> iter =
                   do_CreateInstance("@mozilla.org/content/post-content-iterator;1");
-  if (!iter) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
   
   nsresult res = iter->Init(mDocChangeRange);
   NS_ENSURE_SUCCESS(res, res);
   
   nsTArray<nsIDOMNode*> skipList;
 
   // check for empty nodes
   while (!iter->IsDone())
@@ -8051,36 +8051,36 @@ nsHTMLEditRules::RemoveEmptyNodes()
   }
   
   return res;
 }
 
 nsresult
 nsHTMLEditRules::SelectionEndpointInNode(nsIDOMNode *aNode, PRBool *aResult)
 {
-  if (!aNode || !aResult) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aResult, NS_ERROR_NULL_POINTER);
   
   *aResult = PR_FALSE;
   
   nsCOMPtr<nsISelection>selection;
   nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsISelectionPrivate>selPriv(do_QueryInterface(selection));
   
   nsCOMPtr<nsIEnumerator> enumerator;
   res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(res, res);
-  if (!enumerator) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(enumerator, NS_ERROR_UNEXPECTED);
 
   for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next())
   {
     nsCOMPtr<nsISupports> currentItem;
     res = enumerator->CurrentItem(getter_AddRefs(currentItem));
     NS_ENSURE_SUCCESS(res, res);
-    if (!currentItem) return NS_ERROR_UNEXPECTED;
+    NS_ENSURE_TRUE(currentItem, NS_ERROR_UNEXPECTED);
 
     nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
     nsCOMPtr<nsIDOMNode> startParent, endParent;
     range->GetStartContainer(getter_AddRefs(startParent));
     if (startParent)
     {
       if (aNode == startParent)
       {
@@ -8131,17 +8131,17 @@ nsHTMLEditRules::IsEmptyInline(nsIDOMNod
 
 PRBool 
 nsHTMLEditRules::ListIsEmptyLine(nsCOMArray<nsIDOMNode> &arrayOfNodes)
 {
   // we have a list of nodes which we are candidates for being moved
   // into a new block.  Determine if it's anything more than a blank line.
   // Look for editable content above and beyond one single BR.
   PRInt32 listCount = arrayOfNodes.Count();
-  if (!listCount) return PR_TRUE;
+  NS_ENSURE_TRUE(listCount, PR_TRUE);
   nsCOMPtr<nsIDOMNode> somenode;
   PRInt32 j, brCount=0;
   for (j = 0; j < listCount; j++)
   {
     somenode = arrayOfNodes[j];
     if (somenode && mHTMLEditor->IsEditable(somenode))
     {
       if (nsTextEditUtils::IsBreak(somenode))
@@ -8263,17 +8263,17 @@ nsHTMLEditRules::RemoveListStructure(nsI
 
 nsresult 
 nsHTMLEditRules::ConfirmSelectionInBody()
 {
   nsresult res = NS_OK;
 
   // get the body  
   nsIDOMElement *rootElement = mHTMLEditor->GetRoot();
-  if (!rootElement) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED);
 
   // get the selection
   nsCOMPtr<nsISelection>selection;
   res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   
   // get the selection start location
   nsCOMPtr<nsIDOMNode> selNode, temp, parent;
@@ -8385,17 +8385,17 @@ nsHTMLEditRules::UpdateDocChangeRange(ns
     }
   }
   return res;
 }
 
 nsresult 
 nsHTMLEditRules::InsertMozBRIfNeeded(nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   if (!IsBlockNode(aNode)) return NS_OK;
   
   PRBool isEmpty;
   nsCOMPtr<nsIDOMNode> brNode;
   nsresult res = mHTMLEditor->IsEmptyNode(aNode, &isEmpty);
   NS_ENSURE_SUCCESS(res, res);
   if (isEmpty)
   {
@@ -8418,17 +8418,17 @@ nsHTMLEditRules::WillCreateNode(const ns
 
 NS_IMETHODIMP 
 nsHTMLEditRules::DidCreateNode(const nsAString& aTag, 
                                nsIDOMNode *aNode, 
                                nsIDOMNode *aParent, 
                                PRInt32 aPosition, 
                                nsresult aResult)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   // assumption that Join keeps the righthand node
   nsresult res = mUtilRange->SelectNode(aNode);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
 }
 
 
@@ -8440,28 +8440,28 @@ nsHTMLEditRules::WillInsertNode(nsIDOMNo
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::DidInsertNode(nsIDOMNode *aNode, 
                                nsIDOMNode *aParent, 
                                PRInt32 aPosition, 
                                nsresult aResult)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   nsresult res = mUtilRange->SelectNode(aNode);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::WillDeleteNode(nsIDOMNode *aChild)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   nsresult res = mUtilRange->SelectNode(aChild);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
 }
 
 
 NS_IMETHODIMP 
@@ -8479,43 +8479,43 @@ nsHTMLEditRules::WillSplitNode(nsIDOMNod
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::DidSplitNode(nsIDOMNode *aExistingRightNode, 
                               PRInt32 aOffset, 
                               nsIDOMNode *aNewLeftNode, 
                               nsresult aResult)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   nsresult res = mUtilRange->SetStart(aNewLeftNode, 0);
   NS_ENSURE_SUCCESS(res, res);
   res = mUtilRange->SetEnd(aExistingRightNode, 0);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::WillJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMNode *aParent)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   // remember split point
   nsresult res = nsEditor::GetLengthOfDOMNode(aLeftNode, mJoinOffset);
   return res;  
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::DidJoinNodes(nsIDOMNode  *aLeftNode, 
                               nsIDOMNode *aRightNode, 
                               nsIDOMNode *aParent, 
                               nsresult aResult)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   // assumption that Join keeps the righthand node
   nsresult res = mUtilRange->SetStart(aRightNode, mJoinOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = mUtilRange->SetEnd(aRightNode, mJoinOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
 }
@@ -8529,17 +8529,17 @@ nsHTMLEditRules::WillInsertText(nsIDOMCh
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::DidInsertText(nsIDOMCharacterData *aTextNode, 
                                   PRInt32 aOffset, 
                                   const nsAString &aString, 
                                   nsresult aResult)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   PRInt32 length = aString.Length();
   nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode);
   nsresult res = mUtilRange->SetStart(theNode, aOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = mUtilRange->SetEnd(theNode, aOffset+length);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
@@ -8554,44 +8554,44 @@ nsHTMLEditRules::WillDeleteText(nsIDOMCh
 
 
 NS_IMETHODIMP 
 nsHTMLEditRules::DidDeleteText(nsIDOMCharacterData *aTextNode, 
                                   PRInt32 aOffset, 
                                   PRInt32 aLength, 
                                   nsresult aResult)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode);
   nsresult res = mUtilRange->SetStart(theNode, aOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = mUtilRange->SetEnd(theNode, aOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = UpdateDocChangeRange(mUtilRange);
   return res;  
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::WillDeleteRange(nsIDOMRange *aRange)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   // get the (collapsed) selection location
   return UpdateDocChangeRange(aRange);
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::DidDeleteRange(nsIDOMRange *aRange)
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection)
 {
-  if (!mListenerEnabled) return NS_OK;
+  NS_ENSURE_TRUE(mListenerEnabled, NS_OK);
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode;
   PRInt32 selOffset;
 
   nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = mUtilRange->SetStart(selNode, selOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -8611,17 +8611,17 @@ nsHTMLEditRules::DidDeleteSelection(nsIS
 
 // Let's remove all alignment hints in the children of aNode; it can
 // be an ALIGN attribute (in case we just remove it) or a CENTER
 // element (here we have to remove the container and keep its
 // children). We break on tables and don't look at their children.
 nsresult
 nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignType, PRBool aChildrenOnly)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   if (mHTMLEditor->IsTextNode(aNode) || nsHTMLEditUtils::IsTable(aNode)) return NS_OK;
   nsresult res = NS_OK;
 
   nsCOMPtr<nsIDOMNode> child = aNode,tmp;
   if (aChildrenOnly)
   {
     aNode->GetFirstChild(getter_AddRefs(child));
@@ -8720,30 +8720,30 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMN
 }
 
 // Let's insert a BR as first (resp. last) child of aNode if its
 // first (resp. last) child is not a block nor a BR, and if the
 // previous (resp. next) sibling is not a block nor a BR
 nsresult
 nsHTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, PRBool aStarts)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> child;
   nsresult res;
   if (aStarts)
   {
     res = mHTMLEditor->GetFirstEditableChild(aNode, address_of(child));
   }
   else
   {
     res = mHTMLEditor->GetLastEditableChild(aNode, address_of(child));
   }
   NS_ENSURE_SUCCESS(res, res);
-  if (!child) return NS_OK;
+  NS_ENSURE_TRUE(child, NS_OK);
   PRBool isChildBlock;
   res = mHTMLEditor->NodeIsBlockStatic(child, &isChildBlock);
   NS_ENSURE_SUCCESS(res, res);
   PRBool foundCR = PR_FALSE;
   if (isChildBlock || nsTextEditUtils::IsBreak(child))
   {
     foundCR = PR_TRUE;
   }
@@ -8778,17 +8778,17 @@ nsHTMLEditRules::MakeSureElemStartsOrEnd
   {
     nsCOMPtr<nsIDOMNode> brNode;
     PRInt32 offset = 0;
     if (!aStarts)
     {
       nsCOMPtr<nsIDOMNodeList> childNodes;
       res = aNode->GetChildNodes(getter_AddRefs(childNodes));
       NS_ENSURE_SUCCESS(res, res);
-      if (!childNodes) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(childNodes, NS_ERROR_NULL_POINTER);
       PRUint32 childCount;
       res = childNodes->GetLength(&childCount);
       NS_ENSURE_SUCCESS(res, res);
       offset = childCount;
     }
     res = mHTMLEditor->CreateBR(aNode, offset, address_of(brNode));
     NS_ENSURE_SUCCESS(res, res);
   }
@@ -8802,17 +8802,17 @@ nsHTMLEditRules::MakeSureElemStartsOrEnd
   NS_ENSURE_SUCCESS(res, res);
   res = MakeSureElemStartsOrEndsOnCR(aNode, PR_TRUE);
   return res;
 }
 
 nsresult
 nsHTMLEditRules::AlignBlock(nsIDOMElement * aElement, const nsAString * aAlignType, PRBool aContentsOnly)
 {
-  if (!aElement) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
   PRBool isBlock = IsBlockNode(node);
   if (!isBlock && !nsHTMLEditUtils::IsHR(node)) {
     // we deal only with blocks; early way out
     return NS_OK;
   }
 
--- a/editor/libeditor/html/nsHTMLEditUtils.cpp
+++ b/editor/libeditor/html/nsHTMLEditUtils.cpp
@@ -332,31 +332,31 @@ PRBool
 nsHTMLEditUtils::IsImage(nsIDOMNode *node)
 {
   return nsEditor::NodeIsType(node, nsEditProperty::img);
 }
 
 PRBool 
 nsHTMLEditUtils::IsLink(nsIDOMNode *aNode)
 {
-  if (!aNode) return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
   if (anchor)
   {
     nsAutoString tmpText;
     if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && !tmpText.IsEmpty())
       return PR_TRUE;
   }
   return PR_FALSE;
 }
 
 PRBool 
 nsHTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode)
 {
-  if (!aNode) return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
   if (anchor)
   {
     nsAutoString tmpText;
     if (NS_SUCCEEDED(anchor->GetName(tmpText)) && !tmpText.IsEmpty())
       return PR_TRUE;
   }
   return PR_FALSE;
@@ -388,17 +388,17 @@ nsHTMLEditUtils::IsMozDiv(nsIDOMNode *no
 ///////////////////////////////////////////////////////////////////////////
 // IsMailCite: true if node an html blockquote with type=cite
 //                  
 PRBool 
 nsHTMLEditUtils::IsMailCite(nsIDOMNode *node)
 {
   NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsMailCite");
   nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
-  if (!elem) return PR_FALSE;
+  NS_ENSURE_TRUE(elem, PR_FALSE);
   nsAutoString attrName (NS_LITERAL_STRING("type")); 
   
   // don't ask me why, but our html mailcites are id'd by "type=cite"...
   nsAutoString attrVal;
   nsresult res = elem->GetAttribute(attrName, attrVal);
   ToLowerCase(attrVal);
   if (NS_SUCCEEDED(res))
   {
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -259,17 +259,17 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc,
     return 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);
-    if (!sRangeHelper) return result;
+    NS_ENSURE_TRUE(sRangeHelper, result);
   }
    
   if (1)
   {
     // block to scope nsAutoEditInitRulesTrigger
     nsAutoEditInitRulesTrigger rulesTrigger(static_cast<nsPlaintextEditor*>(this), rulesRes);
 
     // Init the plaintext editor
@@ -291,17 +291,17 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc,
     if (mHTMLCSSUtils)
       delete mHTMLCSSUtils;
     result = NS_NewHTMLCSSUtils(&mHTMLCSSUtils);
     if (NS_FAILED(result)) { return result; }
     mHTMLCSSUtils->Init(this);
 
     // disable links
     nsPresContext *context = aPresShell->GetPresContext();
-    if (!context) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
     if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
       mLinkHandler = context->GetLinkHandler();
 
       context->SetLinkHandler(nsnull);
     }
 
     // init the type-in state
     mTypeInState = new TypeInState();
@@ -517,17 +517,17 @@ nsHTMLEditor::SetFlags(PRUint32 aFlags)
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::InitRules()
 {
   // instantiate the rules for the html editor
   nsresult res = NS_NewHTMLEditRules(getter_AddRefs(mRules));
   NS_ENSURE_SUCCESS(res, res);
-  if (!mRules) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(mRules, NS_ERROR_UNEXPECTED);
   res = mRules->Init(static_cast<nsPlaintextEditor*>(this));
   
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::BeginningOfDocument()
 {
@@ -538,17 +538,17 @@ nsHTMLEditor::BeginningOfDocument()
   nsresult res = GetSelection(getter_AddRefs(selection));
   if (NS_FAILED(res))
     return res;
   if (!selection)
     return 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
   PRBool done = PR_FALSE;
   nsCOMPtr<nsIDOMNode> curNode(rootElement), selNode;
   PRInt32 curOffset = 0, selOffset;
   while (!done)
   {
     nsWSRunObject wsObj(this, curNode, curOffset);
@@ -763,17 +763,17 @@ nsHTMLEditor::NodeIsBlockStatic(nsIDOMNo
   nsCOMPtr<nsIDOMElement>element = do_QueryInterface(aNode);
   if (!element)
   {
     // We don't have an element -- probably a text node
     return NS_OK;
   }
 
   nsIAtom *tagAtom = GetTag(aNode);
-  if (!tagAtom) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(tagAtom, NS_ERROR_NULL_POINTER);
 
   // Nodes we know we want to treat as block
   // even though the parser says they're not:
   if (tagAtom==nsEditProperty::body       ||
       tagAtom==nsEditProperty::head       ||
       tagAtom==nsEditProperty::tbody      ||
       tagAtom==nsEditProperty::thead      ||
       tagAtom==nsEditProperty::tfoot      ||
@@ -1124,17 +1124,17 @@ nsCOMPtr<nsIDOMNode>
 nsHTMLEditor::NextNodeInBlock(nsIDOMNode *aNode, IterDirection aDir)
 {
   nsCOMPtr<nsIDOMNode> nullNode;
   nsCOMPtr<nsIContent> content;
   nsCOMPtr<nsIContent> blockContent;
   nsCOMPtr<nsIDOMNode> node;
   nsCOMPtr<nsIDOMNode> blockParent;
   
-  if (!aNode)  return nullNode;
+  NS_ENSURE_TRUE(aNode, nullNode);
 
   nsresult rv;
   nsCOMPtr<nsIContentIterator> iter =
        do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &rv);
   if (NS_FAILED(rv))
     return nullNode;
 
   // much gnashing of teeth as we twit back and forth between content and domnode types
@@ -1143,19 +1143,19 @@ nsHTMLEditor::NextNodeInBlock(nsIDOMNode
   if (NS_SUCCEEDED(NodeIsBlockStatic(aNode, &isBlock)) && isBlock)
   {
     blockParent = aNode;
   }
   else
   {
     blockParent = GetBlockNodeParent(aNode);
   }
-  if (!blockParent) return nullNode;
+  NS_ENSURE_TRUE(blockParent, nullNode);
   blockContent = do_QueryInterface(blockParent);
-  if (!blockContent) return nullNode;
+  NS_ENSURE_TRUE(blockContent, nullNode);
   
   if (NS_FAILED(iter->Init(blockContent)))  return nullNode;
   if (NS_FAILED(iter->PositionAt(content)))  return nullNode;
   
   while (!iter->IsDone())
   {
     // ignore nodes that aren't elements or text, or that are the
     // block parent
@@ -1181,17 +1181,17 @@ static const PRUnichar nbsp = 160;
 nsresult 
 nsHTMLEditor::IsNextCharWhitespace(nsIDOMNode *aParentNode, 
                                    PRInt32 aOffset,
                                    PRBool *outIsSpace,
                                    PRBool *outIsNBSP,
                                    nsCOMPtr<nsIDOMNode> *outNode,
                                    PRInt32 *outOffset)
 {
-  if (!outIsSpace || !outIsNBSP) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outIsSpace && outIsNBSP, NS_ERROR_NULL_POINTER);
   *outIsSpace = PR_FALSE;
   *outIsNBSP = PR_FALSE;
   if (outNode) *outNode = nsnull;
   if (outOffset) *outOffset = -1;
   
   nsAutoString tempString;
   PRUint32 strLength;
   nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(aParentNode);
@@ -1253,17 +1253,17 @@ nsHTMLEditor::IsNextCharWhitespace(nsIDO
 nsresult 
 nsHTMLEditor::IsPrevCharWhitespace(nsIDOMNode *aParentNode, 
                                    PRInt32 aOffset,
                                    PRBool *outIsSpace,
                                    PRBool *outIsNBSP,
                                    nsCOMPtr<nsIDOMNode> *outNode,
                                    PRInt32 *outOffset)
 {
-  if (!outIsSpace || !outIsNBSP) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outIsSpace && outIsNBSP, NS_ERROR_NULL_POINTER);
   *outIsSpace = PR_FALSE;
   *outIsNBSP = PR_FALSE;
   if (outNode) *outNode = nsnull;
   if (outOffset) *outOffset = -1;
   
   nsAutoString tempString;
   PRUint32 strLength;
   nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(aParentNode);
@@ -1388,17 +1388,17 @@ PRBool nsHTMLEditor::IsModifiable()
 #pragma mark -
 #endif
 
 NS_IMETHODIMP
 nsHTMLEditor::UpdateBaseURL()
 {
   nsCOMPtr<nsIDOMDocument> domDoc;
   GetDocument(getter_AddRefs(domDoc));
-  if (!domDoc) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
 
   // Look for an HTML <base> tag
   nsCOMPtr<nsIDOMNodeList> nodeList;
   nsresult rv = domDoc->GetElementsByTagName(NS_LITERAL_STRING("base"), getter_AddRefs(nodeList));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMNode> baseNode;
   if (nodeList)
@@ -1411,17 +1411,17 @@ nsHTMLEditor::UpdateBaseURL()
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   // If no base tag, then set baseURL to the document's URL
   // This is very important, else relative URLs for links and images are wrong
   if (!baseNode)
   {
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-    if (!doc) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
     return doc->SetBaseURI(doc->GetDocumentURI());
   }
   return NS_OK;
 }
 
 /* This routine is needed to provide a bottleneck for typing for logging
    purposes.  Can't use HandleKeyPress() (above) for that since it takes
@@ -1447,37 +1447,37 @@ NS_IMETHODIMP nsHTMLEditor::TypedText(co
         return InsertBR(address_of(brNode));  // only inserts a br node
       }
   } 
   return NS_ERROR_FAILURE; 
 }
 
 NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled)
 {
-  if (!outHandled) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outHandled, NS_ERROR_NULL_POINTER);
   *outHandled = PR_FALSE;
 
   // Find enclosing table cell from the selection (cell may be the selected element)
   nsCOMPtr<nsIDOMElement> cellElement;
     // can't use |NS_LITERAL_STRING| here until |GetElementOrParentByTagName| is fixed to accept readables
   nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cellElement));
   NS_ENSURE_SUCCESS(res, res);
   // Do nothing -- we didn't find a table cell
-  if (!cellElement) return NS_OK;
+  NS_ENSURE_TRUE(cellElement, NS_OK);
 
   // find enclosing table
   nsCOMPtr<nsIDOMNode> tbl = GetEnclosingTable(cellElement);
-  if (!tbl) return res;
+  NS_ENSURE_TRUE(tbl, res);
 
   // advance to next cell
   // first create an iterator over the table
   nsCOMPtr<nsIContentIterator> iter =
       do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
   NS_ENSURE_SUCCESS(res, res);
-  if (!iter) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIContent> cTbl = do_QueryInterface(tbl);
   nsCOMPtr<nsIContent> cBlock = do_QueryInterface(cellElement);
   res = iter->Init(cTbl);
   NS_ENSURE_SUCCESS(res, res);
   // position iter at block
   res = iter->PositionAt(cBlock);
   NS_ENSURE_SUCCESS(res, res);
 
@@ -1534,34 +1534,34 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(P
   return res;
 }
 
 NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, 
                                          PRInt32 *aInOutOffset, 
                                          nsCOMPtr<nsIDOMNode> *outBRNode, 
                                          EDirection aSelect)
 {
-  if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aInOutParent && *aInOutParent && aInOutOffset && outBRNode, NS_ERROR_NULL_POINTER);
   *outBRNode = nsnull;
   nsresult res;
   
   // we need to insert a br.  unfortunately, we may have to split a text node to do it.
   nsCOMPtr<nsIDOMNode> node = *aInOutParent;
   PRInt32 theOffset = *aInOutOffset;
   nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(node);
   NS_NAMED_LITERAL_STRING(brType, "br");
   nsCOMPtr<nsIDOMNode> brNode;
   if (nodeAsText)  
   {
     nsCOMPtr<nsIDOMNode> tmp;
     PRInt32 offset;
     PRUint32 len;
     nodeAsText->GetLength(&len);
     GetNodeLocation(node, address_of(tmp), &offset);
-    if (!tmp) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     if (!theOffset)
     {
       // we are already set to go
     }
     else if (theOffset == (PRInt32)len)
     {
       // update offset to point AFTER the text node
       offset++;
@@ -1622,17 +1622,17 @@ NS_IMETHODIMP nsHTMLEditor::CreateBR(nsI
   return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
 }
 
 NS_IMETHODIMP nsHTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode)
 {
   PRBool bCollapsed;
   nsCOMPtr<nsISelection> selection;
 
-  if (!outBRNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outBRNode, NS_ERROR_NULL_POINTER);
   *outBRNode = nsnull;
 
   // calling it text insertion to trigger moz br treatment by rules
   nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);
 
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
@@ -1658,27 +1658,27 @@ NS_IMETHODIMP nsHTMLEditor::InsertBR(nsC
   res = selection->Collapse(selNode, selOffset+1);
   
   return res;
 }
 
 nsresult 
 nsHTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(nsISelection *aSelection, nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   nsresult res;
 
   nsCOMPtr<nsISelection> selection;
   if (aSelection)
   {
     selection = aSelection;
   } else {
     res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   }
   nsCOMPtr<nsIDOMNode> node = aNode;
   nsCOMPtr<nsIDOMNode> child;
   
   do {
     node->GetFirstChild(getter_AddRefs(child));
     
     if (child)
@@ -1703,38 +1703,38 @@ nsHTMLEditor::CollapseSelectionToDeepest
 //  the rules code won't let us edit under the <head> node
 NS_IMETHODIMP
 nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert)
 {
   nsAutoRules beginRulesSniffing(this, kOpIgnore, nsIEditor::eNone); // don't do any post processing, rules get confused
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   ForceCompositionEnd();
 
   // Do not use nsAutoRules -- rules code won't let us insert in <head>
   // Use the head node as a parent and delete/insert directly
   nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
-  if (!doc) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIDOMNodeList>nodeList; 
   res = doc->GetElementsByTagName(NS_LITERAL_STRING("head"), getter_AddRefs(nodeList));
   NS_ENSURE_SUCCESS(res, res);
-  if (!nodeList) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nodeList, NS_ERROR_NULL_POINTER);
 
   PRUint32 count; 
   nodeList->GetLength(&count);
   if (count < 1) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMNode> headNode;
   res = nodeList->Item(0, getter_AddRefs(headNode)); 
   NS_ENSURE_SUCCESS(res, res);
-  if (!headNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(headNode, NS_ERROR_NULL_POINTER);
 
   // First, make sure there are no return chars in the source.
   // Bad things happen if you insert returns (instead of dom newlines, \n)
   // into an editor document.
   nsAutoString inputString (aSourceToInsert);  // hope this does copy-on-write
  
   // Windows linebreaks: Map CRLF to LF:
   inputString.ReplaceSubstring(NS_LITERAL_STRING("\r\n").get(),
@@ -1743,17 +1743,17 @@ nsHTMLEditor::ReplaceHeadContentsWithHTM
   // Mac linebreaks: Map any remaining CR to LF:
   inputString.ReplaceSubstring(NS_LITERAL_STRING("\r").get(),
                                NS_LITERAL_STRING("\n").get());
 
   nsAutoEditBatch beginBatching(this);
 
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // Get the first range in the selection, for context:
   nsCOMPtr<nsIDOMRange> range;
   res = selection->GetRangeAt(0, getter_AddRefs(range));
   if (NS_FAILED(res))
     return res;
 
   nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range));
@@ -1768,17 +1768,17 @@ nsHTMLEditor::ReplaceHeadContentsWithHTM
 
   if (NS_FAILED(res))
   {
 #ifdef DEBUG
     printf("Couldn't create contextual fragment: error was %d\n", res);
 #endif
     return res;
   }
-  if (!docfrag) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(docfrag, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> child;
 
   // First delete all children in head
   do {
     res = headNode->GetFirstChild(getter_AddRefs(child));
     NS_ENSURE_SUCCESS(res, res);
     if (child)
@@ -1812,17 +1812,17 @@ nsHTMLEditor::RebuildDocumentFromSource(
   ForceCompositionEnd();
 
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
 
   nsIDOMElement *bodyElement = GetRoot();
   NS_ENSURE_SUCCESS(res, res);
-  if (!bodyElement) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);
 
   // Find where the <body> tag starts.
   nsReadingIterator<PRUnichar> beginbody;
   nsReadingIterator<PRUnichar> endbody;
   aSourceString.BeginReading(beginbody);
   aSourceString.EndReading(endbody);
   PRBool foundbody = CaseInsensitiveFindInReadable(NS_LITERAL_STRING("<body"),
                                                    beginbody, endbody);
@@ -1923,29 +1923,29 @@ nsHTMLEditor::RebuildDocumentFromSource(
   bodyTag.AssignLiteral("<div ");
   bodyTag.Append(Substring(endbody, endclosebody));
 
   nsCOMPtr<nsIDOMRange> range;
   res = selection->GetRangeAt(0, getter_AddRefs(range));
   NS_ENSURE_SUCCESS(res, 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(bodyTag, getter_AddRefs(docfrag));
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMNode> fragmentAsNode (do_QueryInterface(docfrag));
-  if (!fragmentAsNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(fragmentAsNode, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsIDOMNode> child;
   res = fragmentAsNode->GetFirstChild(getter_AddRefs(child));
   NS_ENSURE_SUCCESS(res, res);
-  if (!child) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(child, NS_ERROR_NULL_POINTER);
   
   // Copy all attributes from the div child to current body element
   res = CloneAttributes(bodyElement, child);
   NS_ENSURE_SUCCESS(res, res);
   
   // place selection at first editable content
   return BeginningOfDocument();
 }
@@ -2192,17 +2192,17 @@ nsHTMLEditor::SelectElement(nsIDOMElemen
   nsresult res = NS_ERROR_NULL_POINTER;
 
   // Must be sure that element is contained in the document body
   if (IsElementInBody(aElement))
   {
     nsCOMPtr<nsISelection> selection;
     res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsIDOMNode>parent;
     res = aElement->GetParentNode(getter_AddRefs(parent));
     if (NS_SUCCEEDED(res) && parent)
     {
       PRInt32 offsetInParent;
       res = GetChildOffset(aElement, parent, offsetInParent);
 
       if (NS_SUCCEEDED(res))
@@ -2225,21 +2225,21 @@ nsHTMLEditor::SetCaretAfterElement(nsIDO
   nsresult res = NS_ERROR_NULL_POINTER;
 
   // Be sure the element is contained in the document body
   if (aElement && IsElementInBody(aElement))
   {
     nsCOMPtr<nsISelection> selection;
     res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsIDOMNode>parent;
     res = aElement->GetParentNode(getter_AddRefs(parent));
     NS_ENSURE_SUCCESS(res, res);
-    if (!parent) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
     PRInt32 offsetInParent;
     res = GetChildOffset(aElement, parent, offsetInParent);
     if (NS_SUCCEEDED(res))
     {
       // Collapse selection to just after desired element,
       res = selection->Collapse(parent, offsetInParent+1);
 #if 0 //def DEBUG_cmanske
       {
@@ -2269,19 +2269,19 @@ nsHTMLEditor::SetParagraphFormat(const n
   else
     return InsertBasicBlock(tag);
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetParagraphState(PRBool *aMixed, nsAString &outFormat)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
-  if (!aMixed) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
-  if (!htmlRules) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
   
   return htmlRules->GetParagraphState(aMixed, outFormat);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetBackgroundColorState(PRBool *aMixed, nsAString &aOutColor)
 {
   nsresult res;
@@ -2314,32 +2314,32 @@ nsHTMLEditor::GetHighlightColorState(PRB
     res = GetCSSBackgroundColorState(aMixed, aOutColor, PR_FALSE);
   }
   return res;
 }
 
 nsresult
 nsHTMLEditor::GetCSSBackgroundColorState(PRBool *aMixed, nsAString &aOutColor, PRBool aBlockLevel)
 {
-  if (!aMixed) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
   *aMixed = PR_FALSE;
   // the default background color is transparent
   aOutColor.AssignLiteral("transparent");
   
   // get selection
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
 
   // get selection location
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   res = GetStartNodeAndOffset(selection, getter_AddRefs(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
-  if (!parent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
 
   // is the selection collapsed?
   PRBool bCollapsed;
   res = selection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsIDOMNode> nodeToExamine;
   if (bCollapsed || IsTextNode(parent))
   {
@@ -2349,17 +2349,17 @@ nsHTMLEditor::GetCSSBackgroundColorState
   else
   {
     // otherwise we want to look at the first editable node after
     // {parent,offset} and it's ancestors for divs with alignment on them
     nodeToExamine = GetChildAt(parent, offset);
     //GetNextNode(parent, offset, PR_TRUE, address_of(nodeToExamine));
   }
   
-  if (!nodeToExamine) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
 
   // is the node to examine a block ?
   PRBool isBlock;
   res = NodeIsBlockStatic(nodeToExamine, &isBlock);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMNode> tmp;
 
@@ -2426,17 +2426,17 @@ nsHTMLEditor::GetCSSBackgroundColorState
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetHTMLBackgroundColorState(PRBool *aMixed, nsAString &aOutColor)
 {
   //TODO: We don't handle "mixed" correctly!
-  if (!aMixed) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER);
   *aMixed = PR_FALSE;
   aOutColor.Truncate();
   
   nsCOMPtr<nsIDOMElement> element;
   PRInt32 selectedCount;
   nsAutoString tagName;
   nsresult res = GetSelectedOrParentTableElement(tagName,
                                                  &selectedCount,
@@ -2463,64 +2463,64 @@ nsHTMLEditor::GetHTMLBackgroundColorStat
     nsCOMPtr<nsIDOMNode> parentNode;
     res = element->GetParentNode(getter_AddRefs(parentNode));
     NS_ENSURE_SUCCESS(res, res);
     element = do_QueryInterface(parentNode);
   }
 
   // If no table or cell found, get page body
   element = GetRoot();
-  if (!element) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
 
   return element->GetAttribute(styleName, aOutColor);
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool *aDL)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
-  if (!aMixed || !aOL || !aUL || !aDL) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && aOL && aUL && aDL, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
-  if (!htmlRules) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
   
   return htmlRules->GetListState(aMixed, aOL, aUL, aDL);
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetListItemState(PRBool *aMixed, PRBool *aLI, PRBool *aDT, PRBool *aDD)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
-  if (!aMixed || !aLI || !aDT || !aDD) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && aLI && aDT && aDD, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
-  if (!htmlRules) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
   
   return htmlRules->GetListItemState(aMixed, aLI, aDT, aDD);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetAlignment(PRBool *aMixed, nsIHTMLEditor::EAlignment *aAlign)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
-  if (!aMixed || !aAlign) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aMixed && aAlign, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
-  if (!htmlRules) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
   
   return htmlRules->GetAlignment(aMixed, aAlign);
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
-  if (!aCanIndent || !aCanOutdent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCanIndent && aCanOutdent, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
-  if (!htmlRules) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
   
   return htmlRules->GetIndentState(aCanIndent, aCanOutdent);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::MakeOrChangeList(const nsAString& aListType, PRBool entireList, const nsAString& aBulletType)
 {
   nsresult res;
@@ -2533,17 +2533,17 @@ nsHTMLEditor::MakeOrChangeList(const nsA
   PRBool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpMakeList, nsIEditor::eNext);
   
   // pre-process
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeList);
   ruleInfo.blockType = &aListType;
   ruleInfo.entireList = entireList;
   ruleInfo.bulletType = &aBulletType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
@@ -2566,17 +2566,17 @@ nsHTMLEditor::MakeOrChangeList(const nsA
       // have to find a place to put the list
       nsCOMPtr<nsIDOMNode> parent = node;
       nsCOMPtr<nsIDOMNode> topChild = node;
       nsCOMPtr<nsIDOMNode> tmp;
     
       while ( !CanContainTag(parent, aListType))
       {
         parent->GetParentNode(getter_AddRefs(tmp));
-        if (!tmp) return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
         topChild = parent;
         parent = tmp;
       }
     
       if (parent != node)
       {
         // we need to split up to the child of parent
         res = SplitNodeDeep(topChild, node, offset, &offset);
@@ -2614,17 +2614,17 @@ nsHTMLEditor::RemoveList(const nsAString
   PRBool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpRemoveList, nsIEditor::eNext);
   
   // pre-process
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveList);
   if (aListType.LowerCaseEqualsLiteral("ol"))
     ruleInfo.bOrdered = PR_TRUE;
   else  ruleInfo.bOrdered = PR_FALSE;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
@@ -2647,17 +2647,17 @@ nsHTMLEditor::MakeDefinitionItem(const n
   PRBool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpMakeDefListItem, nsIEditor::eNext);
   
   // pre-process
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeDefListItem);
   ruleInfo.blockType = &aItemType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // todo: no default for now.  we count on rules to handle it.
@@ -2680,17 +2680,17 @@ nsHTMLEditor::InsertBasicBlock(const nsA
   PRBool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpMakeBasicBlock, nsIEditor::eNext);
   
   // pre-process
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeBasicBlock);
   ruleInfo.blockType = &aBlockType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
@@ -2710,17 +2710,17 @@ nsHTMLEditor::InsertBasicBlock(const nsA
       // have to find a place to put the block
       nsCOMPtr<nsIDOMNode> parent = node;
       nsCOMPtr<nsIDOMNode> topChild = node;
       nsCOMPtr<nsIDOMNode> tmp;
     
       while ( !CanContainTag(parent, aBlockType))
       {
         parent->GetParentNode(getter_AddRefs(tmp));
-        if (!tmp) return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
         topChild = parent;
         parent = tmp;
       }
     
       if (parent != node)
       {
         // we need to split up to the child of parent
         res = SplitNodeDeep(topChild, node, offset, &offset);
@@ -2761,17 +2761,17 @@ nsHTMLEditor::Indent(const nsAString& aI
   }
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
   
   // pre-process
   nsCOMPtr<nsISelection> selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(theAction);
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
   
   if (!handled)
   {
     // Do default - insert a blockquote node if selection collapsed
@@ -2792,17 +2792,17 @@ nsHTMLEditor::Indent(const nsAString& aI
         // have to find a place to put the blockquote
         nsCOMPtr<nsIDOMNode> parent = node;
         nsCOMPtr<nsIDOMNode> topChild = node;
         nsCOMPtr<nsIDOMNode> tmp;
         NS_NAMED_LITERAL_STRING(bq, "blockquote");
         while ( !CanContainTag(parent, bq))
         {
           parent->GetParentNode(getter_AddRefs(tmp));
-          if (!tmp) return NS_ERROR_FAILURE;
+          NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
           topChild = parent;
           parent = tmp;
         }
     
         if (parent != node)
         {
           // we need to split up to the child of parent
           res = SplitNodeDeep(topChild, node, offset, &offset);
@@ -2843,17 +2843,17 @@ nsHTMLEditor::Align(const nsAString& aAl
 
   nsCOMPtr<nsIDOMNode> node;
   PRBool cancel, handled;
   
   // Find out if the selection is collapsed:
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(nsTextEditRules::kAlign);
   ruleInfo.alignType = &aAlignType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(res))
     return res;
   
   res = mRules->DidDoAction(selection, &ruleInfo, res);
   return res;
@@ -2871,22 +2871,22 @@ nsHTMLEditor::GetElementOrParentByTagNam
   if (aNode)
     currentNode = aNode;
   else
   {
     // If no node supplied, get it from anchor node of current selection
     nsCOMPtr<nsISelection>selection;
     res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
     nsCOMPtr<nsIDOMNode> anchorNode;
     res = selection->GetAnchorNode(getter_AddRefs(anchorNode));
     if(NS_FAILED(res)) return res;
-    if (!anchorNode)  return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(anchorNode, NS_ERROR_FAILURE);
 
     // Try to get the actual selected node
     PRBool hasChildren = PR_FALSE;
     anchorNode->HasChildNodes(&hasChildren);
     if (hasChildren)
     {
       PRInt32 offset;
       res = selection->GetAnchorOffset(&offset);
@@ -2989,17 +2989,17 @@ nsHTMLEditor::GetSelectedElement(const n
   
   // 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);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   PRBool bNodeFound = PR_FALSE;
   res=NS_ERROR_NOT_INITIALIZED;
   PRBool isCollapsed;
   selection->GetIsCollapsed(&isCollapsed);
 
   nsAutoString domTagName;
@@ -3238,17 +3238,17 @@ nsHTMLEditor::CreateElementWithDefaults(
     realTagName = TagName;
   }
   //We don't use editor's CreateElement because we don't want to 
   //  go through the transaction system
 
   nsCOMPtr<nsIDOMElement>newElement;
   nsCOMPtr<nsIContent> newContent;
   nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
-  if (!doc) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
 
   //new call to use instead to get proper HTML element, bug# 39919
   res = CreateHTMLContent(realTagName, getter_AddRefs(newContent));
   newElement = do_QueryInterface(newContent);
   if (NS_FAILED(res) || !newElement)
     return NS_ERROR_FAILURE;
 
   // Mark the new element dirty, so it will be formatted
@@ -3288,27 +3288,27 @@ nsHTMLEditor::CreateElementWithDefaults(
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
 {
   nsresult res=NS_ERROR_NULL_POINTER;
   nsCOMPtr<nsISelection> selection;
 
-  if (!aAnchorElement) return NS_ERROR_NULL_POINTER; 
+  NS_ENSURE_TRUE(aAnchorElement, NS_ERROR_NULL_POINTER); 
 
 
   // We must have a real selection
   res = GetSelection(getter_AddRefs(selection));
   if (!selection)
   {
     res = NS_ERROR_NULL_POINTER;
   }
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   PRBool isCollapsed;
   res = selection->GetIsCollapsed(&isCollapsed);
   if (NS_FAILED(res))
     isCollapsed = PR_TRUE;
   
   if (isCollapsed)
   {
@@ -3406,17 +3406,17 @@ nsHTMLEditor::SetHTMLBackgroundColor(con
         };
         return res;
       }
     }
     // If we failed to find a cell, fall through to use originally-found element
   } else {
     // No table element -- set the background color on the body tag
     element = GetRoot();
-    if (!element)       return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
   }
   // Use the editor method that goes through the transaction system
   if (setColor)
     res = SetAttribute(element, bgcolor, aColor);
   else
     res = RemoveAttribute(element, bgcolor);
 
   return res;
@@ -3443,21 +3443,21 @@ nsHTMLEditor::GetLinkedObjects(nsISuppor
 {
   if (!aNodeList)
     return NS_ERROR_NULL_POINTER;
 
   nsresult res;
 
   res = NS_NewISupportsArray(aNodeList);
   NS_ENSURE_SUCCESS(res, res);
-  if (!*aNodeList) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aNodeList, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIContentIterator> iter =
        do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
-  if (!iter) return NS_ERROR_NULL_POINTER;
+  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;
 
     nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
@@ -3519,19 +3519,19 @@ nsHTMLEditor::ReplaceStyleSheet(const ns
     // Disable last sheet if not the same as new one
     if (!mLastStyleSheetURL.IsEmpty() && !mLastStyleSheetURL.Equals(aURL))
       return EnableStyleSheet(mLastStyleSheetURL, PR_FALSE);
 
     return NS_OK;
   }
 
   // Make sure the pres shell doesn't disappear during the load.
-  if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mPresShellWeak, NS_ERROR_NOT_INITIALIZED);
   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);
 
   return ps->GetDocument()->CSSLoader()->
     LoadSheet(uaURI, nsnull, EmptyCString(), this);
 }
@@ -3631,19 +3631,19 @@ nsHTMLEditor::RemoveOverrideStyleSheet(c
 
   // 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
 
-  if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mPresShellWeak, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   ps->RemoveOverrideStyleSheet(sheet);
   ps->ReconstructStyleData();
 
   // Remove it from our internal list
   return rv;
 }
 
@@ -3765,21 +3765,21 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupp
 {
   if (!aNodeList)
     return NS_ERROR_NULL_POINTER;
 
   nsresult res;
 
   res = NS_NewISupportsArray(aNodeList);
   NS_ENSURE_SUCCESS(res, res);
-  if (!*aNodeList) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(*aNodeList, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIContentIterator> iter =
       do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
-  if (!iter) return NS_ERROR_NULL_POINTER;
+  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;
 
     nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
@@ -3959,54 +3959,54 @@ nsHTMLEditor::IsModifiableNode(nsIDOMNod
   return !content || !(content->IntrinsicState() & NS_EVENT_STATE_MOZ_READONLY);
 }
 
 static nsresult SetSelectionAroundHeadChildren(nsCOMPtr<nsISelection> aSelection, nsWeakPtr aDocWeak)
 {
   nsresult res = NS_OK;
   // Set selection around <head> node
   nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(aDocWeak);
-  if (!doc) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIDOMNodeList>nodeList; 
   res = doc->GetElementsByTagName(NS_LITERAL_STRING("head"), getter_AddRefs(nodeList));
   NS_ENSURE_SUCCESS(res, res);
-  if (!nodeList) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(nodeList, NS_ERROR_NULL_POINTER);
 
   PRUint32 count; 
   nodeList->GetLength(&count);
   if (count < 1) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMNode> headNode;
   res = nodeList->Item(0, getter_AddRefs(headNode)); 
   NS_ENSURE_SUCCESS(res, res);
-  if (!headNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(headNode, NS_ERROR_NULL_POINTER);
 
   // Collapse selection to before first child of the head,
   res = aSelection->Collapse(headNode, 0);
   NS_ENSURE_SUCCESS(res, res);
 
   //  then extend it to just after
   nsCOMPtr<nsIDOMNodeList> childNodes;
   res = headNode->GetChildNodes(getter_AddRefs(childNodes));
   NS_ENSURE_SUCCESS(res, res);
-  if (!childNodes) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(childNodes, NS_ERROR_NULL_POINTER);
   PRUint32 childCount;
   childNodes->GetLength(&childCount);
 
   return aSelection->Extend(headNode, childCount+1);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetHeadContentsAsHTML(nsAString& aOutputString)
 {
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // Save current selection
   nsAutoSelectionReset selectionResetter(selection, this);
 
   res = SetSelectionAroundHeadChildren(selection, mDocWeak);
   NS_ENSURE_SUCCESS(res, res);
 
   res = OutputToString(NS_LITERAL_STRING("text/html"),
@@ -4464,17 +4464,17 @@ nsCOMPtr<nsIDOMElement> nsHTMLEditor::Fi
  * and collapses them into a single text node.
  * "adjacent" means literally adjacent siblings of the same parent.
  * Uses nsEditor::JoinNodes so action is undoable. 
  * Should be called within the context of a batch transaction.
  */
 NS_IMETHODIMP
 nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMRange *aInRange)
 {
-  if (!aInRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aInRange, NS_ERROR_NULL_POINTER);
   nsAutoTxnsConserveSelection dontSpazMySelection(this);
   nsTArray<nsIDOMNode*> textNodes;
   // we can't actually do anything during iteration, so store the text nodes in an array
   // don't bother ref counting them because we know we can hold them for the 
   // lifetime of this method
 
 
   // build a list of editable text nodes
@@ -4510,17 +4510,17 @@ nsHTMLEditor::CollapseAdjacentTextNodes(
     result =
       rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
     NS_ENSURE_SUCCESS(result, result);
     if (prevSibOfRightNode && (prevSibOfRightNode == leftTextNode))
     {
       nsCOMPtr<nsIDOMNode> parent;
       result = rightTextNode->GetParentNode(getter_AddRefs(parent));
       NS_ENSURE_SUCCESS(result, result);
-      if (!parent) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
       result = JoinNodes(leftTextNode, rightTextNode, parent);
       NS_ENSURE_SUCCESS(result, result);
     }
 
     textNodes.RemoveElementAt(0); // remove the leftmost text node from the list
   }
 
   return result;
@@ -4639,26 +4639,26 @@ nsHTMLEditor::RemoveBlockContainer(nsIDO
 
 ///////////////////////////////////////////////////////////////////////////
 // GetPriorHTMLSibling: returns the previous editable sibling, if there is
 //                   one within the parent
 //                       
 nsresult
 nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode)
 {
-  if (!outNode || !inNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode && inNode, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   *outNode = nsnull;
   nsCOMPtr<nsIDOMNode> temp, node = do_QueryInterface(inNode);
   
   while (1)
   {
     res = node->GetPreviousSibling(getter_AddRefs(temp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!temp) return NS_OK;  // return null sibling
+    NS_ENSURE_TRUE(temp, NS_OK);  // return null sibling
     // if it's editable, we're done
     if (IsEditable(temp)) break;
     // otherwise try again
     node = temp;
   }
   *outNode = temp;
   return res;
 }
@@ -4668,20 +4668,20 @@ nsHTMLEditor::GetPriorHTMLSibling(nsIDOM
 ///////////////////////////////////////////////////////////////////////////
 // GetPriorHTMLSibling: returns the previous editable sibling, if there is
 //                   one within the parent.  just like above routine but
 //                   takes a parent/offset instead of a node.
 //                       
 nsresult
 nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode)
 {
-  if (!outNode || !inParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode && inParent, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   *outNode = nsnull;
-  if (!inOffset) return NS_OK;  // return null sibling if at offset zero
+  NS_ENSURE_TRUE(inOffset, NS_OK);  // return null sibling if at offset zero
   nsCOMPtr<nsIDOMNode> node = nsEditor::GetChildAt(inParent,inOffset-1);
   if (IsEditable(node)) 
   {
     *outNode = node;
     return res;
   }
   // else
   return GetPriorHTMLSibling(node, outNode);
@@ -4691,26 +4691,26 @@ nsHTMLEditor::GetPriorHTMLSibling(nsIDOM
 
 ///////////////////////////////////////////////////////////////////////////
 // GetNextHTMLSibling: returns the next editable sibling, if there is
 //                   one within the parent
 //                       
 nsresult
 nsHTMLEditor::GetNextHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode)
 {
-  if (!outNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   *outNode = nsnull;
   nsCOMPtr<nsIDOMNode> temp, node = do_QueryInterface(inNode);
   
   while (1)
   {
     res = node->GetNextSibling(getter_AddRefs(temp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!temp) return NS_OK;  // return null sibling
+    NS_ENSURE_TRUE(temp, NS_OK);  // return null sibling
     // if it's editable, we're done
     if (IsEditable(temp)) break;
     // otherwise try again
     node = temp;
   }
   *outNode = temp;
   return res;
 }
@@ -4720,21 +4720,21 @@ nsHTMLEditor::GetNextHTMLSibling(nsIDOMN
 ///////////////////////////////////////////////////////////////////////////
 // GetNextHTMLSibling: returns the next editable sibling, if there is
 //                   one within the parent.  just like above routine but
 //                   takes a parent/offset instead of a node.
 //                       
 nsresult
 nsHTMLEditor::GetNextHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode)
 {
-  if (!outNode || !inParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode && inParent, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
   *outNode = nsnull;
   nsCOMPtr<nsIDOMNode> node = nsEditor::GetChildAt(inParent,inOffset);
-  if (!node) return NS_OK; // return null sibling if no sibling
+  NS_ENSURE_TRUE(node, NS_OK); // return null sibling if no sibling
   if (IsEditable(node)) 
   {
     *outNode = node;
     return res;
   }
   // else
   return GetPriorHTMLSibling(node, outNode);
 }
@@ -4743,17 +4743,17 @@ nsHTMLEditor::GetNextHTMLSibling(nsIDOMN
 
 ///////////////////////////////////////////////////////////////////////////
 // GetPriorHTMLNode: returns the previous editable leaf node, if there is
 //                   one within the <body>
 //
 nsresult
 nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, PRBool bNoBlockCrossing)
 {
-  if (!outNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
   nsresult res = GetPriorNode(inNode, PR_TRUE, address_of(*outNode), bNoBlockCrossing);
   NS_ENSURE_SUCCESS(res, res);
   
   // if it's not in the body, then zero it out
   if (*outNode && !nsTextEditUtils::InBody(*outNode, this))
   {
     *outNode = nsnull;
   }
@@ -4762,17 +4762,17 @@ nsHTMLEditor::GetPriorHTMLNode(nsIDOMNod
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetPriorHTMLNode: same as above but takes {parent,offset} instead of node
 //                       
 nsresult
 nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode, PRBool bNoBlockCrossing)
 {
-  if (!outNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
   nsresult res = GetPriorNode(inParent, inOffset, PR_TRUE, address_of(*outNode), bNoBlockCrossing);
   NS_ENSURE_SUCCESS(res, res);
   
   // if it's not in the body, then zero it out
   if (*outNode && !nsTextEditUtils::InBody(*outNode, this))
   {
     *outNode = nsnull;
   }
@@ -4782,17 +4782,17 @@ nsHTMLEditor::GetPriorHTMLNode(nsIDOMNod
 
 ///////////////////////////////////////////////////////////////////////////
 // GetNextHTMLNode: returns the next editable leaf node, if there is
 //                   one within the <body>
 //                       
 nsresult
 nsHTMLEditor::GetNextHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, PRBool bNoBlockCrossing)
 {
-  if (!outNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
   nsresult res = GetNextNode(inNode, PR_TRUE, address_of(*outNode), bNoBlockCrossing);
   NS_ENSURE_SUCCESS(res, res);
   
   // if it's not in the body, then zero it out
   if (*outNode && !nsTextEditUtils::InBody(*outNode, this))
   {
     *outNode = nsnull;
   }
@@ -4801,147 +4801,147 @@ nsHTMLEditor::GetNextHTMLNode(nsIDOMNode
 
 
 ///////////////////////////////////////////////////////////////////////////
 // GetNHTMLextNode: same as above but takes {parent,offset} instead of node
 //                       
 nsresult
 nsHTMLEditor::GetNextHTMLNode(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode, PRBool bNoBlockCrossing)
 {
-  if (!outNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
   nsresult res = GetNextNode(inParent, inOffset, PR_TRUE, address_of(*outNode), bNoBlockCrossing);
   NS_ENSURE_SUCCESS(res, res);
   
   // if it's not in the body, then zero it out
   if (*outNode && !nsTextEditUtils::InBody(*outNode, this))
   {
     *outNode = nsnull;
   }
   return res;
 }
 
 
 nsresult 
 nsHTMLEditor::IsFirstEditableChild( nsIDOMNode *aNode, PRBool *aOutIsFirst)
 {
   // check parms
-  if (!aOutIsFirst || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOutIsFirst && aNode, NS_ERROR_NULL_POINTER);
   
   // init out parms
   *aOutIsFirst = PR_FALSE;
   
   // find first editable child and compare it to aNode
   nsCOMPtr<nsIDOMNode> parent, firstChild;
   nsresult res = aNode->GetParentNode(getter_AddRefs(parent));
   NS_ENSURE_SUCCESS(res, res);
-  if (!parent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
   res = GetFirstEditableChild(parent, address_of(firstChild));
   NS_ENSURE_SUCCESS(res, res);
   
   *aOutIsFirst = (firstChild.get() == aNode);
   return res;
 }
 
 
 nsresult 
 nsHTMLEditor::IsLastEditableChild( nsIDOMNode *aNode, PRBool *aOutIsLast)
 {
   // check parms
-  if (!aOutIsLast || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOutIsLast && aNode, NS_ERROR_NULL_POINTER);
   
   // init out parms
   *aOutIsLast = PR_FALSE;
   
   // find last editable child and compare it to aNode
   nsCOMPtr<nsIDOMNode> parent, lastChild;
   nsresult res = aNode->GetParentNode(getter_AddRefs(parent));
   NS_ENSURE_SUCCESS(res, res);
-  if (!parent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
   res = GetLastEditableChild(parent, address_of(lastChild));
   NS_ENSURE_SUCCESS(res, res);
   
   *aOutIsLast = (lastChild.get() == aNode);
   return res;
 }
 
 
 nsresult 
 nsHTMLEditor::GetFirstEditableChild( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutFirstChild)
 {
   // check parms
-  if (!aOutFirstChild || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOutFirstChild && aNode, NS_ERROR_NULL_POINTER);
   
   // init out parms
   *aOutFirstChild = nsnull;
   
   // find first editable child
   nsCOMPtr<nsIDOMNode> child;
   nsresult res = aNode->GetFirstChild(getter_AddRefs(child));
   NS_ENSURE_SUCCESS(res, res);
   
   while (child && !IsEditable(child))
   {
     nsCOMPtr<nsIDOMNode> tmp;
     res = child->GetNextSibling(getter_AddRefs(tmp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!tmp) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     child = tmp;
   }
   
   *aOutFirstChild = child;
   return res;
 }
 
 
 nsresult 
 nsHTMLEditor::GetLastEditableChild( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutLastChild)
 {
   // check parms
-  if (!aOutLastChild || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOutLastChild && aNode, NS_ERROR_NULL_POINTER);
   
   // init out parms
   *aOutLastChild = aNode;
   
   // find last editable child
   nsCOMPtr<nsIDOMNode> child;
   nsresult res = aNode->GetLastChild(getter_AddRefs(child));
   NS_ENSURE_SUCCESS(res, res);
   
   while (child && !IsEditable(child))
   {
     nsCOMPtr<nsIDOMNode> tmp;
     res = child->GetPreviousSibling(getter_AddRefs(tmp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!tmp) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     child = tmp;
   }
   
   *aOutLastChild = child;
   return res;
 }
 
 nsresult 
 nsHTMLEditor::GetFirstEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutFirstLeaf)
 {
   // check parms
-  if (!aOutFirstLeaf || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOutFirstLeaf && aNode, NS_ERROR_NULL_POINTER);
   
   // init out parms
   *aOutFirstLeaf = aNode;
   
   // find leftmost leaf
   nsCOMPtr<nsIDOMNode> child;
   nsresult res = NS_OK;
   child = GetLeftmostChild(aNode);  
   while (child && (!IsEditable(child) || !nsEditorUtils::IsLeafNode(child)))
   {
     nsCOMPtr<nsIDOMNode> tmp;
     res = GetNextHTMLNode(child, address_of(tmp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!tmp) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     
     // only accept nodes that are descendants of aNode
     if (nsEditorUtils::IsDescendantOf(tmp, aNode))
       child = tmp;
     else
     {
       child = nsnull;  // this will abort the loop
     }
@@ -4951,31 +4951,31 @@ nsHTMLEditor::GetFirstEditableLeaf( nsID
   return res;
 }
 
 
 nsresult 
 nsHTMLEditor::GetLastEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOutLastLeaf)
 {
   // check parms
-  if (!aOutLastLeaf || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aOutLastLeaf && aNode, NS_ERROR_NULL_POINTER);
   
   // init out parms
   *aOutLastLeaf = nsnull;
   
   // find rightmost leaf
   nsCOMPtr<nsIDOMNode> child;
   nsresult res = NS_OK;
   child = GetRightmostChild(aNode, PR_FALSE);  
   while (child && (!IsEditable(child) || !nsEditorUtils::IsLeafNode(child)))
   {
     nsCOMPtr<nsIDOMNode> tmp;
     res = GetPriorHTMLNode(child, address_of(tmp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!tmp) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     
     // only accept nodes that are descendants of aNode
     if (nsEditorUtils::IsDescendantOf(tmp, aNode))
       child = tmp;
     else
     {
       child = nsnull;
     }
@@ -5020,17 +5020,17 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode 
   if (!textContent || !textContent->IsNodeOfType(nsINode::eTEXT)) 
     return NS_ERROR_NULL_POINTER;
   PRUint32 length = textContent->TextLength();
   if (aSafeToAskFrames)
   {
     nsCOMPtr<nsISelectionController> selCon;
     res = GetSelectionController(getter_AddRefs(selCon));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selCon) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
     PRBool isVisible = PR_FALSE;
     // ask the selection controller for information about whether any
     // of the data in the node is really rendered.  This is really
     // something that frames know about, but we aren't supposed to talk to frames.
     // So we put a call in the selection controller interface, since it's already
     // in bed with frames anyway.  (this is a fix for bug 22227, and a
     // partial fix for bug 46209)
     res = selCon->CheckVisibility(aNode, 0, length, &isVisible);
@@ -5072,17 +5072,17 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode 
 //                  
 nsresult
 nsHTMLEditor::IsEmptyNode( nsIDOMNode *aNode, 
                            PRBool *outIsEmptyNode, 
                            PRBool aSingleBRDoesntCount,
                            PRBool aListOrCellNotEmpty,
                            PRBool aSafeToAskFrames)
 {
-  if (!aNode || !outIsEmptyNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outIsEmptyNode, NS_ERROR_NULL_POINTER);
   *outIsEmptyNode = PR_TRUE;
   PRBool seenBR = PR_FALSE;
   return IsEmptyNodeImpl(aNode, outIsEmptyNode, aSingleBRDoesntCount,
                          aListOrCellNotEmpty, aSafeToAskFrames, &seenBR);
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // IsEmptyNodeImpl: workhorse for IsEmptyNode.
@@ -5090,17 +5090,17 @@ nsHTMLEditor::IsEmptyNode( nsIDOMNode *a
 nsresult
 nsHTMLEditor::IsEmptyNodeImpl( nsIDOMNode *aNode, 
                                PRBool *outIsEmptyNode, 
                                PRBool aSingleBRDoesntCount,
                                PRBool aListOrCellNotEmpty,
                                PRBool aSafeToAskFrames,
                                PRBool *aSeenBR)
 {
-  if (!aNode || !outIsEmptyNode || !aSeenBR) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && outIsEmptyNode && aSeenBR, NS_ERROR_NULL_POINTER);
   nsresult res = NS_OK;
 
   if (nsEditor::IsTextNode(aNode))
   {
     res = IsVisTextNode(aNode, outIsEmptyNode, aSafeToAskFrames);
     return res;
   }
 
@@ -5133,17 +5133,17 @@ nsHTMLEditor::IsEmptyNodeImpl( nsIDOMNod
     nsCOMPtr<nsIDOMNode> node = child;
     // is the node editable and non-empty?  if so, return false
     if (nsEditor::IsEditable(node))
     {
       if (nsEditor::IsTextNode(node))
       {
         res = IsVisTextNode(node, outIsEmptyNode, aSafeToAskFrames);
         NS_ENSURE_SUCCESS(res, res);
-        if (!*outIsEmptyNode) return NS_OK;  // break out if we find we aren't emtpy
+        NS_ENSURE_TRUE(*outIsEmptyNode, NS_OK);  // break out if we find we aren't emtpy
       }
       else  // an editable, non-text node.  we need to check it's content.
       {
         // is it the node we are iterating over?
         if (node == aNode) break;
         else if (aSingleBRDoesntCount && !*aSeenBR && nsTextEditUtils::IsBreak(node))
         {
           // the first br in a block doesn't count if the caller so indicated
@@ -5316,17 +5316,17 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   nsresult res;
   nsCOMPtr<nsISelection>selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   PRBool isCollapsed;
   selection->GetIsCollapsed(&isCollapsed);
 
   nsAutoEditBatch batchIt(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertElement, nsIEditor::eNext);
   nsAutoSelectionReset selectionResetter(selection, this);
@@ -5337,28 +5337,28 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled)
   {
     // get selection range enumerator
     nsCOMPtr<nsIEnumerator> enumerator;
     res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
     NS_ENSURE_SUCCESS(res, res);
-    if (!enumerator)    return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE);
 
     // loop thru the ranges in the selection
     enumerator->First(); 
     nsCOMPtr<nsISupports> currentItem;
     nsAutoString bgcolor; bgcolor.AssignLiteral("bgcolor");
     nsCOMPtr<nsIDOMNode> cachedBlockParent = nsnull;
     while ((NS_ENUMERATOR_FALSE == enumerator->IsDone()))
     {
       res = enumerator->CurrentItem(getter_AddRefs(currentItem));
       NS_ENSURE_SUCCESS(res, res);
-      if (!currentItem)   return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(currentItem, NS_ERROR_FAILURE);
       
       nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
       
       // check for easy case: both range endpoints in same text node
       nsCOMPtr<nsIDOMNode> startNode, endNode;
       PRInt32 startOffset, endOffset;
       res = range->GetStartContainer(getter_AddRefs(startNode));
       NS_ENSURE_SUCCESS(res, res);
@@ -5423,17 +5423,17 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
         // lets handle the nodes reported by the iterator.  These nodes
         // are entirely contained in the selection range.  We build up
         // a list of them (since doing operations on the document during
         // iteration would perturb the iterator).
 
         nsCOMPtr<nsIContentIterator> iter =
           do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
         NS_ENSURE_SUCCESS(res, res);
-        if (!iter)          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(iter, NS_ERROR_FAILURE);
 
         nsCOMArray<nsIDOMNode> arrayOfNodes;
         nsCOMPtr<nsIDOMNode> node;
                 
         // iterate range and build up array
         res = iter->Init(range);
         // init returns an error if no nodes in range.
         // this can easily happen with the subtree 
@@ -5643,25 +5643,25 @@ nsHTMLEditor::CopyLastEditableChildStyle
 }
 
 nsresult
 nsHTMLEditor::GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & aY)
 {
   aX = 0;
   aY = 0;
 
-  if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mPresShellWeak, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
   nsIFrame *frame = content->GetPrimaryFrame();
 
   nsIFrame *container = ps->GetAbsoluteContainingBlock(frame);
-  if (!frame) return NS_OK;
+  NS_ENSURE_TRUE(frame, NS_OK);
   nsPoint off = frame->GetOffsetTo(container);
   aX = nsPresContext::AppUnitsToIntCSSPixels(off.x);
   aY = nsPresContext::AppUnitsToIntCSSPixels(off.y);
 
   return NS_OK;
 }
 
 nsresult
@@ -5675,17 +5675,17 @@ nsHTMLEditor::EndUpdateViewBatch()
   // mutation events listeners because all the changes the user can apply
   // to a document may result in multiple events, some of them quite hard
   // to listen too (in particular when an ancestor of the selection is
   // changed but the selection itself is not changed).
   if (mUpdateCount == 0) {
     nsCOMPtr<nsISelection> selection;
     res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_NOT_INITIALIZED;
+    NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
     res = CheckSelectionStateForAnonymousButtons(selection);
   }
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::IgnoreSpuriousDragEvent(PRBool aIgnoreSpuriousDragEvent)
 {
@@ -5717,17 +5717,17 @@ nsHTMLEditor::GetSelectionContainer(nsID
     res = selection->GetRangeCount(&rangeCount);
     NS_ENSURE_SUCCESS(res, res);
 
     if (rangeCount == 1) {
 
       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<nsIDOMNode> startContainer, endContainer;
       res = range->GetStartContainer(getter_AddRefs(startContainer));
       NS_ENSURE_SUCCESS(res, res);
       res = range->GetEndContainer(getter_AddRefs(endContainer));
       NS_ENSURE_SUCCESS(res, res);
       PRInt32 startOffset, endOffset;
       res = range->GetStartOffset(&startOffset);
--- a/editor/libeditor/html/nsHTMLEditorEventListener.cpp
+++ b/editor/libeditor/html/nsHTMLEditorEventListener.cpp
@@ -98,17 +98,17 @@ nsHTMLEditorEventListener::MouseUp(nsIDO
     return NS_OK;
   }
 
   nsHTMLEditor* htmlEditor = GetHTMLEditor();
 
   nsCOMPtr<nsIDOMEventTarget> target;
   nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
   NS_ENSURE_SUCCESS(res, res);
-  if (!target) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
   PRInt32 clientX, clientY;
   mouseEvent->GetClientX(&clientX);
   mouseEvent->GetClientY(&clientY);
   htmlEditor->MouseUp(clientX, clientY, element);
 
   return nsEditorEventListener::MouseUp(aMouseEvent);
@@ -148,35 +148,35 @@ nsHTMLEditorEventListener::MouseDown(nsI
   PRInt32 clickCount;
   res = mouseEvent->GetDetail(&clickCount);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMEventTarget> target;
   nsCOMPtr<nsIDOMNSEvent> internalEvent = do_QueryInterface(aMouseEvent);
   res = internalEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
   NS_ENSURE_SUCCESS(res, res);
-  if (!target) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
   if (isContextClick || (buttonNumber == 0 && clickCount == 2))
   {
     nsCOMPtr<nsISelection> selection;
     mEditor->GetSelection(getter_AddRefs(selection));
-    if (!selection) return NS_OK;
+    NS_ENSURE_TRUE(selection, NS_OK);
 
     // Get location of mouse within target node
     nsCOMPtr<nsIDOMNSUIEvent> uiEvent = do_QueryInterface(aMouseEvent);
-    if (!uiEvent) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(uiEvent, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIDOMNode> parent;
     PRInt32 offset = 0;
 
     res = uiEvent->GetRangeParent(getter_AddRefs(parent));
     NS_ENSURE_SUCCESS(res, res);
-    if (!parent) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
 
     res = uiEvent->GetRangeOffset(&offset);
     NS_ENSURE_SUCCESS(res, res);
 
     // Detect if mouse point is within current selection for context click
     PRBool nodeIsInSelection = PR_FALSE;
     if (isContextClick)
     {
@@ -296,15 +296,15 @@ nsHTMLEditorEventListener::MouseClick(ns
   if (!mouseEvent) {
     //non-ui event passed in.  bad things.
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMEventTarget> target;
   nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
   NS_ENSURE_SUCCESS(res, res);
-  if (!target) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
   GetHTMLEditor()->DoInlineTableEditingAction(element);
 
   return nsEditorEventListener::MouseClick(aMouseEvent);
 }
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -128,17 +128,17 @@ NS_IMETHODIMP nsHTMLEditor::SetInlinePro
 {
   if (!aProperty) { return NS_ERROR_NULL_POINTER; }
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
   ForceCompositionEnd();
 
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   PRBool isCollapsed;
   selection->GetIsCollapsed(&isCollapsed);
   if (isCollapsed)
   {
     // manipulating text attributes on a collapsed selection only sets state for the next text insertion
     nsString tAttr(aAttribute);//MJUDGE SCC NEED HELP
@@ -156,26 +156,26 @@ NS_IMETHODIMP nsHTMLEditor::SetInlinePro
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled)
   {
     // get selection range enumerator
     nsCOMPtr<nsIEnumerator> enumerator;
     res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
     NS_ENSURE_SUCCESS(res, res);
-    if (!enumerator)    return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE);
 
     // loop thru the ranges in the selection
     enumerator->First(); 
     nsCOMPtr<nsISupports> currentItem;
     while ((NS_ENUMERATOR_FALSE == enumerator->IsDone()))
     {
       res = enumerator->CurrentItem(getter_AddRefs(currentItem));
       NS_ENSURE_SUCCESS(res, res);
-      if (!currentItem)   return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(currentItem, NS_ERROR_FAILURE);
       
       nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
 
       // adjust range to include any ancestors who's children are entirely selected
       res = PromoteInlineRange(range);
       NS_ENSURE_SUCCESS(res, res);
       
       // check for easy case: both range endpoints in same text node
@@ -204,17 +204,17 @@ NS_IMETHODIMP nsHTMLEditor::SetInlinePro
         // lets handle the nodes reported by the iterator.  These nodes
         // are entirely contained in the selection range.  We build up
         // a list of them (since doing operations on the document during
         // iteration would perturb the iterator).
 
         nsCOMPtr<nsIContentIterator> iter =
           do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
         NS_ENSURE_SUCCESS(res, res);
-        if (!iter)          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(iter, NS_ERROR_FAILURE);
 
         nsCOMArray<nsIDOMNode> arrayOfNodes;
         nsCOMPtr<nsIDOMNode> node;
         
         // iterate range and build up array
         res = iter->Init(range);
         // init returns an error if no nodes in range.
         // this can easily happen with the subtree 
@@ -289,17 +289,17 @@ NS_IMETHODIMP nsHTMLEditor::SetInlinePro
 nsresult
 nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, 
                                             PRInt32 aStartOffset,
                                             PRInt32 aEndOffset,
                                             nsIAtom *aProperty, 
                                             const nsAString *aAttribute,
                                             const nsAString *aValue)
 {
-  if (!aTextNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTextNode, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> parent;
   nsresult res = aTextNode->GetParentNode(getter_AddRefs(parent));
   NS_ENSURE_SUCCESS(res, res);
 
   nsAutoString tagString;
   aProperty->ToString(tagString);
   if (!CanContainTag(parent, tagString)) return NS_OK;
   
@@ -378,17 +378,17 @@ nsHTMLEditor::SetInlinePropertyOnTextNod
 
 
 nsresult
 nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode,
                                        nsIAtom *aProperty, 
                                        const nsAString *aAttribute,
                                        const nsAString *aValue)
 {
-  if (!aNode || !aProperty) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && aProperty, NS_ERROR_NULL_POINTER);
 
   nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> tmp;
   nsAutoString tag;
   aProperty->ToString(tag);
   ToLowerCase(tag);
   
   PRBool useCSS;
@@ -534,17 +534,17 @@ nsHTMLEditor::SetInlinePropertyOnNode( n
   return res;
 }
 
 
 nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, 
                                             nsIAtom *aProperty, 
                                             const nsAString *aAttribute)
 {
-  if (!inRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
   nsresult res;
   nsCOMPtr<nsIDOMNode> startNode, endNode, origStartNode;
   PRInt32 startOffset, endOffset, origStartOffset;
   
   res = inRange->GetStartContainer(getter_AddRefs(startNode));
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->GetStartOffset(&startOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -576,17 +576,17 @@ nsresult nsHTMLEditor::SplitStyleAboveRa
 
 nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
                                            PRInt32 *aOffset,
                                            nsIAtom *aProperty,          // null here means we split all properties
                                            const nsAString *aAttribute,
                                            nsCOMPtr<nsIDOMNode> *outLeftNode,
                                            nsCOMPtr<nsIDOMNode> *outRightNode)
 {
-  if (!aNode || !*aNode || !aOffset) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode && *aNode && aOffset, NS_ERROR_NULL_POINTER);
   if (outLeftNode)  *outLeftNode  = nsnull;
   if (outRightNode) *outRightNode = nsnull;
   // split any matching style nodes above the node/offset
   nsCOMPtr<nsIDOMNode> parent, tmp = *aNode;
   PRInt32 offset;
 
   PRBool useCSS;
   GetIsCSSEnabled(&useCSS);
@@ -620,17 +620,17 @@ nsresult nsHTMLEditor::SplitStyleAbovePo
     tmp->GetParentNode(getter_AddRefs(parent));
     tmp = parent;
   }
   return NS_OK;
 }
 
 PRBool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode)
 {
-  if (!aNode)               return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   if (!IsContainer(aNode))  return PR_FALSE;
   if (!IsEditable(aNode))   return PR_FALSE;
   if (IsBlockNode(aNode))   return PR_FALSE;
   if (NodeIsType(aNode, nsEditProperty::a)) return PR_FALSE;
   return PR_TRUE;
 }
 
 nsresult nsHTMLEditor::ApplyDefaultProperties()
@@ -648,17 +648,17 @@ nsresult nsHTMLEditor::ApplyDefaultPrope
   return res;
 }
 
 nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, 
                                    nsIAtom *aProperty,   // null here means remove all properties
                                    const nsAString *aAttribute, 
                                    PRBool aChildrenOnly)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   if (IsTextNode(aNode)) return NS_OK;
   nsresult res = NS_OK;
 
   // first process the children
   nsCOMPtr<nsIDOMNode> child, tmp;
   aNode->GetFirstChild(getter_AddRefs(child));
   while (child)
   {
@@ -727,17 +727,17 @@ nsresult nsHTMLEditor::RemoveStyleInside
         // then remove the whole node.  Otherwise just nix the attribute.
         if (IsOnlyAttribute(aNode, aAttribute))
         {
           res = RemoveContainer(aNode);
         }
         else
         {
           nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);
-          if (!elem) return NS_ERROR_NULL_POINTER;
+          NS_ENSURE_TRUE(elem, NS_ERROR_NULL_POINTER);
           res = RemoveAttribute(elem, *aAttribute);
         }
       }
     }
   }
   else {
     PRBool useCSS;
     GetIsCSSEnabled(&useCSS);
@@ -773,19 +773,19 @@ nsresult nsHTMLEditor::RemoveStyleInside
     res = RemoveContainer(aNode);  // if we are setting font size, remove any nested bigs and smalls
   }
   return res;
 }
 
 PRBool nsHTMLEditor::IsOnlyAttribute(nsIDOMNode *aNode, 
                                      const nsAString *aAttribute)
 {
-  if (!aNode || !aAttribute) return PR_FALSE;  // ooops
+  NS_ENSURE_TRUE(aNode && aAttribute, PR_FALSE);  // ooops
   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
-  if (!content) return PR_FALSE;  // ooops
+  NS_ENSURE_TRUE(content, PR_FALSE);  // ooops
   
   PRUint32 i, attrCount = content->GetAttrCount();
   for (i = 0; i < attrCount; ++i) {
     nsAutoString attrString;
     const nsAttrName* name = content->GetAttrNameAt(i);
     if (!name->NamespaceEquals(kNameSpaceID_None)) {
       return PR_FALSE;
     }
@@ -800,41 +800,41 @@ PRBool nsHTMLEditor::IsOnlyAttribute(nsI
   // if we made it through all of them without finding a real attribute
   // other than aAttribute, then return PR_TRUE
   return PR_TRUE;
 }
 
 PRBool nsHTMLEditor::HasAttr(nsIDOMNode *aNode, 
                              const nsAString *aAttribute)
 {
-  if (!aNode) return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   if (!aAttribute || aAttribute->IsEmpty()) return PR_TRUE;  // everybody has the 'null' attribute
   
   // get element
   nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);
-  if (!elem) return PR_FALSE;
+  NS_ENSURE_TRUE(elem, PR_FALSE);
   
   // get attribute node
   nsCOMPtr<nsIDOMAttr> attNode;
   nsresult res = elem->GetAttributeNode(*aAttribute, getter_AddRefs(attNode));
   if ((NS_FAILED(res)) || !attNode) return PR_FALSE;
   return PR_TRUE;
 }
 
 
 PRBool nsHTMLEditor::HasAttrVal(nsIDOMNode *aNode, 
                                 const nsAString *aAttribute, 
                                 const nsAString *aValue)
 {
-  if (!aNode) return PR_FALSE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);
   if (!aAttribute || aAttribute->IsEmpty()) return PR_TRUE;  // everybody has the 'null' attribute
   
   // get element
   nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);
-  if (!elem) return PR_FALSE;
+  NS_ENSURE_TRUE(elem, PR_FALSE);
   
   // get attribute node
   nsCOMPtr<nsIDOMAttr> attNode;
   nsresult res = elem->GetAttributeNode(*aAttribute, getter_AddRefs(attNode));
   if ((NS_FAILED(res)) || !attNode) return PR_FALSE;
   
   // check if attribute has a value
   PRBool isSet;
@@ -848,17 +848,17 @@ PRBool nsHTMLEditor::HasAttrVal(nsIDOMNo
   
   // do values match?
   if (attrVal.Equals(*aValue,nsCaseInsensitiveStringComparator())) return PR_TRUE;
   return PR_FALSE;
 }
 
 nsresult nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsIDOMRange *inRange)
 {
-  if (!inRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
   nsresult res;
   nsCOMPtr<nsIDOMNode> startNode, endNode, parent, tmp;
   PRInt32 startOffset, endOffset, tmpOffset;
   
   res = inRange->GetStartContainer(getter_AddRefs(startNode));
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->GetStartOffset(&startOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -871,17 +871,17 @@ nsresult nsHTMLEditor::PromoteRangeIfSta
   while ( tmp && 
           !nsTextEditUtils::IsBody(tmp) &&
           !nsHTMLEditUtils::IsNamedAnchor(tmp))
   {
     res = GetNodeLocation(tmp, address_of(parent), &tmpOffset);
     NS_ENSURE_SUCCESS(res, res);
     tmp = parent;
   }
-  if (!tmp) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(tmp, NS_ERROR_NULL_POINTER);
   if (nsHTMLEditUtils::IsNamedAnchor(tmp))
   {
     res = GetNodeLocation(tmp, address_of(parent), &tmpOffset);
     NS_ENSURE_SUCCESS(res, res);
     startNode = parent;
     startOffset = tmpOffset;
   }
 
@@ -889,34 +889,34 @@ nsresult nsHTMLEditor::PromoteRangeIfSta
   while ( tmp && 
           !nsTextEditUtils::IsBody(tmp) &&
           !nsHTMLEditUtils::IsNamedAnchor(tmp))
   {
     res = GetNodeLocation(tmp, address_of(parent), &tmpOffset);
     NS_ENSURE_SUCCESS(res, res);
     tmp = parent;
   }
-  if (!tmp) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(tmp, NS_ERROR_NULL_POINTER);
   if (nsHTMLEditUtils::IsNamedAnchor(tmp))
   {
     res = GetNodeLocation(tmp, address_of(parent), &tmpOffset);
     NS_ENSURE_SUCCESS(res, res);
     endNode = parent;
     endOffset = tmpOffset + 1;
   }
 
   res = inRange->SetStart(startNode, startOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->SetEnd(endNode, endOffset);
   return res;
 }
 
 nsresult nsHTMLEditor::PromoteInlineRange(nsIDOMRange *inRange)
 {
-  if (!inRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inRange, NS_ERROR_NULL_POINTER);
   nsresult res;
   nsCOMPtr<nsIDOMNode> startNode, endNode, parent;
   PRInt32 startOffset, endOffset;
   
   res = inRange->GetStartContainer(getter_AddRefs(startNode));
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->GetStartOffset(&startOffset);
   NS_ENSURE_SUCCESS(res, res);
@@ -929,73 +929,73 @@ nsresult nsHTMLEditor::PromoteInlineRang
           !nsTextEditUtils::IsBody(startNode) && 
           IsEditable(startNode) &&
           IsAtFrontOfNode(startNode, startOffset) )
   {
     res = GetNodeLocation(startNode, address_of(parent), &startOffset);
     NS_ENSURE_SUCCESS(res, res);
     startNode = parent;
   }
-  if (!startNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(startNode, NS_ERROR_NULL_POINTER);
   
   while ( endNode && 
           !nsTextEditUtils::IsBody(endNode) && 
           IsEditable(endNode) &&
           IsAtEndOfNode(endNode, endOffset) )
   {
     res = GetNodeLocation(endNode, address_of(parent), &endOffset);
     NS_ENSURE_SUCCESS(res, res);
     endNode = parent;
     endOffset++;  // we are AFTER this node
   }
-  if (!endNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(endNode, NS_ERROR_NULL_POINTER);
   
   res = inRange->SetStart(startNode, startOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = inRange->SetEnd(endNode, endOffset);
   return res;
 }
 
 PRBool nsHTMLEditor::IsAtFrontOfNode(nsIDOMNode *aNode, PRInt32 aOffset)
 {
-  if (!aNode) return PR_FALSE;  // oops
-  if (!aOffset) return PR_TRUE;
+  NS_ENSURE_TRUE(aNode, PR_FALSE);  // oops
+  NS_ENSURE_TRUE(aOffset, PR_TRUE);
   
   if (IsTextNode(aNode))
   {
     return PR_FALSE;
   }
   else
   {
     nsCOMPtr<nsIDOMNode> firstNode;
     GetFirstEditableChild(aNode, address_of(firstNode));
-    if (!firstNode) return PR_TRUE; 
+    NS_ENSURE_TRUE(firstNode, PR_TRUE); 
     PRInt32 offset;
     nsEditor::GetChildOffset(firstNode, aNode, offset);
     if (offset < aOffset) return PR_FALSE;
     return PR_TRUE;
   }
 }
 
 PRBool nsHTMLEditor::IsAtEndOfNode(nsIDOMNode *aNode, PRInt32 aOffset)
 {
-  if (!aNode) return PR_FALSE;  // oops
+  NS_ENSURE_TRUE(aNode, PR_FALSE);  // oops
   PRUint32 len;
   GetLengthOfDOMNode(aNode, len);
   if (aOffset == (PRInt32)len) return PR_TRUE;
   
   if (IsTextNode(aNode))
   {
     return PR_FALSE;
   }
   else
   {
     nsCOMPtr<nsIDOMNode> lastNode;
     GetLastEditableChild(aNode, address_of(lastNode));
-    if (!lastNode) return PR_TRUE; 
+    NS_ENSURE_TRUE(lastNode, PR_TRUE); 
     PRInt32 offset;
     nsEditor::GetChildOffset(lastNode, aNode, offset);
     if (offset < aOffset) return PR_TRUE;
     return PR_FALSE;
   }
 }
 
 
@@ -1019,41 +1019,41 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
   PRBool first=PR_TRUE;
 
   PRBool useCSS;
   GetIsCSSEnabled(&useCSS);
 
   nsCOMPtr<nsISelection>selection;
   result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   PRBool isCollapsed;
   selection->GetIsCollapsed(&isCollapsed);
   nsCOMPtr<nsIDOMNode> collapsedNode;
   nsCOMPtr<nsIEnumerator> enumerator;
   result = selPriv->GetEnumerator(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(result, result);
-  if (!enumerator) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(enumerator, NS_ERROR_NULL_POINTER);
 
   enumerator->First(); 
   nsCOMPtr<nsISupports> currentItem;
   result = enumerator->CurrentItem(getter_AddRefs(currentItem));
   // XXX: should be a while loop, to get each separate range
   // XXX: ERROR_HANDLING can currentItem be null?
   if ((NS_SUCCEEDED(result)) && currentItem)
   {
     PRBool firstNodeInRange = PR_TRUE; // for each range, set a flag 
     nsCOMPtr<nsIDOMRange> range(do_QueryInterface(currentItem));
 
     if (isCollapsed)
     {
       range->GetStartContainer(getter_AddRefs(collapsedNode));
-      if (!collapsedNode) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(collapsedNode, NS_ERROR_FAILURE);
       PRBool isSet, theSetting;
       if (aAttribute)
       {
         nsString tString(*aAttribute); //MJUDGE SCC NEED HELP
         nsString tOutString;//MJUDGE SCC NEED HELP
         nsString *tPassString=nsnull;
         if (outValue)
             tPassString = &tOutString;
@@ -1088,17 +1088,17 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
         }
         return NS_OK;
       }
     }
 
     // non-collapsed selection
     nsCOMPtr<nsIContentIterator> iter =
             do_CreateInstance("@mozilla.org/content/post-content-iterator;1");
-    if (!iter) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
 
     iter->Init(range);
     nsAutoString firstValue, theValue;
 
     nsCOMPtr<nsIDOMNode> endNode;
     PRInt32 endOffset;
     result = range->GetEndContainer(getter_AddRefs(endNode));
     NS_ENSURE_SUCCESS(result, result);
@@ -1261,24 +1261,24 @@ NS_IMETHODIMP nsHTMLEditor::RemoveAllInl
 
 NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsAString &aAttribute)
 {
   return RemoveInlinePropertyImpl(aProperty, &aAttribute);
 }
 
 nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAString *aAttribute)
 {
-  if (!mRules)    return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
   ForceCompositionEnd();
 
   nsresult res;
   nsCOMPtr<nsISelection>selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   PRBool isCollapsed;
   selection->GetIsCollapsed(&isCollapsed);
 
   PRBool useCSS;
   GetIsCSSEnabled(&useCSS);
 
@@ -1304,26 +1304,26 @@ nsresult nsHTMLEditor::RemoveInlinePrope
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(res, res);
   if (!cancel && !handled)
   {
     // get selection range enumerator
     nsCOMPtr<nsIEnumerator> enumerator;
     res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
     NS_ENSURE_SUCCESS(res, res);
-    if (!enumerator)    return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE);
 
     // loop thru the ranges in the selection
     enumerator->First(); 
     nsCOMPtr<nsISupports> currentItem;
     while ((NS_ENUMERATOR_FALSE == enumerator->IsDone()))
     {
       res = enumerator->CurrentItem(getter_AddRefs(currentItem));
       NS_ENSURE_SUCCESS(res, res);
-      if (!currentItem)   return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(currentItem, NS_ERROR_FAILURE);
       
       nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
 
       if (aProperty == nsEditProperty::name)
       {
         // promote range if it starts or end in a named anchor and we
         // want to remove named anchors
         res = PromoteRangeIfStartsOrEndsInNamedAnchor(range);
@@ -1376,17 +1376,17 @@ nsresult nsHTMLEditor::RemoveInlinePrope
         }
       }
       else
       {
         // not the easy case.  range not contained in single text node. 
         nsCOMPtr<nsIContentIterator> iter =
           do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
         NS_ENSURE_SUCCESS(res, res);
-        if (!iter)          return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(iter, NS_ERROR_FAILURE);
 
         nsCOMArray<nsIDOMNode> arrayOfNodes;
         nsCOMPtr<nsIDOMNode> node;
         
         // iterate range and build up array
         iter->Init(range);
         while (!iter->IsDone())
         {
@@ -1464,17 +1464,17 @@ nsHTMLEditor::RelativeFontChange( PRInt3
     return NS_ERROR_ILLEGAL_VALUE;
   
   ForceCompositionEnd();
 
   // Get the selection 
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));  
   // Is the selection collapsed?
   PRBool bCollapsed;
   res = selection->GetIsCollapsed(&bCollapsed);
   NS_ENSURE_SUCCESS(res, res);
   
   // if it's collapsed set typing state
   if (bCollapsed)
@@ -1506,26 +1506,26 @@ nsHTMLEditor::RelativeFontChange( PRInt3
   nsAutoRules beginRulesSniffing(this, kOpSetTextProperty, nsIEditor::eNext);
   nsAutoSelectionReset selectionResetter(selection, this);
   nsAutoTxnsConserveSelection dontSpazMySelection(this);
 
   // get selection range enumerator
   nsCOMPtr<nsIEnumerator> enumerator;
   res = selPriv->GetEnumerator(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(res, res);
-  if (!enumerator)    return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE);
 
   // loop thru the ranges in the selection
   enumerator->First(); 
   nsCOMPtr<nsISupports> currentItem;
   while ((NS_ENUMERATOR_FALSE == enumerator->IsDone()))
   {
     res = enumerator->CurrentItem(getter_AddRefs(currentItem));
     NS_ENSURE_SUCCESS(res, res);
-    if (!currentItem)   return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(currentItem, NS_ERROR_FAILURE);
     
     nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
 
     // adjust range to include any ancestors who's children are entirely selected
     res = PromoteInlineRange(range);
     NS_ENSURE_SUCCESS(res, res);
     
     // check for easy case: both range endpoints in same text node
@@ -1554,17 +1554,17 @@ nsHTMLEditor::RelativeFontChange( PRInt3
       // lets handle the nodes reported by the iterator.  These nodes
       // are entirely contained in the selection range.  We build up
       // a list of them (since doing operations on the document during
       // iteration would perturb the iterator).
 
       nsCOMPtr<nsIContentIterator> iter =
         do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res);
       NS_ENSURE_SUCCESS(res, res);
-      if (!iter)          return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(iter, NS_ERROR_FAILURE);
 
       nsCOMArray<nsIDOMNode> arrayOfNodes;
       nsCOMPtr<nsIDOMNode> node;
       
       // iterate range and build up array
       res = iter->Init(range);
       if (NS_SUCCEEDED(res))
       {
@@ -1625,17 +1625,17 @@ nsresult
 nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange, 
                                             nsIDOMCharacterData *aTextNode, 
                                             PRInt32 aStartOffset,
                                             PRInt32 aEndOffset)
 {
   // Can only change font size by + or - 1
   if ( !( (aSizeChange==1) || (aSizeChange==-1) ) )
     return NS_ERROR_ILLEGAL_VALUE;
-  if (!aTextNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTextNode, NS_ERROR_NULL_POINTER);
   
   // don't need to do anything if no characters actually selected
   if (aStartOffset == aEndOffset) return NS_OK;
   
   nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> parent;
   res = aTextNode->GetParentNode(getter_AddRefs(parent));
   NS_ENSURE_SUCCESS(res, res);
@@ -1699,17 +1699,17 @@ nsHTMLEditor::RelativeFontChangeHelper( 
       including aNode itself, looking for font nodes that have the size attr
       set.  Any such nodes need to have big or small put inside them, since
       they override any big/small that are above them.
   */
   
   // Can only change font size by + or - 1
   if ( !( (aSizeChange==1) || (aSizeChange==-1) ) )
     return NS_ERROR_ILLEGAL_VALUE;
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsresult res = NS_OK;
   nsAutoString tag;
   if (aSizeChange == 1) tag.AssignLiteral("big");
   else tag.AssignLiteral("small");
   nsCOMPtr<nsIDOMNodeList> childNodes;
   PRInt32 j;
   PRUint32 childCount;
@@ -1761,17 +1761,17 @@ nsHTMLEditor::RelativeFontChangeHelper( 
 
 nsresult
 nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange, 
                                         nsIDOMNode *aNode)
 {
   // Can only change font size by + or - 1
   if ( !( (aSizeChange==1) || (aSizeChange==-1) ) )
     return NS_ERROR_ILLEGAL_VALUE;
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
 
   nsresult res = NS_OK;
   nsCOMPtr<nsIDOMNode> tmp;
   nsAutoString tag;
   if (aSizeChange == 1) tag.AssignLiteral("big");
   else tag.AssignLiteral("small");
   
   // is it the opposite of what we want?  
--- a/editor/libeditor/html/nsHTMLInlineTableEditor.cpp
+++ b/editor/libeditor/html/nsHTMLInlineTableEditor.cpp
@@ -73,17 +73,17 @@ nsHTMLEditor::ShowInlineTableEditingUI(n
 
   if (mInlineEditedCell) {
     NS_ERROR("call HideInlineTableEditingUI first");
     return NS_ERROR_UNEXPECTED;
   }
 
   // the resizers and the shadow will be anonymous children of the body
   nsIDOMElement *bodyElement = GetRoot();
-  if (!bodyElement)   return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER);
 
   CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                          NS_LITERAL_STRING("mozTableAddColumnBefore"),
                          PR_FALSE, getter_AddRefs(mAddColumnBeforeButton));
   CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
                          NS_LITERAL_STRING("mozTableRemoveColumn"),
                          PR_FALSE, getter_AddRefs(mRemoveColumnButton));
   CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement,
@@ -129,17 +129,17 @@ nsHTMLEditor::HideInlineTableEditingUI()
   // are no document observers to notify, but we still want to
   // UnbindFromTree.
 
   // get the root content node.
 
   nsIDOMElement *bodyElement = GetRoot();
 
   nsCOMPtr<nsIContent> bodyContent( do_QueryInterface(bodyElement) );
-  if (!bodyContent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(bodyContent, NS_ERROR_FAILURE);
 
   DeleteRefToAnonymousNode(mAddColumnBeforeButton, bodyContent, ps);
   mAddColumnBeforeButton = nsnull;
   DeleteRefToAnonymousNode(mRemoveColumnButton, bodyContent, ps);
   mRemoveColumnButton = nsnull;
   DeleteRefToAnonymousNode(mAddColumnAfterButton, bodyContent, ps);
   mAddColumnAfterButton = nsnull;
   DeleteRefToAnonymousNode(mAddRowBeforeButton, bodyContent, ps);
--- a/editor/libeditor/html/nsHTMLObjectResizer.cpp
+++ b/editor/libeditor/html/nsHTMLObjectResizer.cpp
@@ -413,17 +413,17 @@ nsHTMLEditor::ShowResizersInner(nsIDOMEl
   res = CreateResizingInfo(getter_AddRefs(mResizingInfo), parentNode);
   NS_ENSURE_SUCCESS(res, res);
 
   // and listen to the "resize" event on the window first, get the
   // window from the document...
   nsCOMPtr<nsIDOMDocument> domDoc;
   GetDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
-  if (!doc) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(doc->GetWindow());
   if (!target) { return NS_ERROR_NULL_POINTER; }
 
   mResizeEventListenerP = new DocumentResizeEventListener(this);
   if (!mResizeEventListenerP) { return NS_ERROR_OUT_OF_MEMORY; }
   res = target->AddEventListener(NS_LITERAL_STRING("resize"), mResizeEventListenerP, PR_FALSE);
 
--- a/editor/libeditor/html/nsHTMLURIRefObject.cpp
+++ b/editor/libeditor/html/nsHTMLURIRefObject.cpp
@@ -147,17 +147,17 @@ nsHTMLURIRefObject::GetNextURI(nsAString
 
     mCurAttrIndex = 0;
     mNode->GetAttributes(getter_AddRefs(mAttributes));
     if (!mAttributes)
       return NS_ERROR_NOT_INITIALIZED;
 
     rv = mAttributes->GetLength(&mAttributeCnt);
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!mAttributeCnt) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(mAttributeCnt, NS_ERROR_FAILURE);
     mCurAttrIndex = 0;
   }
 #ifdef DEBUG_akkana
   printf("Looking at tag '%s'\n",
          NS_LossyConvertUTF16toASCII(tagName).get());
 #endif
   while (mCurAttrIndex < mAttributeCnt)
   {
@@ -314,17 +314,17 @@ nsHTMLURIRefObject::SetNode(nsIDOMNode *
   // then don't accept this node.
   mNode = 0;
   return NS_ERROR_INVALID_ARG;
 }
 
 nsresult NS_NewHTMLURIRefObject(nsIURIRefObject** aResult, nsIDOMNode* aNode)
 {
   nsHTMLURIRefObject* refObject = new nsHTMLURIRefObject();
-  if (!refObject) return NS_ERROR_OUT_OF_MEMORY;
+  NS_ENSURE_TRUE(refObject, NS_ERROR_OUT_OF_MEMORY);
   nsresult rv = refObject->SetNode(aNode);
   if (NS_FAILED(rv)) {
     *aResult = 0;
     delete refObject;
     return rv;
   }
   return refObject->QueryInterface(NS_GET_IID(nsIURIRefObject),
                                    (void**)aResult);
--- a/editor/libeditor/html/nsTableEditor.cpp
+++ b/editor/libeditor/html/nsTableEditor.cpp
@@ -119,24 +119,24 @@ public:
 };
 
 // Table Editing helper utilities (not exposed in IDL)
 
 NS_IMETHODIMP
 nsHTMLEditor::InsertCell(nsIDOMElement *aCell, PRInt32 aRowSpan, PRInt32 aColSpan, 
                          PRBool aAfter, PRBool aIsHeader, nsIDOMElement **aNewCell)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
   if (aNewCell) *aNewCell = nsnull;
 
   // And the parent and offsets needed to do an insert
   nsCOMPtr<nsIDOMNode> cellParent;
   nsresult res = aCell->GetParentNode(getter_AddRefs(cellParent));
   NS_ENSURE_SUCCESS(res, res);
-  if (!cellParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(cellParent, NS_ERROR_NULL_POINTER);
 
 
   PRInt32 cellOffset;
   res = GetChildOffset(aCell, cellParent, cellOffset);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMElement> newCell;
   if (aIsHeader)
@@ -172,25 +172,25 @@ nsHTMLEditor::InsertCell(nsIDOMElement *
 
   //Don't let Rules System change the selection
   nsAutoTxnsConserveSelection dontChangeSelection(this);
   return InsertNode(newCell, cellParent, cellOffset);
 }
 
 NS_IMETHODIMP nsHTMLEditor::SetColSpan(nsIDOMElement *aCell, PRInt32 aColSpan)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
   nsAutoString newSpan;
   newSpan.AppendInt(aColSpan, 10);
   return SetAttribute(aCell, NS_LITERAL_STRING("colspan"), newSpan);
 }
 
 NS_IMETHODIMP nsHTMLEditor::SetRowSpan(nsIDOMElement *aCell, PRInt32 aRowSpan)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
   nsAutoString newSpan;
   newSpan.AppendInt(aRowSpan, 10);
   return SetAttribute(aCell, NS_LITERAL_STRING("rowspan"), newSpan);
 }
 
 /****************************************************************/
 
 // Table Editing interface methods
@@ -204,27 +204,27 @@ nsHTMLEditor::InsertTableCell(PRInt32 aN
   PRInt32 cellOffset, startRowIndex, startColIndex;
   nsresult res = GetCellContext(nsnull,
                                 getter_AddRefs(table), 
                                 getter_AddRefs(curCell), 
                                 getter_AddRefs(cellParent), &cellOffset,
                                 &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if no cell found
-  if (!curCell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(curCell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   // Get more data for current cell in row we are inserting at (we need COLSPAN)
   PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   res = GetCellDataAt(table, startRowIndex, startColIndex,
                       getter_AddRefs(curCell),
                       &curStartRowIndex, &curStartColIndex, &rowSpan, &colSpan,
                       &actualRowSpan, &actualColSpan, &isSelected);
   NS_ENSURE_SUCCESS(res, res);
-  if (!curCell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(curCell, NS_ERROR_FAILURE);
   PRInt32 newCellIndex = aAfter ? (startColIndex+colSpan) : startColIndex;
   //We control selection resetting after the insert...
   nsSetSelectionAfterTableEdit setCaret(this, table, startRowIndex, newCellIndex, ePreviousColumn, PR_FALSE);
   //...so suppress Rules System selection munging
   nsAutoTxnsConserveSelection dontChangeSelection(this);
 
   PRInt32 i;
   for (i = 0; i < aNumber; i++)
@@ -240,26 +240,26 @@ nsHTMLEditor::InsertTableCell(PRInt32 aN
   }
   return res;
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetFirstRow(nsIDOMElement* aTableElement, nsIDOMNode** aRowNode)
 {
-  if (!aRowNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
 
   *aRowNode = nsnull;  
 
-  if (!aTableElement) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTableElement, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMElement> tableElement;
   nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTableElement, getter_AddRefs(tableElement));
   NS_ENSURE_SUCCESS(res, res);
-  if (!tableElement) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(tableElement, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> tableChild;
   res = tableElement->GetFirstChild(getter_AddRefs(tableChild));
   NS_ENSURE_SUCCESS(res, res);
 
   while (tableChild)
   {
     nsCOMPtr<nsIContent> content = do_QueryInterface(tableChild);
@@ -312,21 +312,21 @@ nsHTMLEditor::GetFirstRow(nsIDOMElement*
   };
   // If here, row was not found
   return NS_EDITOR_ELEMENT_NOT_FOUND;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetNextRow(nsIDOMNode* aCurrentRowNode, nsIDOMNode **aRowNode)
 {
-  if (!aRowNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
 
   *aRowNode = nsnull;  
 
-  if (!aCurrentRowNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCurrentRowNode, NS_ERROR_NULL_POINTER);
 
   if (!nsHTMLEditUtils::IsTableRow(aCurrentRowNode))
     return NS_ERROR_FAILURE;
   
   nsCOMPtr<nsIDOMNode> nextRow;
   nsresult res = aCurrentRowNode->GetNextSibling(getter_AddRefs(nextRow));
   NS_ENSURE_SUCCESS(res, res);
 
@@ -346,17 +346,17 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCu
     NS_ADDREF(*aRowNode);
     return NS_OK;
   }
 
   // No row found, search for rows in other table sections
   nsCOMPtr<nsIDOMNode> rowParent;
   res = aCurrentRowNode->GetParentNode(getter_AddRefs(rowParent));
   NS_ENSURE_SUCCESS(res, res);
-  if (!rowParent) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(rowParent, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> parentSibling;
   res = rowParent->GetNextSibling(getter_AddRefs(parentSibling));
   NS_ENSURE_SUCCESS(res, res);
 
   while (parentSibling)
   {
     res = parentSibling->GetFirstChild(getter_AddRefs(nextRow));
@@ -389,21 +389,21 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCu
   }
   // If here, row was not found
   return NS_EDITOR_ELEMENT_NOT_FOUND;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetLastCellInRow(nsIDOMNode* aRowNode, nsIDOMNode** aCellNode)
 {
-  if (!aCellNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCellNode, NS_ERROR_NULL_POINTER);
 
   *aCellNode = nsnull;
 
-  if (!aRowNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> rowChild;
   nsresult res = aRowNode->GetLastChild(getter_AddRefs(rowChild));
   NS_ENSURE_SUCCESS(res, res);
 
   while (rowChild && !nsHTMLEditUtils::IsTableCell(rowChild))
   {
     // Skip over textnodes
@@ -432,28 +432,28 @@ nsHTMLEditor::InsertTableColumn(PRInt32 
   PRInt32 startRowIndex, startColIndex;
   nsresult res = GetCellContext(getter_AddRefs(selection),
                                 getter_AddRefs(table), 
                                 getter_AddRefs(curCell), 
                                 nsnull, nsnull,
                                 &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if no cell found
-  if (!curCell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(curCell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   // Get more data for current cell (we need ROWSPAN)
   PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   res = GetCellDataAt(table, startRowIndex, startColIndex,
                       getter_AddRefs(curCell),
                       &curStartRowIndex, &curStartColIndex,
                       &rowSpan, &colSpan, 
                       &actualRowSpan, &actualColSpan, &isSelected);
   NS_ENSURE_SUCCESS(res, res);
-  if (!curCell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(curCell, NS_ERROR_FAILURE);
 
   nsAutoEditBatch beginBatching(this);
   // Prevent auto insertion of BR in new cell until we're done
   nsAutoRules beginRulesSniffing(this, kOpInsertNode, nsIEditor::eNext);
 
   // Use column after current cell if requested
   if (aAfter)
   {
@@ -531,17 +531,17 @@ nsHTMLEditor::InsertTableColumn(PRInt32 
       }
       NS_ENSURE_SUCCESS(res, res);
 
       if (rowNode)
       {
         nsCOMPtr<nsIDOMNode> lastCell;
         res = GetLastCellInRow(rowNode, getter_AddRefs(lastCell));
         NS_ENSURE_SUCCESS(res, res);
-        if (!lastCell) return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(lastCell, NS_ERROR_FAILURE);
 
         curCell = do_QueryInterface(lastCell);
         if (curCell)
         {
           // Simply add same number of cells to each row
           // Although tempted to check cell indexes for curCell,
           //  the effects of COLSPAN>1 in some cells makes this futile!
           // We must use NormalizeTable first to assure
@@ -565,28 +565,28 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNu
   PRInt32 startRowIndex, startColIndex;
   nsresult res = GetCellContext(nsnull,
                                 getter_AddRefs(table), 
                                 getter_AddRefs(curCell), 
                                 nsnull, nsnull, 
                                 &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if no cell found
-  if (!curCell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(curCell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   // Get more data for current cell in row we are inserting at (we need COLSPAN)
   PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   res = GetCellDataAt(table, startRowIndex, startColIndex,
                       getter_AddRefs(curCell),
                       &curStartRowIndex, &curStartColIndex,
                       &rowSpan, &colSpan, 
                       &actualRowSpan, &actualColSpan, &isSelected);
   NS_ENSURE_SUCCESS(res, res);
-  if (!curCell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(curCell, NS_ERROR_FAILURE);
   
   PRInt32 rowCount, colCount;
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   nsAutoEditBatch beginBatching(this);
   // Prevent auto insertion of BR in new cell until we're done
   nsAutoRules beginRulesSniffing(this, kOpInsertNode, nsIEditor::eNext);
@@ -686,20 +686,20 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNu
     PRInt32 newRowOffset;
 
     NS_NAMED_LITERAL_STRING(trStr, "tr");
     if (cellForRowParent)
     {
       nsCOMPtr<nsIDOMElement> parentRow;
       res = GetElementOrParentByTagName(trStr, cellForRowParent, getter_AddRefs(parentRow));
       NS_ENSURE_SUCCESS(res, res);
-      if (!parentRow) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(parentRow, NS_ERROR_NULL_POINTER);
 
       parentRow->GetParentNode(getter_AddRefs(parentOfRow));
-      if (!parentOfRow) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(parentOfRow, NS_ERROR_NULL_POINTER);
 
       res = GetChildOffset(parentRow, parentOfRow, newRowOffset);
       NS_ENSURE_SUCCESS(res, res);
       
       // Adjust for when adding past the end 
       if (aAfter && startRowIndex >= rowCount)
         newRowOffset++;
     }
@@ -708,24 +708,24 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNu
 
     for (PRInt32 row = 0; row < aNumber; row++)
     {
       // Create a new row
       nsCOMPtr<nsIDOMElement> newRow;
       res = CreateElementWithDefaults(trStr, getter_AddRefs(newRow));
       if (NS_SUCCEEDED(res))
       {
-        if (!newRow) return NS_ERROR_FAILURE;
+        NS_ENSURE_TRUE(newRow, NS_ERROR_FAILURE);
       
         for (PRInt32 i = 0; i < cellsInRow; i++)
         {
           nsCOMPtr<nsIDOMElement> newCell;
           res = CreateElementWithDefaults(NS_LITERAL_STRING("td"), getter_AddRefs(newCell));
           NS_ENSURE_SUCCESS(res, res);
-          if (!newCell) return NS_ERROR_FAILURE;
+          NS_ENSURE_TRUE(newCell, NS_ERROR_FAILURE);
 
           // Don't use transaction system yet! (not until entire row is inserted)
           nsCOMPtr<nsIDOMNode>resultNode;
           res = newRow->AppendChild(newCell, getter_AddRefs(resultNode));
           NS_ENSURE_SUCCESS(res, res);
         }
         // Use transaction system to insert the entire row+cells
         // (Note that rows are inserted at same childoffset each time)
@@ -738,17 +738,17 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNu
 }
 
 // Editor helper only
 // XXX Code changed for bug 217717 and now we don't need aSelection param
 //     TODO: Remove aSelection param
 NS_IMETHODIMP
 nsHTMLEditor::DeleteTable2(nsIDOMElement *aTable, nsISelection *aSelection)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
 
   // Select the table
   nsresult res = ClearSelection();
   if (NS_SUCCEEDED(res))
     res = AppendNodeToSelectionAsRange(aTable);
   NS_ENSURE_SUCCESS(res, res);
 
   return DeleteSelection(nsIEditor::eNext);
@@ -781,17 +781,17 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aN
   nsresult res = GetCellContext(getter_AddRefs(selection),
                          getter_AddRefs(table), 
                          getter_AddRefs(cell), 
                          nsnull, nsnull,
                          &startRowIndex, &startColIndex);
 
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if we didn't find a table or cell
-  if (!table || !cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(table && cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   nsAutoEditBatch beginBatching(this);
   // Prevent rules testing until we're done
   nsAutoRules beginRulesSniffing(this, kOpDeleteNode, nsIEditor::eNext);
 
   nsCOMPtr<nsIDOMElement> firstCell;
   nsCOMPtr<nsIDOMRange> range;
   res = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell));
@@ -919,24 +919,24 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aN
   {
     res = GetCellContext(getter_AddRefs(selection),
                          getter_AddRefs(table), 
                          getter_AddRefs(cell), 
                          nsnull, nsnull,
                          &startRowIndex, &startColIndex);
     NS_ENSURE_SUCCESS(res, res);
     // Don't fail if no cell found
-    if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+    NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
     if (1 == GetNumberOfCellsInRow(table, startRowIndex))
     {
       nsCOMPtr<nsIDOMElement> parentRow;
       res = GetElementOrParentByTagName(NS_LITERAL_STRING("tr"), cell, getter_AddRefs(parentRow));
       NS_ENSURE_SUCCESS(res, res);
-      if (!parentRow) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(parentRow, NS_ERROR_NULL_POINTER);
 
       // We should delete the row instead,
       //  but first check if its the only row left
       //  so we can delete the entire table
       PRInt32 rowCount, colCount;
       res = GetTableSize(table, &rowCount, &colCount);
       NS_ENSURE_SUCCESS(res, res);
       
@@ -973,17 +973,17 @@ nsHTMLEditor::DeleteTableCellContents()
   nsresult res;
   res = GetCellContext(getter_AddRefs(selection),
                        getter_AddRefs(table), 
                        getter_AddRefs(cell), 
                        nsnull, nsnull,
                        &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if no cell found
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
 
   nsAutoEditBatch beginBatching(this);
   // Prevent rules testing until we're done
   nsAutoRules beginRulesSniffing(this, kOpDeleteNode, nsIEditor::eNext);
   //Don't let Rules System change the selection
   nsAutoTxnsConserveSelection dontChangeSelection(this);
 
@@ -1016,17 +1016,17 @@ nsHTMLEditor::DeleteTableCellContents()
       cell = nsnull;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::DeleteCellContents(nsIDOMElement *aCell)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
 
   // Prevent rules testing until we're done
   nsAutoRules beginRulesSniffing(this, kOpDeleteNode, nsIEditor::eNext);
 
   nsCOMPtr<nsIDOMNode> child;
   PRBool hasChild;
   aCell->HasChildNodes(&hasChild);
 
@@ -1049,17 +1049,17 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 
   PRInt32 startRowIndex, startColIndex, rowCount, colCount;
   nsresult res = GetCellContext(getter_AddRefs(selection),
                                 getter_AddRefs(table), 
                                 getter_AddRefs(cell), 
                                 nsnull, nsnull,
                                 &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if no cell found
-  if (!table || !cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(table && cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   // Shortcut the case of deleting all columns in table
   if(startColIndex == 0 && aNumber >= colCount)
     return DeleteTable2(table, selection);
 
@@ -1122,17 +1122,17 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 
     NS_ENSURE_SUCCESS(res, res);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMElement> cell;
   nsCOMPtr<nsIDOMElement> cellInDeleteCol;
   PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   PRInt32 rowIndex = 0;
   nsresult res = NS_OK;
    
@@ -1184,17 +1184,17 @@ nsHTMLEditor::DeleteColumn(nsIDOMElement
           res = GetTableSize(aTable, &rowCount, &colCount);
           NS_ENSURE_SUCCESS(res, res);
 
           if (rowCount == 1)
           {
             nsCOMPtr<nsISelection> selection;
             res = GetSelection(getter_AddRefs(selection));
             NS_ENSURE_SUCCESS(res, res);
-            if (!selection) return NS_ERROR_FAILURE;
+            NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
             return DeleteTable2(aTable, selection);
           }
     
           // Delete the row by placing caret in cell we were to delete
           // We need to call DeleteTableRow to handle cells with rowspan 
           res = DeleteRow(aTable, startRowIndex);
           NS_ENSURE_SUCCESS(res, res);
 
@@ -1228,17 +1228,17 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNu
   PRInt32 rowCount, colCount;
   nsresult res =  GetCellContext(getter_AddRefs(selection),
                                  getter_AddRefs(table), 
                                  getter_AddRefs(cell), 
                                  nsnull, nsnull,
                                  &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if no cell found
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   // Shortcut the case of deleting all rows in table
   if(startRowIndex == 0 && aNumber >= rowCount)
     return DeleteTable2(table, selection);
 
@@ -1316,17 +1316,17 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNu
   }
   return NS_OK;
 }
 
 // Helper that doesn't batch or change the selection
 NS_IMETHODIMP
 nsHTMLEditor::DeleteRow(nsIDOMElement *aTable, PRInt32 aRowIndex)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMElement> cell;
   nsCOMPtr<nsIDOMElement> cellInDeleteRow;
   PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   PRInt32 colIndex = 0;
   nsresult res = NS_OK;
    
@@ -1419,60 +1419,60 @@ nsHTMLEditor::DeleteRow(nsIDOMElement *a
 NS_IMETHODIMP 
 nsHTMLEditor::SelectTable()
 {
   nsCOMPtr<nsIDOMElement> table;
   nsresult res = NS_ERROR_FAILURE;
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), nsnull, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if we didn't find a table
-  if (!table) return NS_OK;
+  NS_ENSURE_TRUE(table, NS_OK);
 
   res = ClearSelection();
   if (NS_SUCCEEDED(res))
     res = AppendNodeToSelectionAsRange(table);
 
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::SelectTableCell()
 {
   nsCOMPtr<nsIDOMElement> cell;
   nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell));
   NS_ENSURE_SUCCESS(res, res);
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   res = ClearSelection();
   if (NS_SUCCEEDED(res))
     res = AppendNodeToSelectionAsRange(cell);
 
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::SelectBlockOfCells(nsIDOMElement *aStartCell, nsIDOMElement *aEndCell)
 {
-  if (!aStartCell || !aEndCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aStartCell && aEndCell, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   NS_NAMED_LITERAL_STRING(tableStr, "table");
   nsCOMPtr<nsIDOMElement> table;
   res = GetElementOrParentByTagName(tableStr, aStartCell, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
-  if (!table) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMElement> endTable;
   res = GetElementOrParentByTagName(tableStr, aEndCell, getter_AddRefs(endTable));
   NS_ENSURE_SUCCESS(res, res);
-  if (!endTable) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(endTable, NS_ERROR_FAILURE);
   
   // We can only select a block if within the same table,
   //  so do nothing if not within one table
   if (table != endTable) return NS_OK;
 
   PRInt32 startRowIndex, startColIndex, endRowIndex, endColIndex;
 
   // Get starting and ending cells' location in the cellmap
@@ -1541,34 +1541,34 @@ nsHTMLEditor::SelectBlockOfCells(nsIDOME
 NS_IMETHODIMP 
 nsHTMLEditor::SelectAllTableCells()
 {
   nsCOMPtr<nsIDOMElement> cell;
   nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell));
   NS_ENSURE_SUCCESS(res, res);
   
   // Don't fail if we didn't find a cell
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   nsCOMPtr<nsIDOMElement> startCell = cell;
   
   // Get parent table
   nsCOMPtr<nsIDOMElement> table;
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), cell, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
   if(!table) return NS_ERROR_NULL_POINTER;
 
   PRInt32 rowCount, colCount;
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsISelection> selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   // Suppress nsISelectionListener notification
   //  until all selection changes are finished
   nsSelectionBatcherForTable selectionBatcher(selection);
 
   // It is now safe to clear the selection
   // BE SURE TO RESET IT BEFORE LEAVING!
   res = ClearSelection();
@@ -1606,31 +1606,31 @@ nsHTMLEditor::SelectAllTableCells()
 NS_IMETHODIMP 
 nsHTMLEditor::SelectTableRow()
 {
   nsCOMPtr<nsIDOMElement> cell;
   nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell));
   NS_ENSURE_SUCCESS(res, res);
   
   // Don't fail if we didn't find a cell
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
   nsCOMPtr<nsIDOMElement> startCell = cell;
 
   // Get table and location of cell:
   nsCOMPtr<nsISelection> selection;
   nsCOMPtr<nsIDOMElement> table;
   PRInt32 startRowIndex, startColIndex;
 
   res = GetCellContext(getter_AddRefs(selection),
                        getter_AddRefs(table), 
                        getter_AddRefs(cell),
                        nsnull, nsnull,
                        &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
-  if (!table) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
   
   PRInt32 rowCount, colCount;
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   //Note: At this point, we could get first and last cells in row,
   //  then call SelectBlockOfCells, but that would take just
   //  a little less code, so the following is more efficient
@@ -1672,32 +1672,32 @@ nsHTMLEditor::SelectTableRow()
 NS_IMETHODIMP 
 nsHTMLEditor::SelectTableColumn()
 {
   nsCOMPtr<nsIDOMElement> cell;
   nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell));
   NS_ENSURE_SUCCESS(res, res);
   
   // Don't fail if we didn't find a cell
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   nsCOMPtr<nsIDOMElement> startCell = cell;
   
   // Get location of cell:
   nsCOMPtr<nsISelection> selection;
   nsCOMPtr<nsIDOMElement> table;
   PRInt32 startRowIndex, startColIndex;
 
   res = GetCellContext(getter_AddRefs(selection),
                        getter_AddRefs(table), 
                        getter_AddRefs(cell),
                        nsnull, nsnull,
                        &startRowIndex, &startColIndex);
   NS_ENSURE_SUCCESS(res, res);
-  if (!table) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
 
   PRInt32 rowCount, colCount;
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   // Suppress nsISelectionListener notification
   //  until all selection changes are finished
   nsSelectionBatcherForTable selectionBatcher(selection);
@@ -1792,17 +1792,17 @@ nsHTMLEditor::SplitTableCell()
     rowIndex++;
   }
   return res;
 }
 
 nsresult
 nsHTMLEditor::CopyCellBackgroundColor(nsIDOMElement *destCell, nsIDOMElement *sourceCell)
 {
-  if (!destCell || !sourceCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(destCell && sourceCell, NS_ERROR_NULL_POINTER);
 
   // Copy backgournd color to new cell
   NS_NAMED_LITERAL_STRING(bgcolor, "bgcolor");
   nsAutoString color;
   PRBool isSet;
   nsresult res = GetAttributeValue(sourceCell, bgcolor, color, &isSet);
 
   if (NS_SUCCEEDED(res) && isSet)
@@ -1811,28 +1811,28 @@ nsHTMLEditor::CopyCellBackgroundColor(ns
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::SplitCellIntoColumns(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32 aColIndex,
                                    PRInt32 aColSpanLeft, PRInt32 aColSpanRight,
                                    nsIDOMElement **aNewCell)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
   if (aNewCell) *aNewCell = nsnull;
 
   nsCOMPtr<nsIDOMElement> cell;
   PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   nsresult res = GetCellDataAt(aTable, aRowIndex, aColIndex, getter_AddRefs(cell),
                                &startRowIndex, &startColIndex,
                                &rowSpan, &colSpan, 
                                &actualRowSpan, &actualColSpan, &isSelected);
   NS_ENSURE_SUCCESS(res, res);
-  if (!cell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(cell, NS_ERROR_NULL_POINTER);
   
   // We can't split!
   if (actualColSpan <= 1 || (aColSpanLeft + aColSpanRight) > actualColSpan)
     return NS_OK;
 
   // Reduce colspan of cell to split
   res = SetColSpan(cell, aColSpanLeft);
   NS_ENSURE_SUCCESS(res, res);
@@ -1854,28 +1854,28 @@ nsHTMLEditor::SplitCellIntoColumns(nsIDO
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::SplitCellIntoRows(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32 aColIndex,
                                 PRInt32 aRowSpanAbove, PRInt32 aRowSpanBelow, 
                                 nsIDOMElement **aNewCell)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
   if (aNewCell) *aNewCell = nsnull;
 
   nsCOMPtr<nsIDOMElement> cell;
   PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
   nsresult res = GetCellDataAt(aTable, aRowIndex, aColIndex, getter_AddRefs(cell),
                                &startRowIndex, &startColIndex,
                                &rowSpan, &colSpan, 
                                &actualRowSpan, &actualColSpan, &isSelected);
   NS_ENSURE_SUCCESS(res, res);
-  if (!cell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(cell, NS_ERROR_NULL_POINTER);
   
   // We can't split!
   if (actualRowSpan <= 1 || (aRowSpanAbove + aRowSpanBelow) > actualRowSpan)
     return NS_OK;
 
   PRInt32 rowCount, colCount;
   res = GetTableSize(aTable, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
@@ -1966,42 +1966,42 @@ nsHTMLEditor::SplitCellIntoRows(nsIDOMEl
     res = CopyCellBackgroundColor(newCell, cell2);
   }
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElement **aNewCell)
 {
-  if (!aSourceCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aSourceCell, NS_ERROR_NULL_POINTER);
 
   nsAutoEditBatch beginBatching(this);
   // Prevent auto insertion of BR in new cell created by ReplaceContainer
   nsAutoRules beginRulesSniffing(this, kOpInsertNode, nsIEditor::eNext);
 
   nsCOMPtr<nsIDOMNode> newNode;
 
   // Save current selection to restore when done
   // This is needed so ReplaceContainer can monitor selection
   //  when replacing nodes
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   nsAutoSelectionReset selectionResetter(selection, this);
 
   // Set to the opposite of current type
   nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(aSourceCell);
   nsString newCellType( (atom == nsEditProperty::td) ? NS_LITERAL_STRING("th") : NS_LITERAL_STRING("td"));
 
   // This creates new node, moves children, copies attributes (PR_TRUE)
   //   and manages the selection!
   res = ReplaceContainer(aSourceCell, address_of(newNode), newCellType, nsnull, nsnull, PR_TRUE);
   NS_ENSURE_SUCCESS(res, res);
-  if (!newNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(newNode, NS_ERROR_FAILURE);
 
   // Return the new cell
   if (aNewCell)
   {
     nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newNode);
     *aNewCell = newElement.get();
     NS_ADDREF(*aNewCell);
   }
@@ -2246,29 +2246,29 @@ nsHTMLEditor::JoinTableCells(PRBool aMer
         res = DeleteNode(node);
         NS_ENSURE_SUCCESS(res, res);
       }
     }
     // Cleanup selection: remove ranges where cells were deleted
     nsCOMPtr<nsISelection> selection;
     res = GetSelection(getter_AddRefs(selection));
     NS_ENSURE_SUCCESS(res, res);
-    if (!selection) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
     PRInt32 rangeCount;
     res = selection->GetRangeCount(&rangeCount);
     NS_ENSURE_SUCCESS(res, res);
 
     nsCOMPtr<nsIDOMRange> range;
     PRInt32 i;
     for (i = 0; i < rangeCount; i++)
     {
       res = selection->GetRangeAt(i, getter_AddRefs(range));
       NS_ENSURE_SUCCESS(res, res);
-      if (!range) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
       nsCOMPtr<nsIDOMElement> deletedCell;
       res = GetCellFromRange(range, getter_AddRefs(deletedCell));
       if (!deletedCell)
       {
         selection->RemoveRange(range);
         rangeCount--;
         i--;
@@ -2287,17 +2287,17 @@ nsHTMLEditor::JoinTableCells(PRBool aMer
   }
   else
   {
     // Joining with cell to the right -- get rowspan and colspan data of target cell
     res = GetCellDataAt(table, startRowIndex, startColIndex, getter_AddRefs(targetCell),
                         &startRowIndex, &startColIndex, &rowSpan, &colSpan, 
                         &actualRowSpan, &actualColSpan, &isSelected);
     NS_ENSURE_SUCCESS(res, res);
-    if (!targetCell) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(targetCell, NS_ERROR_NULL_POINTER);
 
     // Get data for cell to the right
     res = GetCellDataAt(table, startRowIndex, startColIndex+actualColSpan, getter_AddRefs(cell2),
                         &startRowIndex2, &startColIndex2, &rowSpan2, &colSpan2, 
                         &actualRowSpan2, &actualColSpan2, &isSelected2);
     NS_ENSURE_SUCCESS(res, res);
     if(!cell2) return NS_OK; // Don't fail if there's no cell
 
@@ -2351,17 +2351,17 @@ nsHTMLEditor::JoinTableCells(PRBool aMer
   return res;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::MergeCells(nsCOMPtr<nsIDOMElement> aTargetCell, 
                          nsCOMPtr<nsIDOMElement> aCellToMerge,
                          PRBool aDeleteCellToMerge)
 {
-  if (!aTargetCell || !aCellToMerge) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTargetCell && aCellToMerge, NS_ERROR_NULL_POINTER);
 
   nsresult res = NS_OK;
 
   // Prevent rules testing until we're done
   nsAutoRules beginRulesSniffing(this, kOpDeleteNode, nsIEditor::eNext);
 
   // Don't need to merge if cell is empty
   if (!IsEmptyCell(aCellToMerge))
@@ -2416,17 +2416,17 @@ nsHTMLEditor::MergeCells(nsCOMPtr<nsIDOM
 
   return res;
 }
 
 
 NS_IMETHODIMP 
 nsHTMLEditor::FixBadRowSpan(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32& aNewRowCount)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
 
   PRInt32 rowCount, colCount;
   nsresult res = GetTableSize(aTable, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMElement>cell;
   PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
@@ -2474,17 +2474,17 @@ nsHTMLEditor::FixBadRowSpan(nsIDOMElemen
     }
   }
   return GetTableSize(aTable, &aNewRowCount, &colCount);
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::FixBadColSpan(nsIDOMElement *aTable, PRInt32 aColIndex, PRInt32& aNewColCount)
 {
-  if (!aTable) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NULL_POINTER);
 
   PRInt32 rowCount, colCount;
   nsresult res = GetTableSize(aTable, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMElement> cell;
   PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
@@ -2535,23 +2535,23 @@ nsHTMLEditor::FixBadColSpan(nsIDOMElemen
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::NormalizeTable(nsIDOMElement *aTable)
 {
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMElement> table;
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTable, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
   // Don't fail if we didn't find a table
-  if (!table)         return NS_OK;
+  NS_ENSURE_TRUE(table, NS_OK);
 
   PRInt32 rowCount, colCount, rowIndex, colIndex;
   res = GetTableSize(table, &rowCount, &colCount);
   NS_ENSURE_SUCCESS(res, res);
 
   // Save current selection
   nsAutoSelectionReset selectionResetter(selection, this);
 
@@ -2638,45 +2638,45 @@ nsHTMLEditor::GetCellIndexes(nsIDOMEleme
     nsCOMPtr<nsIDOMElement> cell;
     res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell));
     if (NS_SUCCEEDED(res) && cell)
       aCell = cell;
     else
       return NS_ERROR_FAILURE;
   }
 
-  if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(mPresShellWeak, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIContent> nodeAsContent( do_QueryInterface(aCell) );
-  if (!nodeAsContent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(nodeAsContent, NS_ERROR_FAILURE);
   // frames are not ref counted, so don't use an nsCOMPtr
   nsIFrame *layoutObject = nodeAsContent->GetPrimaryFrame();
-  if (!layoutObject)  return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(layoutObject, NS_ERROR_FAILURE);
 
   nsITableCellLayout *cellLayoutObject = do_QueryFrame(layoutObject);
-  if (!cellLayoutObject)  return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(cellLayoutObject, NS_ERROR_FAILURE);
   return cellLayoutObject->GetCellIndexes(*aRowIndex, *aColIndex);
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetTableLayoutObject(nsIDOMElement* aTable, nsITableLayout **tableLayoutObject)
 {
   *tableLayoutObject=nsnull;
-  if (!aTable) return NS_ERROR_NOT_INITIALIZED;
-  if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NOT_INITIALIZED);
+  NS_ENSURE_TRUE(mPresShellWeak, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
-  if (!ps) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsIContent> nodeAsContent( do_QueryInterface(aTable) );
-  if (!nodeAsContent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(nodeAsContent, NS_ERROR_FAILURE);
   // frames are not ref counted, so don't use an nsCOMPtr
   nsIFrame *layoutObject = nodeAsContent->GetPrimaryFrame();
-  if (!layoutObject)  return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(layoutObject, NS_ERROR_FAILURE);
 
   *tableLayoutObject = do_QueryFrame(layoutObject);
   return *tableLayoutObject ? NS_OK : NS_NOINTERFACE;
 }
 
 //Return actual number of cells (a cell with colspan > 1 counts as just 1)
 PRBool nsHTMLEditor::GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowIndex)
 {
@@ -2719,17 +2719,17 @@ nsHTMLEditor::GetTableSize(nsIDOMElement
   NS_ENSURE_ARG_POINTER(aColCount);
   nsresult res;
   *aRowCount = 0;
   *aColCount = 0;
   nsCOMPtr<nsIDOMElement> table;
   // Get the selected talbe or the table enclosing the selection anchor
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTable, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
-  if (!table)         return NS_ERROR_FAILURE;
+  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;
 
@@ -2746,17 +2746,17 @@ nsHTMLEditor::GetCellDataAt(nsIDOMElemen
 {
   NS_ENSURE_ARG_POINTER(aStartRowIndex);
   NS_ENSURE_ARG_POINTER(aStartColIndex);
   NS_ENSURE_ARG_POINTER(aRowSpan);
   NS_ENSURE_ARG_POINTER(aColSpan);
   NS_ENSURE_ARG_POINTER(aActualRowSpan);
   NS_ENSURE_ARG_POINTER(aActualColSpan);
   NS_ENSURE_ARG_POINTER(aIsSelected);
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
 
   nsresult res=NS_ERROR_FAILURE;
   *aStartRowIndex = 0;
   *aStartColIndex = 0;
   *aRowSpan = 0;
   *aColSpan = 0;
   *aActualRowSpan = 0;
   *aActualColSpan = 0;
@@ -2775,17 +2775,17 @@ nsHTMLEditor::GetCellDataAt(nsIDOMElemen
     else
       return NS_ERROR_FAILURE;
   }
   
   // frames are not ref counted, so don't use an nsCOMPtr
   nsITableLayout *tableLayoutObject;
   res = GetTableLayoutObject(aTable, &tableLayoutObject);
   NS_ENSURE_SUCCESS(res, res);
-  if (!tableLayoutObject) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(tableLayoutObject, NS_ERROR_FAILURE);
 
   // Note that this returns NS_TABLELAYOUT_CELL_NOT_FOUND when
   //  the index(es) are out of bounds
   nsCOMPtr<nsIDOMElement> cell;
   res = tableLayoutObject->GetCellDataAt(aRowIndex, aColIndex,
                                          *getter_AddRefs(cell), 
                                          *aStartRowIndex, *aStartColIndex,
                                          *aRowSpan, *aColSpan, 
@@ -2839,17 +2839,17 @@ nsHTMLEditor::GetCellContext(nsISelectio
   if (aCellParent) *aCellParent = nsnull;
   if (aCellOffset) *aCellOffset = 0;
   if (aRowIndex) *aRowIndex = 0;
   if (aColIndex) *aColIndex = 0;
 
   nsCOMPtr <nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   if (aSelection)
   {
     *aSelection = selection.get();
     NS_ADDREF(*aSelection);
   }
   nsCOMPtr <nsIDOMElement> table;
   nsCOMPtr <nsIDOMElement> cell;
@@ -2891,17 +2891,17 @@ nsHTMLEditor::GetCellContext(nsISelectio
     *aCell = cell.get();
     NS_ADDREF(*aCell);
   }
 
   // Get containing table
   res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), cell, getter_AddRefs(table));
   NS_ENSURE_SUCCESS(res, res);
   // Cell must be in a table, so fail if not found
-  if (!table) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(table, NS_ERROR_FAILURE);
   if (aTable)
   {
     *aTable = table.get();
     NS_ADDREF(*aTable);
   }
 
   // Get the rest of the related data only if requested
   if (aRowIndex || aColIndex)
@@ -2915,54 +2915,54 @@ nsHTMLEditor::GetCellContext(nsISelectio
   }
   if (aCellParent)
   {
     nsCOMPtr <nsIDOMNode> cellParent;
     // Get the immediate parent of the cell
     res = cell->GetParentNode(getter_AddRefs(cellParent));
     NS_ENSURE_SUCCESS(res, res);
     // Cell has to have a parent, so fail if not found
-    if (!cellParent) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(cellParent, NS_ERROR_FAILURE);
 
     *aCellParent = cellParent.get();
     NS_ADDREF(*aCellParent);
 
     if (aCellOffset)
       res = GetChildOffset(cell, cellParent, *aCellOffset);
   }
 
   return res;
 }
 
 nsresult 
 nsHTMLEditor::GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell)
 {
   // Note: this might return a node that is outside of the range.
   // Use carefully.
-  if (!aRange || !aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRange && aCell, NS_ERROR_NULL_POINTER);
 
   *aCell = nsnull;
 
   nsCOMPtr<nsIDOMNode> startParent;
   nsresult res = aRange->GetStartContainer(getter_AddRefs(startParent));
   NS_ENSURE_SUCCESS(res, res);
-  if (!startParent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(startParent, NS_ERROR_FAILURE);
 
   PRInt32 startOffset;
   res = aRange->GetStartOffset(&startOffset);
   NS_ENSURE_SUCCESS(res, res);
 
   nsCOMPtr<nsIDOMNode> childNode = GetChildAt(startParent, startOffset);
   // This means selection is probably at a text node (or end of doc?)
-  if (!childNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(childNode, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMNode> endParent;
   res = aRange->GetEndContainer(getter_AddRefs(endParent));
   NS_ENSURE_SUCCESS(res, res);
-  if (!startParent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(startParent, NS_ERROR_FAILURE);
 
   PRInt32 endOffset;
   res = aRange->GetEndOffset(&endOffset);
   NS_ENSURE_SUCCESS(res, res);
   
   // If a cell is deleted, the range is collapse
   //   (startOffset == endOffset)
   //   so tell caller the cell wasn't found
@@ -2978,121 +2978,121 @@ nsHTMLEditor::GetCellFromRange(nsIDOMRan
     return NS_OK;
   }
   return NS_EDITOR_ELEMENT_NOT_FOUND;
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetFirstSelectedCell(nsIDOMRange **aRange, nsIDOMElement **aCell)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
   *aCell = nsnull;
   if (aRange) *aRange = nsnull;
 
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMRange> range;
   res = selection->GetRangeAt(0, getter_AddRefs(range));
   NS_ENSURE_SUCCESS(res, res);
-  if (!range) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
   mSelectedCellIndex = 0;
 
   res = GetCellFromRange(range, aCell);
   // Failure here probably means selection is in a text node,
   //  so there's no selected cell
   NS_ENSURE_SUCCESS(res, NS_EDITOR_ELEMENT_NOT_FOUND);
   // No cell means range was collapsed (cell was deleted)
-  if (!*aCell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(*aCell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   if (aRange)
   {
     *aRange = range.get();
     NS_ADDREF(*aRange);
   }
 
   // Setup for next cell
   mSelectedCellIndex = 1;
 
   return res;  
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::GetNextSelectedCell(nsIDOMRange **aRange, nsIDOMElement **aCell)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
   *aCell = nsnull;
   if (aRange) *aRange = nsnull;
 
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   PRInt32 rangeCount;
   res = selection->GetRangeCount(&rangeCount);
   NS_ENSURE_SUCCESS(res, res);
 
   // Don't even try if index exceeds range count
   if (mSelectedCellIndex >= rangeCount) 
     return NS_EDITOR_ELEMENT_NOT_FOUND;
 
   // Scan through ranges to find next valid selected cell
   nsCOMPtr<nsIDOMRange> range;
   for (; mSelectedCellIndex < rangeCount; mSelectedCellIndex++)
   {
     res = selection->GetRangeAt(mSelectedCellIndex, getter_AddRefs(range));
     NS_ENSURE_SUCCESS(res, res);
-    if (!range) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
     res = GetCellFromRange(range, aCell);
     // Failure here means the range doesn't contain a cell
     NS_ENSURE_SUCCESS(res, NS_EDITOR_ELEMENT_NOT_FOUND);
     
     // We found a selected cell
     if (*aCell) break;
 #ifdef DEBUG_cmanske
     else
       printf("GetNextSelectedCell: Collapsed range found\n");
 #endif
 
     // If we didn't find a cell, continue to next range in selection
   }
   // No cell means all remaining ranges were collapsed (cells were deleted)
-  if (!*aCell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(*aCell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   if (aRange)
   {
     *aRange = range.get();
     NS_ADDREF(*aRange);
   }
 
   // Setup for next cell
   mSelectedCellIndex++;
 
   return res;  
 }
 
 NS_IMETHODIMP 
 nsHTMLEditor::GetFirstSelectedCellInTable(PRInt32 *aRowIndex, PRInt32 *aColIndex, nsIDOMElement **aCell)
 {
-  if (!aCell) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
   *aCell = nsnull;
   if (aRowIndex)
     *aRowIndex = 0;
   if (aColIndex)
     *aColIndex = 0;
 
   nsCOMPtr<nsIDOMElement> cell;
   nsresult res = GetFirstSelectedCell(nsnull, getter_AddRefs(cell));
   NS_ENSURE_SUCCESS(res, res);
-  if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND;
+  NS_ENSURE_TRUE(cell, NS_EDITOR_ELEMENT_NOT_FOUND);
 
   *aCell = cell.get();
   NS_ADDREF(*aCell);
 
   // Also return the row and/or column if requested
   if (aRowIndex || aColIndex)
   {
     PRInt32 startRowIndex, startColIndex;
@@ -3108,17 +3108,17 @@ nsHTMLEditor::GetFirstSelectedCellInTabl
 
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::SetSelectionAfterTableEdit(nsIDOMElement* aTable, PRInt32 aRow, PRInt32 aCol, 
                                      PRInt32 aDirection, PRBool aSelected)
 {
-  if (!aTable) return NS_ERROR_NOT_INITIALIZED;
+  NS_ENSURE_TRUE(aTable, NS_ERROR_NOT_INITIALIZED);
 
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   
   if (!selection)
   {
 #ifdef DEBUG_cmanske
@@ -3209,17 +3209,17 @@ nsHTMLEditor::GetSelectedOrParentTableEl
   NS_ENSURE_ARG_POINTER(aSelectedCount);
   *aTableElement = nsnull;
   aTagName.Truncate();
   *aSelectedCount = 0;
 
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   // Try to get the first selected cell
   nsCOMPtr<nsIDOMElement> tableOrCellElement;
   res = GetFirstSelectedCell(nsnull, getter_AddRefs(tableOrCellElement));
   NS_ENSURE_SUCCESS(res, res);
 
   NS_NAMED_LITERAL_STRING(tdName, "td");
 
@@ -3231,17 +3231,17 @@ nsHTMLEditor::GetSelectedOrParentTableEl
       NS_ENSURE_SUCCESS(res, res);
       aTagName = tdName;
   }
   else
   {
     nsCOMPtr<nsIDOMNode> anchorNode;
     res = selection->GetAnchorNode(getter_AddRefs(anchorNode));
     if(NS_FAILED(res)) return res;
-    if (!anchorNode)  return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(anchorNode, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIDOMNode> selectedNode;
 
     // Get child of anchor node, if exists
     PRBool hasChildren;
     anchorNode->HasChildNodes(&hasChildren);
 
     if (hasChildren)
@@ -3380,63 +3380,63 @@ nsHTMLEditor::GetSelectedCellsType(nsIDO
     *aSelectionType = nsISelectionPrivate::TABLESELECTION_COLUMN;
 
   return NS_OK;
 }
 
 PRBool 
 nsHTMLEditor::AllCellsInRowSelected(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32 aNumberOfColumns)
 {
-  if (!aTable) return PR_FALSE;
+  NS_ENSURE_TRUE(aTable, PR_FALSE);
 
   PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
 
   for( PRInt32 col = 0; col < aNumberOfColumns; col += NS_MAX(actualColSpan, 1))
   {
     nsCOMPtr<nsIDOMElement> cell;    
     nsresult res = GetCellDataAt(aTable, aRowIndex, col, getter_AddRefs(cell),
                                  &curStartRowIndex, &curStartColIndex,
                                  &rowSpan, &colSpan,
                                  &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
-    if (!cell) return (col > 0) ? PR_TRUE : PR_FALSE;
+    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_ASSERTION((actualColSpan > 0),"ActualColSpan = 0 in AllCellsInRowSelected");
   }
   return PR_TRUE;
 }
 
 PRBool 
 nsHTMLEditor::AllCellsInColumnSelected(nsIDOMElement *aTable, PRInt32 aColIndex, PRInt32 aNumberOfRows)
 {
-  if (!aTable) return PR_FALSE;
+  NS_ENSURE_TRUE(aTable, PR_FALSE);
 
   PRInt32 curStartRowIndex, curStartColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan;
   PRBool  isSelected;
 
   for( PRInt32 row = 0; row < aNumberOfRows; row += NS_MAX(actualRowSpan, 1))
   {
     nsCOMPtr<nsIDOMElement> cell;    
     nsresult res = GetCellDataAt(aTable, row, aColIndex, getter_AddRefs(cell),
                                  &curStartRowIndex, &curStartColIndex,
                                  &rowSpan, &colSpan,
                                  &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
-    if (!cell) return (row > 0) ? PR_TRUE : PR_FALSE;
+    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;
   }
   return PR_TRUE;
 }
 
--- a/editor/libeditor/html/nsWSRunObject.cpp
+++ b/editor/libeditor/html/nsWSRunObject.cpp
@@ -446,17 +446,17 @@ nsWSRunObject::InsertText(const nsAStrin
 
 nsresult 
 nsWSRunObject::DeleteWSBackward()
 {
   nsresult res = NS_OK;
   WSPoint point;
   res = GetCharBefore(mNode, mOffset, &point);  
   NS_ENSURE_SUCCESS(res, res);
-  if (!point.mTextNode) return NS_OK;  // nothing to delete
+  NS_ENSURE_TRUE(point.mTextNode, NS_OK);  // nothing to delete
   
   if (mPRE)  // easy case, preformatted ws
   {
     if (nsCRT::IsAsciiSpace(point.mChar) || (point.mChar == nbsp))
     {
       nsCOMPtr<nsIDOMNode> node(do_QueryInterface(point.mTextNode));
       PRInt32 startOffset = point.mOffset;
       PRInt32 endOffset = point.mOffset+1;
@@ -501,17 +501,17 @@ nsWSRunObject::DeleteWSBackward()
 
 nsresult 
 nsWSRunObject::DeleteWSForward()
 {
   nsresult res = NS_OK;
   WSPoint point;
   res = GetCharAfter(mNode, mOffset, &point);  
   NS_ENSURE_SUCCESS(res, res);
-  if (!point.mTextNode) return NS_OK;  // nothing to delete
+  NS_ENSURE_TRUE(point.mTextNode, NS_OK);  // nothing to delete
   
   if (mPRE)  // easy case, preformatted ws
   {
     if (nsCRT::IsAsciiSpace(point.mChar) || (point.mChar == nbsp))
     {
       nsCOMPtr<nsIDOMNode> node(do_QueryInterface(point.mTextNode));
       PRInt32 startOffset = point.mOffset;
       PRInt32 endOffset = point.mOffset+1;
@@ -665,17 +665,17 @@ nsWSRunObject::NextVisibleNode (nsIDOMNo
 }
 
 nsresult 
 nsWSRunObject::AdjustWhitespace()
 {
   // this routine examines a run of ws and tries to get rid of some unneeded nbsp's,
   // replacing them with regualr ascii space if possible.  Keeping things simple
   // for now and just trying to fix up the trailing ws in the run.
-  if (!mLastNBSPNode) return NS_OK; // nothing to do!
+  NS_ENSURE_TRUE(mLastNBSPNode, NS_OK); // nothing to do!
   nsresult res = NS_OK;
   WSFragment *curRun = mStartRun;
   while (curRun)
   {
     // look for normal ws run
     if (curRun->mType == eNormalWS)
     {
       res = CheckTrailingNBSPOfRun(curRun);
@@ -1015,32 +1015,32 @@ nsWSRunObject::GetRuns()
       wstype = eLeadingWS;
     if (mEndReason & eBlock) 
       wstype |= eTrailingWS;
     return MakeSingleWSRun(wstype);
   }
   
   // otherwise a little trickier.  shucks.
   mStartRun = new WSFragment();
-  if (!mStartRun) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mStartRun, NS_ERROR_NULL_POINTER);
   mStartRun->mStartNode = mStartNode;
   mStartRun->mStartOffset = mStartOffset;
   
   if ( (mStartReason & eBlock) || (mStartReason == eBreak) )
   {
     // set up mStartRun
     mStartRun->mType = eLeadingWS;
     mStartRun->mEndNode = mFirstNBSPNode;
     mStartRun->mEndOffset = mFirstNBSPOffset;
     mStartRun->mLeftType = mStartReason;
     mStartRun->mRightType = eNormalWS;
     
     // set up next run
     WSFragment *normalRun = new WSFragment();
-    if (!normalRun) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(normalRun, NS_ERROR_NULL_POINTER);
     mStartRun->mRight = normalRun;
     normalRun->mType = eNormalWS;
     normalRun->mStartNode = mFirstNBSPNode;
     normalRun->mStartOffset = mFirstNBSPOffset;
     normalRun->mLeftType = eLeadingWS;
     normalRun->mLeft = mStartRun;
     if (mEndReason != eBlock)
     {
@@ -1067,17 +1067,17 @@ nsWSRunObject::GetRuns()
       else
       {
         normalRun->mEndNode = mLastNBSPNode;
         normalRun->mEndOffset = mLastNBSPOffset+1;
         normalRun->mRightType = eTrailingWS;
         
         // set up next run
         WSFragment *lastRun = new WSFragment();
-        if (!lastRun) return NS_ERROR_NULL_POINTER;
+        NS_ENSURE_TRUE(lastRun, NS_ERROR_NULL_POINTER);
         lastRun->mType = eTrailingWS;
         lastRun->mStartNode = mLastNBSPNode;
         lastRun->mStartOffset = mLastNBSPOffset+1;
         lastRun->mEndNode = mEndNode;
         lastRun->mEndOffset = mEndOffset;
         lastRun->mLeftType = eNormalWS;
         lastRun->mLeft = normalRun;
         lastRun->mRightType = mEndReason;
@@ -1104,17 +1104,17 @@ nsWSRunObject::GetRuns()
       mStartRun->mEndNode   = mEndNode;
       mStartRun->mEndOffset = mEndOffset;
       mEndRun = mStartRun;
     }
     else
     {
       // set up next run
       WSFragment *lastRun = new WSFragment();
-      if (!lastRun) return NS_ERROR_NULL_POINTER;
+      NS_ENSURE_TRUE(lastRun, NS_ERROR_NULL_POINTER);
       lastRun->mType = eTrailingWS;
       lastRun->mStartNode = mLastNBSPNode;
       lastRun->mStartOffset = mLastNBSPOffset+1;
       lastRun->mLeftType = eNormalWS;
       lastRun->mLeft = mStartRun;
       lastRun->mRightType = mEndReason;
       mEndRun = lastRun;
       mStartRun->mRight = lastRun;
@@ -1139,17 +1139,17 @@ nsWSRunObject::ClearRuns()
   mStartRun = 0;
   mEndRun = 0;
 }
 
 nsresult 
 nsWSRunObject::MakeSingleWSRun(PRInt16 aType)
 {
   mStartRun = new WSFragment();
-  if (!mStartRun) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(mStartRun, NS_ERROR_NULL_POINTER);
 
   mStartRun->mStartNode   = mStartNode;
   mStartRun->mStartOffset = mStartOffset;
   mStartRun->mType        = aType;
   mStartRun->mEndNode     = mEndNode;
   mStartRun->mEndOffset   = mEndOffset;
   mStartRun->mLeftType    = mStartReason;
   mStartRun->mRightType   = mEndReason;
@@ -1157,50 +1157,50 @@ nsWSRunObject::MakeSingleWSRun(PRInt16 a
   mEndRun  = mStartRun;
   
   return NS_OK;
 }
 
 nsresult 
 nsWSRunObject::PrependNodeToList(nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   if (!mNodeArray.InsertObjectAt(aNode, 0))
     return NS_ERROR_FAILURE;
   return NS_OK;
 }
 
 nsresult 
 nsWSRunObject::AppendNodeToList(nsIDOMNode *aNode)
 {
-  if (!aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
   if (!mNodeArray.AppendObject(aNode))
     return NS_ERROR_FAILURE;
   return NS_OK;
 }
 
 nsresult 
 nsWSRunObject::GetPreviousWSNode(nsIDOMNode *aStartNode, 
                                  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);
   
   nsresult res = aStartNode->GetPreviousSibling(getter_AddRefs(*aPriorNode));
   NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsIDOMNode> temp, curNode = aStartNode;
   while (!*aPriorNode)
   {
     // we have exhausted nodes in parent of aStartNode.
     res = curNode->GetParentNode(getter_AddRefs(temp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!temp) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(temp, NS_ERROR_NULL_POINTER);
     if (temp == aBlockParent)
     {
       // we have exhausted nodes in the block parent.  The convention here is to return null.
       *aPriorNode = nsnull;
       return NS_OK;
     }
     // we have a parent: look for previous sibling
     res = temp->GetPreviousSibling(getter_AddRefs(*aPriorNode));
@@ -1300,17 +1300,17 @@ nsWSRunObject::GetNextWSNode(nsIDOMNode 
   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.
     res = curNode->GetParentNode(getter_AddRefs(temp));
     NS_ENSURE_SUCCESS(res, res);
-    if (!temp) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(temp, NS_ERROR_NULL_POINTER);
     if (temp == aBlockParent)
     {
       // we have exhausted nodes in the block parent.  The convention
       // here is to return null.
       *aNextNode = nsnull;
       return NS_OK;
     }
     // we have a parent: look for next sibling
@@ -1603,17 +1603,17 @@ nsWSRunObject::DeleteChars(nsIDOMNode *a
       }
       break;
     }
     else
     {
       if (!range)
       {
         range = do_CreateInstance("@mozilla.org/content/range;1");
-        if (!range) return NS_ERROR_OUT_OF_MEMORY;
+        NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY);
         res = range->SetStart(aStartNode, aStartOffset);
         NS_ENSURE_SUCCESS(res, res);
         res = range->SetEnd(aEndNode, aEndOffset);
         NS_ENSURE_SUCCESS(res, res);
       }
       PRBool nodeBefore, nodeAfter;
       nsCOMPtr<nsIContent> content (do_QueryInterface(node));
       res = mHTMLEditor->sRangeHelper->CompareNodeToRange(content, range, &nodeBefore, &nodeAfter);
@@ -1698,17 +1698,17 @@ nsWSRunObject::GetCharAfter(WSPoint &aPo
   if (PRUint16(aPoint.mOffset) < aPoint.mTextNode->TextLength())
   {
     *outPoint = aPoint;
     outPoint->mChar = GetCharAt(aPoint.mTextNode, aPoint.mOffset);
   }
   else if (idx < (PRInt32)(numNodes-1))
   {
     nsIDOMNode* node = mNodeArray[idx+1];
-    if (!node) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
     outPoint->mTextNode = do_QueryInterface(node);
     if (!outPoint->mTextNode->IsNodeOfType(nsINode::eDATA_NODE)) {
       // Not sure if this is needed, but it'll maintain the same
       // functionality
       outPoint->mTextNode = nsnull;
     }
     outPoint->mOffset = 0;
     outPoint->mChar = GetCharAt(outPoint->mTextNode, 0);
@@ -1734,17 +1734,17 @@ nsWSRunObject::GetCharBefore(WSPoint &aP
   {
     *outPoint = aPoint;
     outPoint->mOffset--;
     outPoint->mChar = GetCharAt(aPoint.mTextNode, aPoint.mOffset-1);
   }
   else if (idx)
   {
     nsIDOMNode* node = mNodeArray[idx-1];
-    if (!node) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
     outPoint->mTextNode = do_QueryInterface(node);
 
     PRUint32 len = outPoint->mTextNode->TextLength();
 
     if (len)
     {
       outPoint->mOffset = len-1;
       outPoint->mChar = GetCharAt(outPoint->mTextNode, len-1);
@@ -2049,17 +2049,17 @@ nsWSRunObject::GetWSPointBefore(nsIDOMNo
   }
 }
 
 nsresult
 nsWSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
 {    
   // try to change an nbsp to a space, if possible, just to prevent nbsp proliferation. 
   // examine what is before and after the trailing nbsp, if any.
-  if (!aRun) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRun, NS_ERROR_NULL_POINTER);
   WSPoint thePoint;
   PRBool leftCheck = PR_FALSE;
   PRBool spaceNBSP = PR_FALSE;
   PRBool rightCheck = PR_FALSE;
   
   // confirm run is normalWS
   if (aRun->mType != eNormalWS) return NS_ERROR_FAILURE;
   
@@ -2165,17 +2165,17 @@ nsWSRunObject::CheckTrailingNBSPOfRun(WS
 
 nsresult
 nsWSRunObject::CheckTrailingNBSP(WSFragment *aRun, nsIDOMNode *aNode, PRInt32 aOffset)
 {    
   // try to change an nbsp to a space, if possible, just to prevent nbsp proliferation. 
   // this routine is called when we about to make this point in the ws abut an inserted break
   // or text, so we don't have to worry about what is after it.  What is after it now will 
   // end up after the inserted object.   
-  if (!aRun || !aNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRun && aNode, NS_ERROR_NULL_POINTER);
   WSPoint thePoint;
   PRBool canConvert = PR_FALSE;
   nsresult res = GetCharBefore(aNode, aOffset, &thePoint);
   if (NS_SUCCEEDED(res) && thePoint.mTextNode && thePoint.mChar == nbsp)
   {
     WSPoint prevPoint;
     res = GetCharBefore(thePoint, &prevPoint);
     if (NS_SUCCEEDED(res) && prevPoint.mTextNode)
--- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp
@@ -157,57 +157,57 @@ NS_IMETHODIMP nsPlaintextEditor::InsertF
   
   nsresult rv;
   nsCOMPtr<nsIDragService> dragService = 
            do_GetService("@mozilla.org/widget/dragservice;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDragSession> dragSession;
   dragService->GetCurrentSession(getter_AddRefs(dragSession));
-  if (!dragSession) return NS_OK;
+  NS_ENSURE_TRUE(dragSession, NS_OK);
 
   // Current doc is destination
   nsCOMPtr<nsIDOMDocument> destdomdoc; 
   rv = GetDocument(getter_AddRefs(destdomdoc)); 
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Get the nsITransferable interface for getting the data from the drop
   nsCOMPtr<nsITransferable> trans;
   rv = PrepareTransferable(getter_AddRefs(trans));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!trans) return NS_OK;  // NS_ERROR_FAILURE; SHOULD WE FAIL?
+  NS_ENSURE_TRUE(trans, NS_OK);  // NS_ERROR_FAILURE; SHOULD WE FAIL?
 
   PRUint32 numItems = 0; 
   rv = dragSession->GetNumDropItems(&numItems);
   NS_ENSURE_SUCCESS(rv, rv);
   if (numItems < 1) return NS_ERROR_FAILURE;  // nothing to drop?
 
   // Combine any deletion and drop insertion into one transaction
   nsAutoEditBatch beginBatching(this);
 
   PRBool deleteSelection = PR_FALSE;
 
   // We have to figure out whether to delete and relocate caret only once
   // Parent and offset are under the mouse cursor
   nsCOMPtr<nsIDOMNSUIEvent> nsuiEvent (do_QueryInterface(aDropEvent));
-  if (!nsuiEvent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(nsuiEvent, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMNode> newSelectionParent;
   rv = nsuiEvent->GetRangeParent(getter_AddRefs(newSelectionParent));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!newSelectionParent) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(newSelectionParent, NS_ERROR_FAILURE);
 
   PRInt32 newSelectionOffset;
   rv = nsuiEvent->GetRangeOffset(&newSelectionOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISelection> selection;
   rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!selection) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
   PRBool isCollapsed;
   rv = selection->GetIsCollapsed(&isCollapsed);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Check if mouse is in the selection
   // if so, jump through some hoops to determine if mouse is over selection (bail)
   // and whether user wants to copy selection or delete it
@@ -285,17 +285,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertF
     content = content->GetParent();
   }
 
   PRUint32 i; 
   for (i = 0; i < numItems; ++i)
   {
     rv = dragSession->GetData(trans, i);
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!trans) return NS_OK; // NS_ERROR_FAILURE; Should we fail?
+    NS_ENSURE_TRUE(trans, NS_OK); // NS_ERROR_FAILURE; Should we fail?
 
     // Beware! This may flush notifications via synchronous
     // ScrollSelectionIntoView.
     rv = InsertTextFromTransferable(trans, newSelectionParent, newSelectionOffset, deleteSelection);
   }
 
   return rv;
 }
@@ -356,17 +356,17 @@ NS_IMETHODIMP nsPlaintextEditor::CanDrag
 
 NS_IMETHODIMP nsPlaintextEditor::DoDrag(nsIDOMEvent *aDragEvent)
 {
   nsresult rv;
 
   nsCOMPtr<nsITransferable> trans;
   rv = PutDragDataInTransferable(getter_AddRefs(trans));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!trans) return NS_OK; // maybe there was nothing to copy?
+  NS_ENSURE_TRUE(trans, NS_OK); // maybe there was nothing to copy?
 
  /* 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;
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -327,17 +327,17 @@ nsPlaintextEditor::SetDocumentCharacterS
 } 
 
 
 NS_IMETHODIMP nsPlaintextEditor::InitRules()
 {
   // instantiate the rules for this text editor
   nsresult res = NS_NewTextEditRules(getter_AddRefs(mRules));
   NS_ENSURE_SUCCESS(res, res);
-  if (!mRules) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(mRules, NS_ERROR_UNEXPECTED);
   return mRules->Init(this);
 }
 
 
 NS_IMETHODIMP
 nsPlaintextEditor::GetIsDocumentEditable(PRBool *aIsDocumentEditable)
 {
   NS_ENSURE_ARG_POINTER(aIsDocumentEditable);
@@ -447,34 +447,34 @@ NS_IMETHODIMP nsPlaintextEditor::TypedTe
         return InsertLineBreak();
       } 
   } 
   return NS_ERROR_FAILURE; 
 }
 
 NS_IMETHODIMP nsPlaintextEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect)
 {
-  if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_SUCCESS(aInOutParent && *aInOutParent && aInOutOffset && outBRNode, NS_ERROR_NULL_POINTER);
   *outBRNode = nsnull;
   nsresult res;
   
   // we need to insert a br.  unfortunately, we may have to split a text node to do it.
   nsCOMPtr<nsIDOMNode> node = *aInOutParent;
   PRInt32 theOffset = *aInOutOffset;
   nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(node);
   NS_NAMED_LITERAL_STRING(brType, "br");
   nsCOMPtr<nsIDOMNode> brNode;
   if (nodeAsText)  
   {
     nsCOMPtr<nsIDOMNode> tmp;
     PRInt32 offset;
     PRUint32 len;
     nodeAsText->GetLength(&len);
     GetNodeLocation(node, address_of(tmp), &offset);
-    if (!tmp) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
     if (!theOffset)
     {
       // we are already set to go
     }
     else if (theOffset == (PRInt32)len)
     {
       // update offset to point AFTER the text node
       offset++;
@@ -533,17 +533,17 @@ NS_IMETHODIMP nsPlaintextEditor::CreateB
 {
   nsCOMPtr<nsIDOMNode> parent = aNode;
   PRInt32 offset = aOffset;
   return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
 }
 
 NS_IMETHODIMP nsPlaintextEditor::InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode)
 {
-  if (!outBRNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(outBRNode, NS_ERROR_NULL_POINTER);
   *outBRNode = nsnull;
 
   // calling it text insertion to trigger moz br treatment by rules
   nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);
 
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
@@ -744,17 +744,17 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteS
   // delete placeholder txns merge.
   nsAutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
   nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction);
 
   // pre-process
   nsCOMPtr<nsISelection> selection;
   result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // If there is an existing selection when an extended delete is requested,
   //  platforms that use "caret-style" caret positioning collapse the
   //  selection to the  start and then create a new selection.
   //  Platforms that use "selection-style" caret positioning just delete the
   //  existing selection without extending it.
   PRBool bCollapsed;
   result  = selection->GetIsCollapsed(&bCollapsed);
@@ -808,17 +808,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertT
   }
   nsAutoPlaceHolderBatch batch(this, nsnull); 
   nsAutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
 
   // pre-process
   nsCOMPtr<nsISelection> selection;
   nsresult result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsAutoString resultString;
   // XXX can we trust instring to outlive ruleInfo,
   // XXX and ruleInfo not to refer to instring in its dtor?
   //nsAutoString instring(aStringToInsert);
   nsTextRulesInfo ruleInfo(theAction);
   ruleInfo.inString = &aStringToInsert;
   ruleInfo.outString = &resultString;
   ruleInfo.maxLength = mMaxTextLength;
@@ -848,17 +848,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertL
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertBreak, nsIEditor::eNext);
 
   // pre-process
   nsCOMPtr<nsISelection> selection;
   nsresult res;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // Batching the selection and moving nodes out from under the caret causes
   // caret turds. Ask the shell to invalidate the caret now to avoid the turds.
   nsCOMPtr<nsIPresShell> shell;
   res = GetPresShell(getter_AddRefs(shell));
   NS_ENSURE_SUCCESS(res, res);
   shell->MaybeInvalidateCaretPosition();
 
@@ -1278,17 +1278,17 @@ NS_IMETHODIMP
 nsPlaintextEditor::GetAndInitDocEncoder(const nsAString& aFormatType,
                                         PRUint32 aFlags,
                                         const nsACString& aCharset,
                                         nsIDocumentEncoder** encoder)
 {
   nsCOMPtr<nsIPresShell> presShell;
   nsresult rv = GetPresShell(getter_AddRefs(presShell));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!presShell) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
   formatType.AppendWithConversion(aFormatType);
   nsCOMPtr<nsIDocumentEncoder> docEncoder (do_CreateInstance(formatType.get(), &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsIDocument *doc = presShell->GetDocument();
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
@@ -1487,17 +1487,17 @@ nsPlaintextEditor::InsertAsQuotation(con
   // written without thinking won't be so ugly.
   if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != PRUnichar('\n')))
     quotedStuff.Append(PRUnichar('\n'));
 
   // get selection
   nsCOMPtr<nsISelection> selection;
   rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!selection) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement);
   PRBool cancel, handled;
   rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
@@ -1574,17 +1574,17 @@ nsPlaintextEditor::Rewrap(PRBool aRespec
   PRBool isCollapsed;
   rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted
                           | nsIDocumentEncoder::OutputLFLineBreak,
                           &isCollapsed, current);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsICiter> citer = new nsInternetCiter();
   NS_ENSURE_SUCCESS(rv, rv);
-  if (!citer) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(citer, NS_ERROR_UNEXPECTED);
 
   nsString wrapped;
   PRUint32 firstLineOffset = 0;   // XXX need to reset this if there is a selection
   rv = citer->Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines,
                      wrapped);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (isCollapsed)    // rewrap the whole document
@@ -1602,17 +1602,17 @@ nsPlaintextEditor::StripCites()
 
   nsAutoString current;
   PRBool isCollapsed;
   nsresult rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted,
                                    &isCollapsed, current);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsICiter> citer = new nsInternetCiter();
-  if (!citer) return NS_ERROR_UNEXPECTED;
+  NS_ENSURE_TRUE(citer, NS_ERROR_UNEXPECTED);
 
   nsString stripped;
   rv = citer->StripCites(current, stripped);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (isCollapsed)    // rewrap the whole document
   {
     rv = SelectAll();
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -170,22 +170,22 @@ nsTextEditRules::Init(nsPlaintextEditor 
     NS_ENSURE_SUCCESS(res, res);
   }
 
   if (body)
   {
     // create a range that is the entire body contents
     nsCOMPtr<nsIDOMRange> wholeDoc =
       do_CreateInstance("@mozilla.org/content/range;1");
-    if (!wholeDoc) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(wholeDoc, NS_ERROR_NULL_POINTER);
     wholeDoc->SetStart(body,0);
     nsCOMPtr<nsIDOMNodeList> list;
     res = body->GetChildNodes(getter_AddRefs(list));
     NS_ENSURE_SUCCESS(res, res);
-    if (!list) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(list, NS_ERROR_FAILURE);
 
     PRUint32 listCount;
     res = list->GetLength(&listCount);
     NS_ENSURE_SUCCESS(res, res);
 
     res = wholeDoc->SetEnd(body, listCount);
     NS_ENSURE_SUCCESS(res, res);
 
@@ -478,17 +478,17 @@ nsTextEditRules::DidInsertBreak(nsISelec
   nsresult res;
   res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   // confirm we are at end of document
   if (selOffset == 0) return NS_OK;  // can't be after a br if we are at offset 0
   nsIDOMElement *rootElem = mEditor->GetRoot();
 
   nsCOMPtr<nsIDOMNode> root = do_QueryInterface(rootElem);
-  if (!root) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER);
   if (selNode != root) return NS_OK; // must be inside text node or somewhere other than end of root
 
   nsCOMPtr<nsIDOMNode> temp = mEditor->GetChildAt(selNode, selOffset);
   if (temp) return NS_OK; // can't be at end if there is a node after us.
 
   nsCOMPtr<nsIDOMNode> nearNode = mEditor->GetChildAt(selNode, selOffset-1);
   if (nearNode && nsTextEditUtils::IsBreak(nearNode) && !nsTextEditUtils::IsMozBR(nearNode))
   {
@@ -514,17 +514,17 @@ GetTextNode(nsISelection *selection, nsE
   PRInt32 selOffset;
   nsCOMPtr<nsIDOMNode> selNode;
   nsresult res = editor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, nsnull);
   if (!editor->IsTextNode(selNode)) {
     // Get an nsINode from the nsIDOMNode
     nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
     // if node is null, return it to indicate there's no text
-    if (!node) return nsnull;
+    NS_ENSURE_TRUE(node, nsnull);
     // This should be the root node, walk the tree looking for text nodes
     nsNodeIterator iter(node, nsIDOMNodeFilter::SHOW_TEXT, nsnull, PR_TRUE);
     while (!editor->IsTextNode(selNode)) {
       if (NS_FAILED(res = iter.NextNode(getter_AddRefs(selNode))) || !selNode) {
         return nsnull;
       }
     }
   }
@@ -737,17 +737,17 @@ nsTextEditRules::WillInsertText(PRInt32 
   // don't put text in places that can't have it
   if (!mEditor->IsTextNode(selNode) && !mEditor->CanContainTag(selNode, NS_LITERAL_STRING("#text")))
     return NS_ERROR_FAILURE;
 
   // we need to get the doc
   nsCOMPtr<nsIDOMDocument>doc;
   res = mEditor->GetDocument(getter_AddRefs(doc));
   NS_ENSURE_SUCCESS(res, res);
-  if (!doc) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);
     
   if (aAction == kInsertTextIME) 
   { 
     res = mEditor->InsertTextImpl(*outString, address_of(selNode), &selOffset, doc);
     NS_ENSURE_SUCCESS(res, res);
   }
   else // aAction == kInsertText
   {
@@ -1002,23 +1002,23 @@ nsTextEditRules::WillDeleteSelection(nsI
     }
   }
   else
   {
     nsCOMPtr<nsIDOMNode> startNode;
     PRInt32 startOffset;
     res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
     NS_ENSURE_SUCCESS(res, res);
-    if (!startNode) return NS_ERROR_FAILURE;
+    NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
     
     PRBool bCollapsed;
     res = aSelection->GetIsCollapsed(&bCollapsed);
     NS_ENSURE_SUCCESS(res, res);
   
-    if (!bCollapsed) return NS_OK;
+    NS_ENSURE_TRUE(bCollapsed, NS_OK);
 
     // Test for distance between caret and text that will be deleted
     res = CheckBidiLevelForDeletion(aSelection, startNode, startOffset, aCollapsedAction, aCancel);
     NS_ENSURE_SUCCESS(res, res);
     if (*aCancel) return NS_OK;
 
     res = mEditor->ExtendSelectionForDelete(aSelection, &aCollapsedAction);
     NS_ENSURE_SUCCESS(res, res);
@@ -1036,17 +1036,17 @@ nsresult
 nsTextEditRules::DidDeleteSelection(nsISelection *aSelection, 
                                     nsIEditor::EDirection aCollapsedAction, 
                                     nsresult aResult)
 {
   nsCOMPtr<nsIDOMNode> startNode;
   PRInt32 startOffset;
   nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
-  if (!startNode) return NS_ERROR_FAILURE;
+  NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
   
   // delete empty text nodes at selection
   if (mEditor->IsTextNode(startNode))
   {
     nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(startNode);
     PRUint32 strLength;
     res = textNode->GetLength(&strLength);
     NS_ENSURE_SUCCESS(res, res);
@@ -1092,17 +1092,17 @@ nsTextEditRules:: DidUndo(nsISelection *
   if (NS_SUCCEEDED(res)) 
   {
     if (mBogusNode) {
       mBogusNode = nsnull;
     }
     else
     {
       nsIDOMElement *theRoot = mEditor->GetRoot();
-      if (!theRoot) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(theRoot, NS_ERROR_FAILURE);
       nsCOMPtr<nsIDOMNode> node = mEditor->GetLeftmostChild(theRoot);
       if (node && mEditor->IsMozEditorBogusNode(node))
         mBogusNode = node;
     }
   }
   return res;
 }
 
@@ -1125,31 +1125,31 @@ nsTextEditRules::DidRedo(nsISelection *a
   if (NS_SUCCEEDED(res)) 
   {
     if (mBogusNode) {
       mBogusNode = nsnull;
     }
     else
     {
       nsIDOMElement *theRoot = mEditor->GetRoot();
-      if (!theRoot) return NS_ERROR_FAILURE;
+      NS_ENSURE_TRUE(theRoot, NS_ERROR_FAILURE);
       
       nsCOMPtr<nsIDOMNodeList> nodeList;
       res = theRoot->GetElementsByTagName(NS_LITERAL_STRING("br"),
                                           getter_AddRefs(nodeList));
       NS_ENSURE_SUCCESS(res, res);
       if (nodeList)
       {
         PRUint32 len;
         nodeList->GetLength(&len);
         
         if (len != 1) return NS_OK;  // only in the case of one br could there be the bogus node
         nsCOMPtr<nsIDOMNode> node;
         nodeList->Item(0, getter_AddRefs(node));
-        if (!node) return NS_ERROR_NULL_POINTER;
+        NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
         if (mEditor->IsMozEditorBogusNode(node))
           mBogusNode = node;
       }
     }
   }
   return res;
 }
 
@@ -1190,17 +1190,17 @@ nsresult
 nsTextEditRules::DidOutputText(nsISelection *aSelection, nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
 nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange)
 {
-  if (!aRange) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(aRange, NS_ERROR_NULL_POINTER);
   
   // convert any newlines in editable, preformatted text nodes 
   // into normal breaks.  this is because layout won't give us a place 
   // to put the cursor on empty lines otherwise.
 
   nsresult res;
   nsCOMPtr<nsIContentIterator> iter =
        do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res);
@@ -1253,17 +1253,17 @@ nsTextEditRules::ReplaceNewlines(nsIDOMR
       // delete the newline
       nsRefPtr<DeleteTextTxn> txn;
       // note 1: we are not telling edit listeners about these because they don't care
       // note 2: we are not wrapping these in a placeholder because we know they already are,
       //         or, failing that, undo is disabled
       res = mEditor->CreateTxnForDeleteText(textNode, offset, 1,
                                             getter_AddRefs(txn));
       NS_ENSURE_SUCCESS(res, res); 
-      if (!txn)  return NS_ERROR_OUT_OF_MEMORY;
+      NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY);
       res = mEditor->DoTransaction(txn); 
       NS_ENSURE_SUCCESS(res, res); 
       
       // insert a break
       res = mEditor->CreateBR(textNode, offset, address_of(brNode));
       NS_ENSURE_SUCCESS(res, res);
     } while (1);  // break used to exit while loop
   }
@@ -1278,17 +1278,17 @@ nsTextEditRules::CreateTrailingBRIfNeede
     return NS_OK;
   nsIDOMNode *body = mEditor->GetRoot();
   if (!body)
     return 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);  
-  if (!lastChild) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(lastChild, NS_ERROR_NULL_POINTER);
 
   if (!nsTextEditUtils::IsBreak(lastChild))
   {
     nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);
     PRUint32 rootLen;
     res = mEditor->GetLengthOfDOMNode(body, rootLen);
     NS_ENSURE_SUCCESS(res, res); 
     nsCOMPtr<nsIDOMNode> unused;
@@ -1340,17 +1340,17 @@ nsTextEditRules::CreateBogusNodeIfNeeded
     // create a br
     nsCOMPtr<nsIContent> newContent;
     res = mEditor->CreateHTMLContent(NS_LITERAL_STRING("br"), getter_AddRefs(newContent));
     NS_ENSURE_SUCCESS(res, res);
     nsCOMPtr<nsIDOMElement>brElement = do_QueryInterface(newContent);
 
     // set mBogusNode to be the newly created <br>
     mBogusNode = brElement;
-    if (!mBogusNode) return NS_ERROR_NULL_POINTER;
+    NS_ENSURE_TRUE(mBogusNode, NS_ERROR_NULL_POINTER);
 
     // give it a special attribute
     newContent->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
                         kMOZEditorBogusNodeValue, PR_FALSE);
     
     // put the node in the document
     res = mEditor->InsertNode(mBogusNode, body, 0);
     NS_ENSURE_SUCCESS(res, res);
@@ -1507,17 +1507,17 @@ nsTextEditRules::FillBufWithPWChars(nsAS
 
 
 ///////////////////////////////////////////////////////////////////////////
 // CreateMozBR: put a BR node with moz attribute at {aNode, aOffset}
 //                       
 nsresult 
 nsTextEditRules::CreateMozBR(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outBRNode)
 {
-  if (!inParent || !outBRNode) return NS_ERROR_NULL_POINTER;
+  NS_ENSURE_TRUE(inParent && outBRNode, NS_ERROR_NULL_POINTER);
 
   nsresult res = mEditor->CreateBR(inParent, inOffset, outBRNode);
   NS_ENSURE_SUCCESS(res, res);
 
   // give it special moz attr
   nsCOMPtr<nsIDOMElement> brElem = do_QueryInterface(*outBRNode);
   if (brElem)
   {