Bug 786008 - Add a debug check to make sure that QueryInterface implementations always handle nsISupports; r=ehsan
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Tue, 28 Aug 2012 12:33:47 -0400
changeset 110242 94038167af79185b2d1c0e76370277994e984003
parent 110241 851a00eaa0b71fc285747e77aee9f95030bb6bb0
child 110243 f6e4e6857c0c68460eb352ecbb692483f74e0fb6
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs786008
milestone18.0a1
Bug 786008 - Add a debug check to make sure that QueryInterface implementations always handle nsISupports; r=ehsan
xpcom/glue/nsISupportsImpl.h
--- a/xpcom/glue/nsISupportsImpl.h
+++ b/xpcom/glue/nsISupportsImpl.h
@@ -25,16 +25,18 @@
 #include "nsAtomicRefcnt.h" /* for NS_Atomic{Increment,Decrement}Refcnt */
 #endif
 
 #include "nsDebug.h"
 #include "nsTraceRefcnt.h"
 #include "nsCycleCollector.h"
 #include "nsCycleCollectorUtils.h"
 
+#include "mozilla/Assertions.h"
+
 ////////////////////////////////////////////////////////////////////////////////
 // Macros to help detect thread-safety:
 
 #if defined(DEBUG) && !defined(XPCOM_GLUE_AVOID_NSPR)
 
 class nsAutoOwningThread {
 public:
     nsAutoOwningThread() { mThread = PR_GetCurrentThread(); }
@@ -661,17 +663,21 @@ NS_IMETHODIMP _class::QueryInterface(REF
   if ( aIID.Equals(NS_GET_IID(_interface)) )                                  \
     foundInterface = static_cast<_interface*>(_aggregate);                    \
   else
 
 #define NS_IMPL_QUERY_TAIL_GUTS                                               \
     foundInterface = 0;                                                       \
   nsresult status;                                                            \
   if ( !foundInterface )                                                      \
-    status = NS_NOINTERFACE;                                                  \
+    {                                                                         \
+      /* nsISupports should be handled by this point. If not, fail. */        \
+      MOZ_ASSERT(!aIID.Equals(NS_GET_IID(nsISupports)));                      \
+      status = NS_NOINTERFACE;                                                \
+    }                                                                         \
   else                                                                        \
     {                                                                         \
       NS_ADDREF(foundInterface);                                              \
       status = NS_OK;                                                         \
     }                                                                         \
   *aInstancePtr = foundInterface;                                             \
   return status;                                                              \
 }