Cleanup implementations of QueryInterface. b=385750 r+sr=dbaron r+sr=jst
authormats.palmgren@bredband.net
Tue, 03 Jul 2007 19:15:31 -0700
changeset 3114 106d78ed483e626aab3fc326fef196e1eedee354
parent 3113 a5ac43ff901aa97a5f69d2ca37acc4a646ab748e
child 3115 060a737183b969afaa16afd1ecff5037f1c66c71
push idunknown
push userunknown
push dateunknown
bugs385750
milestone1.9a7pre
Cleanup implementations of QueryInterface. b=385750 r+sr=dbaron r+sr=jst
content/base/src/nsGenericElement.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsGenericHTMLElement.h
content/xml/content/src/nsXMLElement.cpp
content/xtf/src/nsXTFElementWrapper.cpp
content/xtf/src/nsXTFInterfaceAggregator.cpp
content/xtf/src/nsXTFWeakTearoff.cpp
content/xul/content/src/nsXULElement.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsFileControlFrame.cpp
layout/forms/nsFormControlFrame.cpp
layout/forms/nsGfxButtonControlFrame.cpp
layout/forms/nsGfxCheckboxControlFrame.cpp
layout/forms/nsGfxRadioControlFrame.cpp
layout/forms/nsHTMLButtonControlFrame.cpp
layout/forms/nsImageControlFrame.cpp
layout/forms/nsIsIndexFrame.cpp
layout/forms/nsLegendFrame.cpp
layout/forms/nsListControlFrame.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsFrameFrame.cpp
layout/generic/nsFrameSetFrame.cpp
layout/generic/nsHTMLFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsInlineFrame.cpp
layout/generic/nsObjectFrame.cpp
layout/generic/nsSimplePageSequence.cpp
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableFrame.cpp
layout/tables/nsTableOuterFrame.cpp
layout/tables/nsTableRowGroupFrame.cpp
layout/xul/base/src/nsMenuBoxObject.cpp
layout/xul/base/src/nsScrollbarButtonFrame.cpp
widget/src/beos/nsDeviceContextSpecB.cpp
widget/src/os2/nsDeviceContextSpecOS2.cpp
widget/src/windows/nsWindow.cpp
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -3379,17 +3379,18 @@ nsresult
 nsGenericElement::PostQueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
   nsIDocument *document = GetOwnerDoc();
   if (document) {
     return document->BindingManager()->GetBindingImplementation(this, aIID,
                                                                 aInstancePtr);
   }
 
-  return NS_NOINTERFACE;
+  *aInstancePtr = nsnull;
+  return NS_ERROR_NO_INTERFACE;
 }
 
 //----------------------------------------------------------------------
 nsresult
 nsGenericElement::LeaveLink(nsPresContext* aPresContext)
 {
   nsILinkHandler *handler = aPresContext->GetLinkHandler();
   if (!handler) {
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -220,34 +220,43 @@ static nsICSSOMFactory* gCSSOMFactory = 
 static NS_DEFINE_CID(kCSSOMFactoryCID, NS_CSSOMFACTORY_CID);
 
 NS_IMPL_INT_ATTR(nsGenericHTMLElement, TabIndex, tabindex)
 
 nsresult
 nsGenericHTMLElement::DOMQueryInterface(nsIDOMHTMLElement *aElement,
                                         REFNSIID aIID, void **aInstancePtr)
 {
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   nsISupports *inst = nsnull;
 
   if (aIID.Equals(NS_GET_IID(nsIDOMNode))) {
     inst = NS_STATIC_CAST(nsIDOMNode *, aElement);
   } else if (aIID.Equals(NS_GET_IID(nsIDOMElement))) {
     inst = NS_STATIC_CAST(nsIDOMElement *, aElement);
   } else if (aIID.Equals(NS_GET_IID(nsIDOMHTMLElement))) {
     inst = NS_STATIC_CAST(nsIDOMHTMLElement *, aElement);
   } else if (aIID.Equals(NS_GET_IID(nsIDOMNSHTMLElement))) {
     inst = NS_STATIC_CAST(nsIDOMNSHTMLElement *,
                           new nsGenericHTMLElementTearoff(this));
-    NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
+    if (NS_UNLIKELY(!inst)) {
+      *aInstancePtr = nsnull;
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
   } else if (aIID.Equals(NS_GET_IID(nsIDOMElementCSSInlineStyle))) {
     inst = NS_STATIC_CAST(nsIDOMElementCSSInlineStyle *,
                           new nsGenericHTMLElementTearoff(this));
-    NS_ENSURE_TRUE(inst, NS_ERROR_OUT_OF_MEMORY);
+    if (NS_UNLIKELY(!inst)) {
+      *aInstancePtr = nsnull;
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
   } else {
-    return NS_NOINTERFACE;
+    *aInstancePtr = nsnull;
+    return NS_ERROR_NO_INTERFACE;
   }
 
   NS_ADDREF(inst);
 
   *aInstancePtr = inst;
 
   return NS_OK;
 }
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -1089,19 +1089,17 @@ NS_NewHTML##_elementName##Element(nsINod
 
 /**
  * QueryInterface() implementation helper macros
  */
 
 #define NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(_class, _base, _base_if) \
   NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr)    \
   {                                                                           \
-    NS_ENSURE_ARG_POINTER(aInstancePtr);                                      \
-                                                                              \
-    *aInstancePtr = nsnull;                                                   \
+    NS_PRECONDITION(aInstancePtr, "null out param");                          \
                                                                               \
     nsresult rv;                                                              \
                                                                               \
     rv = _base::QueryInterface(aIID, aInstancePtr);                           \
                                                                               \
     if (NS_SUCCEEDED(rv))                                                     \
       return rv;                                                              \
                                                                               \
@@ -1117,25 +1115,23 @@ NS_NewHTML##_elementName##Element(nsINod
 #define NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(_class, _base)                    \
   NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(_class, _base,                 \
                                                nsIDOMHTMLElement)
 
 #define NS_HTML_CONTENT_CC_INTERFACE_MAP_AMBIGUOUS_BEGIN(_class, _base,       \
                                                         _base_if)             \
   NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr)    \
   {                                                                           \
-    NS_ENSURE_ARG_POINTER(aInstancePtr);                                      \
+    NS_PRECONDITION(aInstancePtr, "null out param");                          \
                                                                               \
     if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) {       \
       *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(_class);                      \
       return NS_OK;                                                           \
     }                                                                         \
                                                                               \
-    *aInstancePtr = nsnull;                                                   \
-                                                                              \
     nsresult rv;                                                              \
                                                                               \
     rv = _base::QueryInterface(aIID, aInstancePtr);                           \
                                                                               \
     if (NS_SUCCEEDED(rv))                                                     \
       return rv;                                                              \
                                                                               \
     rv = DOMQueryInterface(NS_STATIC_CAST(_base_if *, this), aIID,            \
--- a/content/xml/content/src/nsXMLElement.cpp
+++ b/content/xml/content/src/nsXMLElement.cpp
@@ -62,18 +62,17 @@ nsXMLElement::nsXMLElement(nsINodeInfo *
 {
 }
 
 
 // QueryInterface implementation for nsXMLElement
 NS_IMETHODIMP 
 nsXMLElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  NS_ENSURE_ARG_POINTER(aInstancePtr);
-  *aInstancePtr = nsnull;
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   nsresult rv = nsGenericElement::QueryInterface(aIID, aInstancePtr);
 
   if (NS_SUCCEEDED(rv))
     return rv;
 
   nsISupports *inst = nsnull;
 
--- a/content/xtf/src/nsXTFElementWrapper.cpp
+++ b/content/xtf/src/nsXTFElementWrapper.cpp
@@ -105,43 +105,44 @@ nsXTFElementWrapper::Init()
 // nsISupports implementation
 
 NS_IMPL_ADDREF_INHERITED(nsXTFElementWrapper,nsXTFElementWrapperBase)
 NS_IMPL_RELEASE_INHERITED(nsXTFElementWrapper,nsXTFElementWrapperBase)
 
 NS_IMETHODIMP
 nsXTFElementWrapper::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  nsresult rv;
-  
-  if(aIID.Equals(NS_GET_IID(nsIClassInfo))) {
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
+  if (aIID.Equals(NS_GET_IID(nsIClassInfo))) {
     *aInstancePtr = NS_STATIC_CAST(nsIClassInfo*, this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
-  else if(aIID.Equals(NS_GET_IID(nsIXTFElementWrapper))) {
+  if (aIID.Equals(NS_GET_IID(nsIXTFElementWrapper))) {
     *aInstancePtr = NS_STATIC_CAST(nsIXTFElementWrapper*, this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
-  else if (NS_SUCCEEDED(rv = nsXTFElementWrapperBase::QueryInterface(aIID, aInstancePtr))) {
+
+  nsresult rv = nsXTFElementWrapperBase::QueryInterface(aIID, aInstancePtr);
+  if (NS_SUCCEEDED(rv)) {
     return rv;
   }
-  else {
-    // try to get get the interface from our wrapped element:
-    nsCOMPtr<nsISupports> inner;
-    QueryInterfaceInner(aIID, getter_AddRefs(inner));
+
+  // try to get get the interface from our wrapped element:
+  nsCOMPtr<nsISupports> inner;
+  QueryInterfaceInner(aIID, getter_AddRefs(inner));
 
-    if (inner) {
-      rv = NS_NewXTFInterfaceAggregator(aIID, inner,
-                                        NS_STATIC_CAST(nsIContent*, this),
-                                        aInstancePtr);
+  if (inner) {
+    rv = NS_NewXTFInterfaceAggregator(aIID, inner,
+                                      NS_STATIC_CAST(nsIContent*, this),
+                                      aInstancePtr);
 
-      return rv;
-    }
+    return rv;
   }
 
   return NS_ERROR_NO_INTERFACE;
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods:
 
--- a/content/xtf/src/nsXTFInterfaceAggregator.cpp
+++ b/content/xtf/src/nsXTFInterfaceAggregator.cpp
@@ -131,22 +131,25 @@ NS_NewXTFInterfaceAggregator(const nsIID
 // nsISupports implementation
 
 NS_IMPL_ADDREF(nsXTFInterfaceAggregator)
 NS_IMPL_RELEASE(nsXTFInterfaceAggregator)
 
 NS_IMETHODIMP
 nsXTFInterfaceAggregator::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  if(aIID.Equals(mIID)) {
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
+  if (aIID.Equals(mIID)) {
     *aInstancePtr = mXPTCStub;
     NS_ADDREF_THIS();
     return NS_OK;
   }
-  else return mOuter->QueryInterface(aIID, aInstancePtr);
+
+  return mOuter->QueryInterface(aIID, aInstancePtr);
 }
 
 //----------------------------------------------------------------------
 // nsXPTCStubBase implementation
 
 NS_IMETHODIMP
 nsXTFInterfaceAggregator::CallMethod(PRUint16 methodIndex,
                                      const XPTMethodDescriptor *info,
--- a/content/xtf/src/nsXTFWeakTearoff.cpp
+++ b/content/xtf/src/nsXTFWeakTearoff.cpp
@@ -114,24 +114,27 @@ NS_NewXTFWeakTearoff(const nsIID& iid,
 // nsISupports implementation
 
 NS_IMPL_ADDREF(nsXTFWeakTearoff)
 NS_IMPL_RELEASE(nsXTFWeakTearoff)
 
 NS_IMETHODIMP
 nsXTFWeakTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  if(aIID.Equals(mIID) || aIID.Equals(NS_GET_IID(nsISupports))) {
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
+  if (aIID.Equals(mIID) || aIID.Equals(NS_GET_IID(nsISupports))) {
     *aInstancePtr = mXPTCStub;
     NS_ADDREF_THIS();
     return NS_OK;
   }
   // we can't map QI onto the obj, because the xpcom wrapper otherwise
   // QI-accumulates all interfaces defined on mObj
   //  else return mObj->QueryInterface(aIID, aInstancePtr); 
+  *aInstancePtr = nsnull;
   return NS_ERROR_NO_INTERFACE;
 }
 
 NS_IMETHODIMP
 nsXTFWeakTearoff::CallMethod(PRUint16 methodIndex,
                              const XPTMethodDescriptor* info,
                              nsXPTCMiniVariant* params)
 {
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -361,20 +361,19 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsXULElement, nsGenericElement)
 NS_IMPL_RELEASE_INHERITED(nsXULElement, nsGenericElement)
 
 NS_IMETHODIMP
 nsXULElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-    NS_ENSURE_ARG_POINTER(aInstancePtr);
-    *aInstancePtr = nsnull;
-
-    if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) {
+    NS_PRECONDITION(aInstancePtr, "null out param");
+
+    if (aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
       *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(nsXULElement);
       return NS_OK;
     }
 
     nsresult rv = nsGenericElement::QueryInterface(aIID, aInstancePtr);
     if (NS_SUCCEEDED(rv))
         return rv;
 
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -285,41 +285,38 @@ nsComboboxControlFrame::~nsComboboxContr
   REFLOW_COUNTER_DUMP("nsCCF");
 }
 
 //--------------------------------------------------------------
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsComboboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIComboboxControlFrame))) {
-    *aInstancePtr = (void*)(nsIComboboxControlFrame*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIComboboxControlFrame*, this);
     return NS_OK;
   } else if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = (void*)(nsIFormControlFrame*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   } else if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {                                         
-    *aInstancePtr = (void*)(nsIAnonymousContentCreator*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this);
     return NS_OK;   
   } else if (aIID.Equals(NS_GET_IID(nsISelectControlFrame))) {
-    *aInstancePtr = (void *)(nsISelectControlFrame*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsISelectControlFrame*, this);
     return NS_OK;
   } else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
-    *aInstancePtr = (void*)(nsIStatefulFrame*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIStatefulFrame*, this);
     return NS_OK;
   } else if (aIID.Equals(NS_GET_IID(nsIRollupListener))) {
-    *aInstancePtr = (void*)(nsIRollupListener*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIRollupListener*, this);
     return NS_OK;
   } else if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider))) {
-    *aInstancePtr = (void*)(nsIScrollableViewProvider*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIScrollableViewProvider*, this);
     return NS_OK;
   } 
   
   return nsAreaFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsComboboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -203,28 +203,27 @@ nsFileControlFrame::CreateAnonymousConte
 
   return NS_OK;
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsFileControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(aInstancePtr, "null ptr");
-  if (NS_UNLIKELY(!aInstancePtr)) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
     *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
     *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   }
+
   return nsAreaFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 void 
 nsFileControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
 {
   // Fix for Bug 6133 
   if (mTextFrame) {
--- a/layout/forms/nsFormControlFrame.cpp
+++ b/layout/forms/nsFormControlFrame.cpp
@@ -61,24 +61,23 @@ nsFormControlFrame::Destroy()
   nsFormControlFrame::RegUnRegAccessKey(NS_STATIC_CAST(nsIFrame*, this), PR_FALSE);
   nsLeafFrame::Destroy();
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsFormControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = (void*) ((nsIFormControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   }
+
   return nsLeafFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 nscoord
 nsFormControlFrame::GetIntrinsicWidth()
 {
   // Provide a reasonable default for sites that use an "auto" height.
   // Note that if you change this, you should change the values in forms.css
--- a/layout/forms/nsGfxButtonControlFrame.cpp
+++ b/layout/forms/nsGfxButtonControlFrame.cpp
@@ -185,26 +185,24 @@ NS_IMETHODIMP nsGfxButtonControlFrame::G
   return NS_ERROR_FAILURE;
 }
 #endif
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsGfxButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_ENSURE_ARG_POINTER(aInstancePtr);
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
     *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this);
-  }
-else {
-    return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr);
+    return NS_OK;
   }
 
-  return NS_OK;
+  return nsHTMLButtonControlFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 // Initially we hardcoded the default strings here.
 // Next, we used html.css to store the default label for various types
 // of buttons. (nsGfxButtonControlFrame::DoNavQuirksReflow rev 1.20)
 // However, since html.css is not internationalized, we now grab the default
 // label from a string bundle as is done for all other UI strings.
 // See bug 16999 for further details.
--- a/layout/forms/nsGfxCheckboxControlFrame.cpp
+++ b/layout/forms/nsGfxCheckboxControlFrame.cpp
@@ -95,22 +95,20 @@ nsGfxCheckboxControlFrame::~nsGfxCheckbo
 
 //----------------------------------------------------------------------
 // nsISupports
 //----------------------------------------------------------------------
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsGfxCheckboxControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!");
-  if ( !aInstancePtr )
-    return NS_ERROR_NULL_POINTER;
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsICheckboxControlFrame))) {
-    *aInstancePtr = (void*) ((nsICheckboxControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsICheckboxControlFrame*, this);
     return NS_OK;
   }
 
   return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/forms/nsGfxRadioControlFrame.cpp
+++ b/layout/forms/nsGfxRadioControlFrame.cpp
@@ -60,22 +60,20 @@ nsGfxRadioControlFrame::nsGfxRadioContro
 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
 {
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsGfxRadioControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIRadioControlFrame))) {
-    *aInstancePtr = (void*) ((nsIRadioControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIRadioControlFrame*, this);
     return NS_OK;
   }
 
   return nsFormControlFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/forms/nsHTMLButtonControlFrame.cpp
+++ b/layout/forms/nsHTMLButtonControlFrame.cpp
@@ -116,22 +116,20 @@ nsrefcnt nsHTMLButtonControlFrame::Relea
   NS_WARNING("not supported");
   return 1;
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsHTMLButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = (void*) ((nsIFormControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   }
 
   return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/forms/nsImageControlFrame.cpp
+++ b/layout/forms/nsImageControlFrame.cpp
@@ -153,22 +153,20 @@ nsImageControlFrame::Init(nsIContent*   
                                  new nsIntPoint(0, 0),
                                  IntPointDtorFunc);
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = (void*) ((nsIFormControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   } 
 
   return nsImageControlFrameSuper::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/forms/nsIsIndexFrame.cpp
+++ b/layout/forms/nsIsIndexFrame.cpp
@@ -233,32 +233,31 @@ nsIsIndexFrame::CreateAnonymousContent(n
 
   return NS_OK;
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsIsIndexFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(aInstancePtr, "null ptr");
-  if (NS_UNLIKELY(!aInstancePtr)) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
     *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
     *aInstancePtr = NS_STATIC_CAST(nsIStatefulFrame*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIDOMKeyListener))) {
     *aInstancePtr = NS_STATIC_CAST(nsIDOMKeyListener*, this);
     return NS_OK;
   }
+
   return nsAreaFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 nscoord
 nsIsIndexFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
 {
   nscoord result;
   DISPLAY_MIN_WIDTH(this, result);
--- a/layout/forms/nsLegendFrame.cpp
+++ b/layout/forms/nsLegendFrame.cpp
@@ -74,27 +74,26 @@ void
 nsLegendFrame::Destroy()
 {
   nsFormControlFrame::RegUnRegAccessKey(NS_STATIC_CAST(nsIFrame*, this), PR_FALSE);
   nsAreaFrame::Destroy();
 }
 
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
-nsLegendFrame::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
+nsLegendFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(aInstancePtrResult, "null pointer");
-  if (NS_UNLIKELY(!aInstancePtrResult)) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(kLegendFrameCID)) {
-    *aInstancePtrResult = this;
+    *aInstancePtr = this;
     return NS_OK;
   }
-  return nsAreaFrame::QueryInterface(aIID, aInstancePtrResult);
+
+  return nsAreaFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 NS_IMETHODIMP 
 nsLegendFrame::Reflow(nsPresContext*          aPresContext,
                      nsHTMLReflowMetrics&     aDesiredSize,
                      const nsHTMLReflowState& aReflowState,
                      nsReflowStatus&          aStatus)
 {
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -375,31 +375,31 @@ void nsListControlFrame::PaintFocus(nsIR
   nsCSSRendering::DrawDashedSides(0, aRC, dirty, borderStyle, colors, fRect, innerRect, 0, nsnull);
 }
 
 //---------------------------------------------------------
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsListControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = (void*) ((nsIFormControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIListControlFrame))) {
-    *aInstancePtr = (void *)((nsIListControlFrame*)this);
+    *aInstancePtr = NS_STATIC_CAST(nsIListControlFrame*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsISelectControlFrame))) {
-    *aInstancePtr = (void *)((nsISelectControlFrame*)this);
+    *aInstancePtr = NS_STATIC_CAST(nsISelectControlFrame*, this);
     return NS_OK;
   }
+
   return nsHTMLScrollFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsListControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -978,37 +978,36 @@ NS_NewTextControlFrame(nsIPresShell* aPr
 
 NS_IMPL_ADDREF_INHERITED(nsTextControlFrame, nsBoxFrame)
 NS_IMPL_RELEASE_INHERITED(nsTextControlFrame, nsBoxFrame)
  
 
 NS_IMETHODIMP
 nsTextControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
-    *aInstancePtr = (void*) ((nsIFormControlFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIFormControlFrame*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIAnonymousContentCreator))) {
-    *aInstancePtr = (void*)(nsIAnonymousContentCreator*) this;
+    *aInstancePtr = NS_STATIC_CAST(nsIAnonymousContentCreator*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsITextControlFrame))) {
-    *aInstancePtr = (void*)(nsITextControlFrame*) this;
+    *aInstancePtr = NS_STATIC_CAST(nsITextControlFrame*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIScrollableViewProvider)) && IsScrollable()) {
-    *aInstancePtr = (void*)(nsIScrollableViewProvider*) this;
+    *aInstancePtr = NS_STATIC_CAST(nsIScrollableViewProvider*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIPhonetic))) {
-    *aInstancePtr = (void*)(nsIPhonetic*) this;
+    *aInstancePtr = NS_STATIC_CAST(nsIPhonetic*, this);
     return NS_OK;
   }
 
   return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsTextControlFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -326,40 +326,41 @@ nsBlockFrame::Destroy()
 
   nsBlockFrameSuper::Destroy();
 }
 
 NS_IMETHODIMP
 nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
   NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(kBlockFrameCID)) {
     *aInstancePtr = NS_STATIC_CAST(void*, NS_STATIC_CAST(nsBlockFrame*, this));
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsILineIterator)) ||
-      aIID.Equals(NS_GET_IID(nsILineIteratorNavigator)))
-  {
+      aIID.Equals(NS_GET_IID(nsILineIteratorNavigator))) {
     nsLineIterator* it = new nsLineIterator;
     if (!it) {
       *aInstancePtr = nsnull;
       return NS_ERROR_OUT_OF_MEMORY;
     }
     NS_ADDREF(it); // reference passed to caller
     const nsStyleVisibility* visibility = GetStyleVisibility();
     nsresult rv = it->Init(mLines,
                            visibility->mDirection == NS_STYLE_DIRECTION_RTL);
     if (NS_FAILED(rv)) {
+      *aInstancePtr = nsnull;
       NS_RELEASE(it);
       return rv;
     }
-    *aInstancePtr = NS_STATIC_CAST(void*,
-            NS_STATIC_CAST(nsILineIteratorNavigator*, it));
+    *aInstancePtr = NS_STATIC_CAST(nsILineIteratorNavigator*, it);
     return NS_OK;
   }
+
   return nsBlockFrameSuper::QueryInterface(aIID, aInstancePtr);
 }
 
 nsSplittableType
 nsBlockFrame::GetSplittableType() const
 {
   return NS_FRAME_SPLITTABLE_NON_RECTANGULAR;
 }
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -505,35 +505,36 @@ nsFrame::~nsFrame()
   NS_IF_RELEASE(mContent);
   if (mStyleContext)
     mStyleContext->Release();
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // nsISupports
 
-nsresult nsFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
+NS_IMETHODIMP
+nsFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
   NS_PRECONDITION(aInstancePtr, "null out param");
 
 #ifdef DEBUG
   if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
-    *aInstancePtr = NS_STATIC_CAST(void*,NS_STATIC_CAST(nsIFrameDebug*,this));
+    *aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*, this);
     return NS_OK;
   }
 #endif
 
   if (aIID.Equals(NS_GET_IID(nsIFrame)) ||
       aIID.Equals(NS_GET_IID(nsISupports))) {
-    *aInstancePtr = NS_STATIC_CAST(void*,NS_STATIC_CAST(nsIFrame*,this));
+    *aInstancePtr = NS_STATIC_CAST(nsIFrame*, this);
     return NS_OK;
   }
 
   *aInstancePtr = nsnull;
-  return NS_NOINTERFACE;
+  return NS_ERROR_NO_INTERFACE;
 }
 
 nsrefcnt nsFrame::AddRef(void)
 {
   NS_WARNING("not supported for frames");
   return 1;
 }
 
--- a/layout/generic/nsFrameFrame.cpp
+++ b/layout/generic/nsFrameFrame.cpp
@@ -197,24 +197,20 @@ NS_IMETHODIMP nsSubDocumentFrame::GetAcc
 }
 #endif
 
 //--------------------------------------------------------------
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 nsSubDocumentFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIFrameFrame))) {
-    nsISupports *tmp = NS_STATIC_CAST(nsIFrameFrame *, this);
-    *aInstancePtr = tmp;
+    *aInstancePtr = NS_STATIC_CAST(nsIFrameFrame*, this);
     return NS_OK;
   }
 
   return nsLeafFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 NS_IMETHODIMP
 nsSubDocumentFrame::Init(nsIContent*     aContent,
--- a/layout/generic/nsFrameSetFrame.cpp
+++ b/layout/generic/nsFrameSetFrame.cpp
@@ -245,22 +245,20 @@ nsHTMLFramesetFrame::~nsHTMLFramesetFram
   delete[] mChildTypes;
   delete[] mChildFrameborder;
   delete[] mChildBorderColors;
 
   nsContentUtils::UnregisterPrefCallback(kFrameResizePref,
                                          FrameResizePrefCallback, this);
 }
 
-nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, 
-                                             void**       aInstancePtr)
+NS_IMETHODIMP
+nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) {
     *aInstancePtr = (void*)this;
     return NS_OK;
   } 
 
   return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
--- a/layout/generic/nsHTMLFrame.cpp
+++ b/layout/generic/nsHTMLFrame.cpp
@@ -157,31 +157,26 @@ NS_NewCanvasFrame(nsIPresShell* aPresShe
   return new (aPresShell)CanvasFrame(aContext);
 }
 
 //--------------------------------------------------------------
 // Frames are not refcounted, no need to AddRef
 NS_IMETHODIMP
 CanvasFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIScrollPositionListener))) {
-    *aInstancePtr = (void*) ((nsIScrollPositionListener*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsIScrollPositionListener*, this);
     return NS_OK;
   } 
-  
   if (aIID.Equals(NS_GET_IID(nsICanvasFrame))) {
-    *aInstancePtr = (void*) ((nsICanvasFrame*) this);
+    *aInstancePtr = NS_STATIC_CAST(nsICanvasFrame*, this);
     return NS_OK;
   } 
-  
 
   return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 NS_IMETHODIMP
 CanvasFrame::Init(nsIContent*      aContent,
                   nsIFrame*        aParent,
                   nsIFrame*        aPrevInFlow)
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -183,38 +183,24 @@ nsImageFrame::nsImageFrame(nsStyleContex
 
 nsImageFrame::~nsImageFrame()
 {
 }
 
 NS_IMETHODIMP
 nsImageFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_ENSURE_ARG_POINTER(aInstancePtr);
-  *aInstancePtr = nsnull;
-
-#ifdef DEBUG
-  if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*,this);
-    return NS_OK;
-  }
-#endif
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIImageFrame))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIFrame))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIFrame*,this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsISupports))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
+    *aInstancePtr = NS_STATIC_CAST(nsIImageFrame*, this);
     return NS_OK;
   }
 
-  return NS_NOINTERFACE;
+  return ImageFrameSuper::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
--- a/layout/generic/nsInlineFrame.cpp
+++ b/layout/generic/nsInlineFrame.cpp
@@ -73,24 +73,23 @@ nsIFrame*
 NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsInlineFrame(aContext);
 }
 
 NS_IMETHODIMP
 nsInlineFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (nsnull == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(kInlineFrameCID)) {
-    nsInlineFrame* tmp = this;
-    *aInstancePtr = (void*) tmp;
+    *aInstancePtr = this;
     return NS_OK;
   }
+
   return nsInlineFrameSuper::QueryInterface(aIID, aInstancePtr);
 }
 
 void
 nsInlineFrame::Destroy()
 {
   if (mState & NS_FRAME_GENERATED_CONTENT) {
     // Make sure all the content nodes for the generated content inside
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -443,37 +443,24 @@ static void ConvertAppUnitsToPixels(cons
 
 nsObjectFrame::~nsObjectFrame()
 {
 }
 
 NS_IMETHODIMP
 nsObjectFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_ENSURE_ARG_POINTER(aInstancePtr);
-  *aInstancePtr = nsnull;
-
-#ifdef DEBUG
-  if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*,this);
-    return NS_OK;
-  }
-#endif
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIObjectFrame))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIObjectFrame*,this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsIFrame))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIFrame*,this);
-    return NS_OK;
-  } else if (aIID.Equals(NS_GET_IID(nsISupports))) {
-    *aInstancePtr = NS_STATIC_CAST(nsIObjectFrame*,this);
+    *aInstancePtr = NS_STATIC_CAST(nsIObjectFrame*, this);
     return NS_OK;
   }
-  return NS_NOINTERFACE;
+
+  return nsObjectFrameSuper::QueryInterface(aIID, aInstancePtr);
 }
 
 NS_IMETHODIMP_(nsrefcnt) nsObjectFrame::AddRef(void)
 {
   NS_WARNING("not supported for frames");
   return 1;
 }
 
--- a/layout/generic/nsSimplePageSequence.cpp
+++ b/layout/generic/nsSimplePageSequence.cpp
@@ -131,25 +131,23 @@ nsSimplePageSequenceFrame::nsSimplePageS
   SetPageNumberFormat("pageofpages", "%1$d of %2$d", PR_FALSE);
 }
 
 nsSimplePageSequenceFrame::~nsSimplePageSequenceFrame()
 {
   if (mPageData) delete mPageData;
 }
 
-nsresult
+NS_IMETHODIMP
 nsSimplePageSequenceFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  NS_PRECONDITION(0 != aInstancePtr, "null ptr");
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsIPageSequenceFrame))) {
-    *aInstancePtr = (void*)(nsIPageSequenceFrame*)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIPageSequenceFrame*, this);
     return NS_OK;
   }
   return nsContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 //----------------------------------------------------------------------
 
 // Creates a continuing page frame
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -906,28 +906,27 @@ NS_METHOD nsTableCellFrame::Reflow(nsPre
   return NS_OK;
 }
 
 /* ----- global methods ----- */
 
 NS_IMPL_ADDREF_INHERITED(nsTableCellFrame, nsHTMLContainerFrame)
 NS_IMPL_RELEASE_INHERITED(nsTableCellFrame, nsHTMLContainerFrame)
 
-nsresult nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
+NS_IMETHODIMP
+nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsITableCellLayout))) {
-    *aInstancePtr = (void*) (nsITableCellLayout *)this;
+    *aInstancePtr = NS_STATIC_CAST(nsITableCellLayout*, this);
     return NS_OK;
   }
   if (aIID.Equals(NS_GET_IID(nsIPercentHeightObserver))) {
-    *aInstancePtr = (void*) (nsIPercentHeightObserver *)this;
+    *aInstancePtr = NS_STATIC_CAST(nsIPercentHeightObserver*, this);
     return NS_OK;
   }
 
   return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsTableCellFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -194,29 +194,27 @@ nsTableFrame::nsTableFrame(nsStyleContex
   mBits.mIsBorderCollapse       = PR_FALSE;
   mBits.mResizedColumns         = PR_FALSE; // only really matters if splitting
   mBits.mGeometryDirty          = PR_FALSE;
 }
 
 NS_IMPL_ADDREF_INHERITED(nsTableFrame, nsHTMLContainerFrame)
 NS_IMPL_RELEASE_INHERITED(nsTableFrame, nsHTMLContainerFrame)
 
-nsresult nsTableFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
-  if (aIID.Equals(NS_GET_IID(nsITableLayout))) 
-  { // note there is no addref here, frames are not addref'd
-    *aInstancePtr = (void*)(nsITableLayout*)this;
+NS_IMETHODIMP
+nsTableFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
+{
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
+  if (aIID.Equals(NS_GET_IID(nsITableLayout))) {
+    *aInstancePtr = NS_STATIC_CAST(nsITableLayout*, this);
     return NS_OK;
   }
-  else {
-    return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
-  }
+
+  return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 NS_IMETHODIMP
 nsTableFrame::Init(nsIContent*      aContent,
                    nsIFrame*        aParent,
                    nsIFrame*        aPrevInFlow)
 {
   nsresult  rv;
--- a/layout/tables/nsTableOuterFrame.cpp
+++ b/layout/tables/nsTableOuterFrame.cpp
@@ -160,25 +160,23 @@ nsTableOuterFrame::nsTableOuterFrame(nsS
   nsHTMLContainerFrame(aContext)
 {
 }
 
 nsTableOuterFrame::~nsTableOuterFrame()
 {
 }
 
-nsresult nsTableOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
+NS_IMETHODIMP
+nsTableOuterFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
-  if (aIID.Equals(NS_GET_IID(nsITableLayout))) 
-  { // note there is no addref here, frames are not addref'd
-    *aInstancePtr = (void*)(nsITableLayout*)this;
+  if (aIID.Equals(NS_GET_IID(nsITableLayout))) {
+    *aInstancePtr = NS_STATIC_CAST(nsITableLayout*, this);
     return NS_OK;
   }
 
   return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsTableOuterFrame::GetAccessible(nsIAccessible** aAccessible)
--- a/layout/tables/nsTableRowGroupFrame.cpp
+++ b/layout/tables/nsTableRowGroupFrame.cpp
@@ -70,36 +70,32 @@ nsrefcnt nsTableRowGroupFrame::AddRef(vo
   return 1;//implementation of nsLineIterator
 }
 
 nsrefcnt nsTableRowGroupFrame::Release(void)
 {
   return 1;//implementation of nsLineIterator
 }
 
-
-nsresult
+NS_IMETHODIMP
 nsTableRowGroupFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
 {
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   static NS_DEFINE_IID(kITableRowGroupIID, NS_ITABLEROWGROUPFRAME_IID);
   if (aIID.Equals(kITableRowGroupIID)) {
     *aInstancePtr = (void*)this;
     return NS_OK;
   }
-  else if (aIID.Equals(NS_GET_IID(nsILineIteratorNavigator)))
-  { // note there is no addref here, frames are not addref'd
-    *aInstancePtr = (void*)(nsILineIteratorNavigator*)this;
+  if (aIID.Equals(NS_GET_IID(nsILineIteratorNavigator))) {
+    *aInstancePtr = NS_STATIC_CAST(nsILineIteratorNavigator*, this);
     return NS_OK;
   }
-  else {
-    return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
-  }
+
+  return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
 }
 
 /* virtual */ PRBool
 nsTableRowGroupFrame::IsContainingBlock() const
 {
   return PR_TRUE;
 }
 
--- a/layout/xul/base/src/nsMenuBoxObject.cpp
+++ b/layout/xul/base/src/nsMenuBoxObject.cpp
@@ -60,21 +60,20 @@ protected:
 
 /* Implementation file */
 NS_IMPL_ADDREF(nsMenuBoxObject)
 NS_IMPL_RELEASE(nsMenuBoxObject)
 
 NS_IMETHODIMP 
 nsMenuBoxObject::QueryInterface(REFNSIID iid, void** aResult)
 {
-  if (!aResult)
-    return NS_ERROR_NULL_POINTER;
-  
+  NS_PRECONDITION(aResult, "null out param");
+
   if (iid.Equals(NS_GET_IID(nsIMenuBoxObject))) {
-    *aResult = (nsIMenuBoxObject*)this;
+    *aResult = NS_STATIC_CAST(nsIMenuBoxObject*, this);
     NS_ADDREF(this);
     return NS_OK;
   }
 
   return nsBoxObject::QueryInterface(iid, aResult);
 }
   
 nsMenuBoxObject::nsMenuBoxObject()
--- a/layout/xul/base/src/nsScrollbarButtonFrame.cpp
+++ b/layout/xul/base/src/nsScrollbarButtonFrame.cpp
@@ -65,19 +65,20 @@ nsIFrame*
 NS_NewScrollbarButtonFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsScrollbarButtonFrame(aPresShell, aContext);
 } // NS_NewScrollBarButtonFrame
 
 NS_IMETHODIMP 
 nsScrollbarButtonFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)      
 {           
+  NS_PRECONDITION(aInstancePtr, "null out param");
+
   if (aIID.Equals(NS_GET_IID(nsITimerCallback))) {                                         
-    *aInstancePtr = (void*)(nsITimerCallback*) this;                                        
-    NS_ADDREF_THIS();                                                    
+    *aInstancePtr = NS_STATIC_CAST(nsITimerCallback*, this);
     return NS_OK;                                                        
   }   
 
   return nsButtonBoxFrame::QueryInterface(aIID, aInstancePtr);                                     
 }
 
 NS_IMETHODIMP
 nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext, 
--- a/widget/src/beos/nsDeviceContextSpecB.cpp
+++ b/widget/src/beos/nsDeviceContextSpecB.cpp
@@ -101,18 +101,17 @@ static NS_DEFINE_IID(kIDeviceContextSpec
 #endif /* USE_POSTSCRIPT */
  
 #if 0 
 NS_IMPL_ISUPPORTS1(nsDeviceContextSpecBeOS, nsIDeviceContextSpec)
 #endif 
  
 NS_IMETHODIMP nsDeviceContextSpecBeOS :: QueryInterface(REFNSIID aIID, void** aInstancePtr) 
 { 
-  if (nsnull == aInstancePtr) 
-    return NS_ERROR_NULL_POINTER; 
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(kIDeviceContextSpecIID)) 
   { 
     nsIDeviceContextSpec* tmp = this; 
     *aInstancePtr = (void*) tmp; 
     NS_ADDREF_THIS(); 
     return NS_OK; 
   } 
@@ -133,17 +132,18 @@ NS_IMETHODIMP nsDeviceContextSpecBeOS ::
   { 
     nsIDeviceContextSpec* tmp = this; 
     nsISupports* tmp2 = tmp; 
     *aInstancePtr = (void*) tmp2; 
     NS_ADDREF_THIS(); 
     return NS_OK; 
   } 
  
-  return NS_NOINTERFACE; 
+  *aInstancePtr = nsnull;
+  return NS_ERROR_NO_INTERFACE;
 } 
  
 NS_IMPL_ADDREF(nsDeviceContextSpecBeOS)
 NS_IMPL_RELEASE(nsDeviceContextSpecBeOS)
 
 /** -------------------------------------------------------
  *  Initialize the nsDeviceContextSpecBeOS
  *  @update   dc 2/15/98
--- a/widget/src/os2/nsDeviceContextSpecOS2.cpp
+++ b/widget/src/os2/nsDeviceContextSpecOS2.cpp
@@ -216,18 +216,17 @@ nsresult nsDeviceContextSpecOS2::SetPrin
   
   delete [] pDJP_Buffer;
   DevCloseDC(hdc);  
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDeviceContextSpecOS2 :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  if (nsnull == aInstancePtr)
-    return NS_ERROR_NULL_POINTER;
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(kIDeviceContextSpecIID))
   {
     nsIDeviceContextSpec* tmp = this;
     *aInstancePtr = (void*) tmp;
     NS_ADDREF_THIS();
     return NS_OK;
   }
@@ -238,17 +237,18 @@ NS_IMETHODIMP nsDeviceContextSpecOS2 :: 
   {
     nsIDeviceContextSpec* tmp = this;
     nsISupports* tmp2 = tmp;
     *aInstancePtr = (void*) tmp2;
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
-  return NS_NOINTERFACE;
+  *aInstancePtr = nsnull;
+  return NS_ERROR_NO_INTERFACE;
 }
 
 NS_IMPL_ADDREF(nsDeviceContextSpecOS2)
 NS_IMPL_RELEASE(nsDeviceContextSpecOS2)
 
 NS_IMETHODIMP nsDeviceContextSpecOS2::Init(nsIWidget *aWidget,
                                            nsIPrintSettings* aPS,
                                            PRBool aIsPrintPreview)
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -751,25 +751,24 @@ void nsWindow::GlobalMsgWindowProc(HWND 
 
 //-------------------------------------------------------------------------
 //
 // nsISupport stuff
 //
 //-------------------------------------------------------------------------
 NS_IMPL_ADDREF(nsWindow)
 NS_IMPL_RELEASE(nsWindow)
-NS_IMETHODIMP nsWindow::QueryInterface(const nsIID& aIID, void** aInstancePtr)
-{
-  if (NULL == aInstancePtr) {
-    return NS_ERROR_NULL_POINTER;
-  }
+NS_IMETHODIMP
+nsWindow::QueryInterface(const nsIID& aIID, void** aInstancePtr)
+{
+  NS_PRECONDITION(aInstancePtr, "null out param");
 
   if (aIID.Equals(NS_GET_IID(nsIKBStateControl))) {
-    *aInstancePtr = (void*) ((nsIKBStateControl*)this);
-    NS_ADDREF((nsBaseWidget*)this);
+    *aInstancePtr = NS_STATIC_CAST(nsIKBStateControl*, this);
+    NS_ADDREF(NS_STATIC_CAST(nsBaseWidget*, this));
     return NS_OK;
   }
 
   return nsBaseWidget::QueryInterface(aIID,aInstancePtr);
 }
 //-------------------------------------------------------------------------
 //
 // nsWindow constructor