Bug 738700 - unmark wrapped gray objects from nsISupports. r=smaug
authorAndrew McCreight <amccreight@mozilla.com>
Wed, 28 Mar 2012 21:51:46 -0700
changeset 93909 ec1874ee6dc3df2795762ed96a7ecc3dcb702adb
parent 93908 0e919664cdf519e380c61033fcc91cea95672919
child 93910 bb679e5939b973b93932b867da24b2eaa10da98e
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs738700
milestone14.0a1
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 738700 - unmark wrapped gray objects from nsISupports. r=smaug
content/base/src/nsFrameMessageManager.cpp
content/base/src/nsGenericElement.cpp
content/events/src/nsDOMEventTargetHelper.h
content/events/src/nsEventListenerManager.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcpublic.h
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -1105,14 +1105,12 @@ NS_NewChildProcessMessageManager(nsISync
   return CallQueryInterface(mm, aResult);
 }
 
 bool
 nsFrameMessageManager::MarkForCC()
 {
   PRUint32 len = mListeners.Length();
   for (PRUint32 i = 0; i < len; ++i) {
-    nsCOMPtr<nsIXPConnectWrappedJS> wjs =
-      do_QueryInterface(mListeners[i].mListener);
-    xpc_UnmarkGrayObject(wjs);
+    xpc_TryUnmarkWrappedGrayObject(mListeners[i].mListener);
   }
   return true;
 }
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -4580,19 +4580,17 @@ nsGenericElement::MarkUserData(void* aOb
   PRUint32* gen = static_cast<PRUint32*>(aData);
   xpc_MarkInCCGeneration(static_cast<nsISupports*>(aChild), *gen);
 }
 
 void
 nsGenericElement::MarkUserDataHandler(void* aObject, nsIAtom* aKey,
                                       void* aChild, void* aData)
 {
-  nsCOMPtr<nsIXPConnectWrappedJS> wjs =
-    do_QueryInterface(static_cast<nsISupports*>(aChild));
-  xpc_UnmarkGrayObject(wjs);
+  xpc_TryUnmarkWrappedGrayObject(static_cast<nsISupports*>(aChild));
 }
 
 void
 nsGenericElement::MarkNodeChildren(nsINode* aNode)
 {
   JSObject* o = GetJSObjectChild(aNode);
   xpc_UnmarkGrayObject(o);
 
--- a/content/events/src/nsDOMEventTargetHelper.h
+++ b/content/events/src/nsDOMEventTargetHelper.h
@@ -194,16 +194,14 @@ private:
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOn##_event##Listener)
 
 #define NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(_event)                      \
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOn##_event##Listener)
 
 #define NS_DISCONNECT_EVENT_HANDLER(_event)                                   \
   if (mOn##_event##Listener) { mOn##_event##Listener->Disconnect(); }
 
-#define NS_UNMARK_LISTENER_WRAPPER(_event)                       \
-  if (tmp->mOn##_event##Listener) {                              \
-    nsCOMPtr<nsIXPConnectWrappedJS> wjs =                        \
-      do_QueryInterface(tmp->mOn##_event##Listener->GetInner()); \
-    xpc_UnmarkGrayObject(wjs);                                   \
+#define NS_UNMARK_LISTENER_WRAPPER(_event)                                    \
+  if (tmp->mOn##_event##Listener) {                                           \
+    xpc_TryUnmarkWrappedGrayObject(tmp->mOn##_event##Listener->GetInner());   \
   }
 
 #endif // nsDOMEventTargetHelper_h_
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -1045,13 +1045,12 @@ nsEventListenerManager::UnmarkGrayJSList
   PRUint32 count = mListeners.Length();
   for (PRUint32 i = 0; i < count; ++i) {
     const nsListenerStruct& ls = mListeners.ElementAt(i);
     nsIJSEventListener* jsl = ls.GetJSListener();
     if (jsl) {
       xpc_UnmarkGrayObject(jsl->GetHandler());
       xpc_UnmarkGrayObject(jsl->GetEventScope());
     } else if (ls.mWrappedJS) {
-      nsCOMPtr<nsIXPConnectWrappedJS> wjs = do_QueryInterface(ls.mListener);
-      xpc_UnmarkGrayObject(wjs);
+      xpc_TryUnmarkWrappedGrayObject(ls.mListener);
     }
   }
 }
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -855,21 +855,22 @@ xpc_MarkInCCGeneration(nsISupports* aVar
         variant = nsnull;
         if (weak->IsPurple()) {
           weak->RemovePurple();
         }
     }
 }
 
 void
-xpc_UnmarkGrayObject(nsIXPConnectWrappedJS* aWrappedJS)
+xpc_TryUnmarkWrappedGrayObject(nsISupports* aWrappedJS)
 {
-    if (aWrappedJS) {
+    nsCOMPtr<nsIXPConnectWrappedJS> wjs = do_QueryInterface(aWrappedJS);
+    if (wjs) {
         // Unmarks gray JSObject.
-        static_cast<nsXPCWrappedJS*>(aWrappedJS)->GetJSObject();
+        static_cast<nsXPCWrappedJS*>(wjs.get())->GetJSObject();
     }
 }
 
 static JSBool
 WrapperIsNotMainThreadOnly(XPCWrappedNative *wrapper)
 {
     XPCWrappedNativeProto *proto = wrapper->GetProto();
     if (proto && proto->ClassIsMainThreadOnly())
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -50,17 +50,16 @@
 
 #include "nsISupports.h"
 #include "nsIPrincipal.h"
 #include "nsWrapperCache.h"
 #include "nsStringGlue.h"
 #include "nsTArray.h"
 
 class nsIPrincipal;
-class nsIXPConnectWrappedJS;
 struct nsDOMClassInfoData;
 
 #ifndef BAD_TLS_INDEX
 #define BAD_TLS_INDEX ((PRUint32) -1)
 #endif
 
 nsresult
 xpc_CreateGlobalObject(JSContext *cx, JSClass *clasp,
@@ -191,19 +190,19 @@ xpc_UnmarkGrayObject(JSObject *obj)
     }
 }
 
 // If aVariant is an XPCVariant, this marks the object to be in aGeneration.
 // This also unmarks the gray JSObject.
 extern void
 xpc_MarkInCCGeneration(nsISupports* aVariant, PRUint32 aGeneration);
 
-// Unmarks aWrappedJS's JSObject.
+// If aWrappedJS is a JS wrapper, unmark its JSObject.
 extern void
-xpc_UnmarkGrayObject(nsIXPConnectWrappedJS* aWrappedJS);
+xpc_TryUnmarkWrappedGrayObject(nsISupports* aWrappedJS);
 
 extern void
 xpc_UnmarkSkippableJSHolders();
 
 // No JS can be on the stack when this is called. Probably only useful from
 // xpcshell.
 NS_EXPORT_(void)
 xpc_ActivateDebugMode();