diff --git a/accessible/src/base/AccEvent.cpp b/accessible/src/base/AccEvent.cpp index fac8de043d4e..00a7fe499bf6 100644 --- a/accessible/src/base/AccEvent.cpp +++ b/accessible/src/base/AccEvent.cpp @@ -88,7 +88,7 @@ AccEvent::CreateXPCOMObject() //////////////////////////////////////////////////////////////////////////////// // AccEvent cycle collection -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(AccEvent) +NS_IMPL_CYCLE_COLLECTION_CLASS(AccEvent) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(AccEvent) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mAccessible) diff --git a/accessible/src/base/NotificationController.cpp b/accessible/src/base/NotificationController.cpp index 48275dbf1bd3..a3df7524aac8 100644 --- a/accessible/src/base/NotificationController.cpp +++ b/accessible/src/base/NotificationController.cpp @@ -56,7 +56,7 @@ NotificationController::~NotificationController() NS_IMPL_ADDREF(NotificationController) NS_IMPL_RELEASE(NotificationController) -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(NotificationController) +NS_IMPL_CYCLE_COLLECTION_CLASS(NotificationController) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(NotificationController) if (tmp->mDocument) @@ -812,7 +812,7 @@ NotificationController::ContentInsertion:: return haveToUpdate; } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(NotificationController::ContentInsertion) +NS_IMPL_CYCLE_COLLECTION_CLASS(NotificationController::ContentInsertion) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(NotificationController::ContentInsertion) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mContainer) diff --git a/accessible/src/generic/Accessible.cpp b/accessible/src/generic/Accessible.cpp index b3e109e4884c..3aefc8dd7c06 100644 --- a/accessible/src/generic/Accessible.cpp +++ b/accessible/src/generic/Accessible.cpp @@ -111,7 +111,7 @@ Accessible::QueryInterface(REFNSIID aIID, void** aInstancePtr) *aInstancePtr = nsnull; if (aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { - *aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(Accessible); + *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(Accessible); return NS_OK; } diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 3b55ee226fff..a67ea8ba16c1 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -2158,7 +2158,7 @@ typedef nsCharSeparatedTokenizerTemplate #define NS_HOLD_JS_OBJECTS(obj, clazz) \ nsContentUtils::HoldJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz), \ - NS_CYCLE_COLLECTION_PARTICIPANT(clazz)) + &NS_CYCLE_COLLECTION_NAME(clazz)) #define NS_DROP_JS_OBJECTS(obj, clazz) \ nsContentUtils::DropJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz)) diff --git a/content/base/src/nsNodeInfoManager.cpp b/content/base/src/nsNodeInfoManager.cpp index 295d5b3a0eb2..39c685d08e8f 100644 --- a/content/base/src/nsNodeInfoManager.cpp +++ b/content/base/src/nsNodeInfoManager.cpp @@ -130,7 +130,7 @@ nsNodeInfoManager::~nsNodeInfoManager() } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsNodeInfoManager) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsNodeInfoManager) NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsNodeInfoManager, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsNodeInfoManager, Release) NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(nsNodeInfoManager) diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index b6e8e8354faf..fb88a7358fc0 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -145,7 +145,7 @@ nsEventListenerManager::Shutdown() nsDOMEvent::Shutdown(); } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsEventListenerManager) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsEventListenerManager) NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsEventListenerManager, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsEventListenerManager, Release) diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index fc84b1f69fb8..cc41eeef2b84 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -257,7 +257,7 @@ TraverseKey(nsISupports* aKey, nsInsertionPointList* aData, void* aClosure) return PL_DHASH_NEXT; } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLBinding) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLBinding) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXBLBinding) // XXX Probably can't unlink mPrototypeBinding->XBLDocumentInfo(), because // mPrototypeBinding is weak. diff --git a/content/xbl/src/nsXBLInsertionPoint.cpp b/content/xbl/src/nsXBLInsertionPoint.cpp index a2c72ede3b54..2ddcd96a0064 100644 --- a/content/xbl/src/nsXBLInsertionPoint.cpp +++ b/content/xbl/src/nsXBLInsertionPoint.cpp @@ -24,7 +24,7 @@ nsXBLInsertionPoint::~nsXBLInsertionPoint() } } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLInsertionPoint) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLInsertionPoint) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXBLInsertionPoint) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mElements) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDefaultContentTemplate) diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index 7ed5a9d9d416..658fce00c9ac 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -227,7 +227,7 @@ private: PRUint32 nsXBLInsertionPointEntry::gRefCnt = 0; nsFixedSizeAllocator* nsXBLInsertionPointEntry::kPool; -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLInsertionPointEntry) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLInsertionPointEntry) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXBLInsertionPointEntry) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mInsertionParent) if (tmp->mDefaultContent) { diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 35e023b565dd..924e3b9a2ed5 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -755,7 +755,7 @@ nsScriptEventHandlerOwnerTearoff::CompileEventHandler( if (!elem->mHoldsScriptObject) { rv = nsContentUtils::HoldJSObjects( - elem, NS_CYCLE_COLLECTION_PARTICIPANT(nsXULPrototypeNode)); + elem, &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode)); NS_ENSURE_SUCCESS(rv, rv); } @@ -3098,7 +3098,7 @@ nsXULPrototypeScript::Set(JSScript* aObject) } nsresult rv = nsContentUtils::HoldJSObjects( - this, NS_CYCLE_COLLECTION_PARTICIPANT(nsXULPrototypeNode)); + this, &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode)); if (NS_SUCCEEDED(rv)) { mScriptObject.mObject = aObject; } diff --git a/content/xul/templates/src/nsXMLBinding.cpp b/content/xul/templates/src/nsXMLBinding.cpp index 03b7c73a5956..a00e1a710f5c 100644 --- a/content/xul/templates/src/nsXMLBinding.cpp +++ b/content/xul/templates/src/nsXMLBinding.cpp @@ -10,7 +10,7 @@ NS_IMPL_ADDREF(nsXMLBindingSet) NS_IMPL_RELEASE(nsXMLBindingSet) -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsXMLBindingSet) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLBindingSet) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXMLBindingSet) nsXMLBinding* binding = tmp->mFirst; diff --git a/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp b/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp index db65822766fb..4d86a248c873 100644 --- a/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp +++ b/content/xul/templates/src/nsXULTemplateQueryProcessorXML.cpp @@ -85,7 +85,7 @@ TraverseRuleToBindingsMap(nsISupports* aKey, nsXMLBindingSet* aMatch, void* aCon NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mRuleToBindingsMap key"); cb->NoteXPCOMChild(aKey); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mRuleToBindingsMap value"); - cb->NoteNativeChild(aMatch, NS_CYCLE_COLLECTION_PARTICIPANT(nsXMLBindingSet)); + cb->NoteNativeChild(aMatch, &NS_CYCLE_COLLECTION_NAME(nsXMLBindingSet)); return PL_DHASH_NEXT; } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 5ecd3d46092c..616b4c7dfae5 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -539,7 +539,7 @@ nsTimeout::~nsTimeout() MOZ_COUNT_DTOR(nsTimeout); } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsTimeout) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsTimeout) NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(nsTimeout) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsTimeout) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mWindow, @@ -1226,7 +1226,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGlobalWindow) for (nsTimeout* timeout = tmp->FirstTimeout(); tmp->IsTimeout(timeout); timeout = timeout->Next()) { - cb.NoteNativeChild(timeout, NS_CYCLE_COLLECTION_PARTICIPANT(nsTimeout)); + cb.NoteNativeChild(timeout, &NS_CYCLE_COLLECTION_NAME(nsTimeout)); } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLocalStorage) diff --git a/editor/txmgr/src/nsTransactionItem.cpp b/editor/txmgr/src/nsTransactionItem.cpp index 7842faf54bde..4dc57f044f38 100644 --- a/editor/txmgr/src/nsTransactionItem.cpp +++ b/editor/txmgr/src/nsTransactionItem.cpp @@ -43,7 +43,7 @@ nsTransactionItem::Release() { return mRefCnt; } -NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(nsTransactionItem) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsTransactionItem) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsTransactionItem) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTransaction) diff --git a/editor/txmgr/src/nsTransactionStack.cpp b/editor/txmgr/src/nsTransactionStack.cpp index 75db2e00047c..2288357297ef 100644 --- a/editor/txmgr/src/nsTransactionStack.cpp +++ b/editor/txmgr/src/nsTransactionStack.cpp @@ -95,7 +95,7 @@ nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb) static_cast(mQue.ObjectAt(i)); if (item) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mQue[i]"); - cb.NoteNativeChild(item, NS_CYCLE_COLLECTION_PARTICIPANT(nsTransactionItem)); + cb.NoteNativeChild(item, &NS_CYCLE_COLLECTION_NAME(nsTransactionItem)); } } } diff --git a/js/xpconnect/src/XPCWrappedJS.cpp b/js/xpconnect/src/XPCWrappedJS.cpp index 4c0104a90ead..f371242bed08 100644 --- a/js/xpconnect/src/XPCWrappedJS.cpp +++ b/js/xpconnect/src/XPCWrappedJS.cpp @@ -17,9 +17,8 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsXPCWrappedJS) NS_IMETHODIMP -NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::TraverseImpl - (NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS) *that, void *p, - nsCycleCollectionTraversalCallback &cb) +NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse + (void *p, nsCycleCollectionTraversalCallback &cb) { nsISupports *s = static_cast(p); NS_ASSERTION(CheckForRightISupports(s), @@ -99,7 +98,7 @@ nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr) } if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) { - *aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(nsXPCWrappedJS); + *aInstancePtr = & NS_CYCLE_COLLECTION_NAME(nsXPCWrappedJS); return NS_OK; } diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index 094a855e8705..6719eb823bbb 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -44,7 +44,7 @@ xpc_OkToHandOutWrapper(nsWrapperCache *cache) NS_IMPL_CYCLE_COLLECTION_CLASS(XPCWrappedNative) NS_IMETHODIMP -NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::UnlinkImpl(void *p) +NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Unlink(void *p) { XPCWrappedNative *tmp = static_cast(p); tmp->ExpireWrapper(); @@ -52,9 +52,8 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::UnlinkImpl(void *p) } NS_IMETHODIMP -NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::TraverseImpl - (NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative) *that, void *p, - nsCycleCollectionTraversalCallback &cb) +NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(void *p, + nsCycleCollectionTraversalCallback &cb) { XPCWrappedNative *tmp = static_cast(p); if (!tmp->IsValid()) diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 34d009bf813a..23333fe59a88 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -543,33 +543,28 @@ nsXPConnect::FinishTraverse() return NS_OK; } -class nsXPConnectParticipant: public nsCycleCollectionParticipant -{ -public: - static NS_METHOD RootImpl(void *n) - { - return NS_OK; - } - static NS_METHOD UnlinkImpl(void *n) - { - return NS_OK; - } - static NS_METHOD UnrootImpl(void *n) - { - return NS_OK; - } - static NS_METHOD TraverseImpl(nsXPConnectParticipant *that, void *n, - nsCycleCollectionTraversalCallback &cb); -}; - -static CCParticipantVTable::Type XPConnect_cycleCollectorGlobal = { - NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(nsXPConnectParticipant) -}; - nsCycleCollectionParticipant * nsXPConnect::GetParticipant() { - return XPConnect_cycleCollectorGlobal.GetParticipant(); + return this; +} + +NS_IMETHODIMP +nsXPConnect::Root(void *p) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXPConnect::Unlink(void *p) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsXPConnect::Unroot(void *p) +{ + return NS_OK; } JSBool @@ -761,9 +756,8 @@ WrapperIsNotMainThreadOnly(XPCWrappedNative *wrapper) return NS_FAILED(CallQueryInterface(wrapper->Native(), &participant)); } -NS_METHOD -nsXPConnectParticipant::TraverseImpl(nsXPConnectParticipant *that, void *p, - nsCycleCollectionTraversalCallback &cb) +NS_IMETHODIMP +nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) { JSGCTraceKind traceKind = js_GetGCThingTraceKind(p); JSObject *obj = nsnull; @@ -849,7 +843,7 @@ nsXPConnectParticipant::TraverseImpl(nsXPConnectParticipant *that, void *p, TraversalTracer trc(cb); - JS_TracerInit(&trc, nsXPConnect::GetRuntimeInstance()->GetJSRuntime(), NoteJSChild); + JS_TracerInit(&trc, GetRuntime()->GetJSRuntime(), NoteJSChild); trc.eagerlyTraceWeakMaps = false; JS_TraceChildren(&trc, p, traceKind); @@ -903,11 +897,11 @@ nsXPConnect::GetOutstandingRequests(JSContext* cx) class JSContextParticipant : public nsCycleCollectionParticipant { public: - static NS_METHOD RootImpl(void *n) + NS_IMETHOD Root(void *n) { return NS_OK; } - static NS_METHOD UnlinkImpl(void *n) + NS_IMETHOD Unlink(void *n) { JSContext *cx = static_cast(n); JSAutoRequest ar(cx); @@ -915,12 +909,11 @@ public: JS_SetGlobalObject(cx, NULL); return NS_OK; } - static NS_METHOD UnrootImpl(void *n) + NS_IMETHOD Unroot(void *n) { return NS_OK; } - static NS_METHOD TraverseImpl(JSContextParticipant *that, void *n, - nsCycleCollectionTraversalCallback &cb) + NS_IMETHODIMP Traverse(void *n, nsCycleCollectionTraversalCallback &cb) { JSContext *cx = static_cast(n); @@ -939,22 +932,20 @@ public: } }; -static CCParticipantVTable::Type JSContext_cycleCollectorGlobal = { - NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(JSContextParticipant) -}; +static JSContextParticipant JSContext_cycleCollectorGlobal; // static nsCycleCollectionParticipant* nsXPConnect::JSContextParticipant() { - return JSContext_cycleCollectorGlobal.GetParticipant(); + return &JSContext_cycleCollectorGlobal; } NS_IMETHODIMP_(void) nsXPConnect::NoteJSContext(JSContext *aJSContext, nsCycleCollectionTraversalCallback &aCb) { - aCb.NoteNativeChild(aJSContext, JSContext_cycleCollectorGlobal.GetParticipant()); + aCb.NoteNativeChild(aJSContext, &JSContext_cycleCollectorGlobal); } diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index b8f28b29cb6e..6c0310cf0f8a 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -478,6 +478,7 @@ class nsXPConnect : public nsIXPConnect, public nsIThreadObserver, public nsSupportsWeakReference, public nsCycleCollectionJSRuntime, + public nsCycleCollectionParticipant, public nsIJSRuntimeService, public nsIThreadJSContextStack, public nsIJSEngineTelemetryStats @@ -538,6 +539,13 @@ public: nsresult GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info); nsresult GetInfoForName(const char * name, nsIInterfaceInfo** info); + // nsCycleCollectionParticipant + NS_IMETHOD Root(void *p); + NS_IMETHOD Unlink(void *p); + NS_IMETHOD Unroot(void *p); + NS_IMETHOD Traverse(void *p, + nsCycleCollectionTraversalCallback &cb); + // nsCycleCollectionLanguageRuntime virtual bool NotifyLeaveMainThread(); virtual void NotifyEnterCycleCollectionThread(); @@ -2547,9 +2555,9 @@ public: { NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(XPCWrappedNative, XPCWrappedNative) - static NS_METHOD RootImpl(void *p) { return NS_OK; } - static NS_METHOD UnlinkImpl(void *p); - static NS_METHOD UnrootImpl(void *p) { return NS_OK; } + NS_IMETHOD Root(void *p) { return NS_OK; } + NS_IMETHOD Unlink(void *p); + NS_IMETHOD Unroot(void *p) { return NS_OK; } }; NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(XPCWrappedNative) diff --git a/xpcom/base/nsAgg.h b/xpcom/base/nsAgg.h index 99546b56e868..8b8a2cc449f6 100644 --- a/xpcom/base/nsAgg.h +++ b/xpcom/base/nsAgg.h @@ -72,11 +72,10 @@ class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsXPCOMCycleCollectionParticipant \ { \ public: \ - static NS_METHOD UnlinkImpl(void *p); \ - static NS_METHOD TraverseImpl(NS_CYCLE_COLLECTION_INNERCLASS *that, \ - void *p, \ - nsCycleCollectionTraversalCallback &cb); \ - static NS_METHOD_(void) UnmarkIfPurpleImpl(nsISupports *p) \ + NS_IMETHOD Unlink(void *p); \ + NS_IMETHOD Traverse(void *p, \ + nsCycleCollectionTraversalCallback &cb); \ + NS_IMETHOD_(void) UnmarkIfPurple(nsISupports *p) \ { \ Downcast(p)->UnmarkIfPurple(); \ } \ @@ -264,14 +263,14 @@ _class::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr) \ if (aIID.Equals(IsPartOfAggregated() ? \ NS_GET_IID(nsCycleCollectionParticipant) : \ NS_GET_IID(nsAggregatedCycleCollectionParticipant))) \ - foundInterface = NS_CYCLE_COLLECTION_PARTICIPANT(_class); \ + foundInterface = & NS_CYCLE_COLLECTION_NAME(_class); \ else #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_AGGREGATED(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraverseImpl \ - (NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, \ - void *p, nsCycleCollectionTraversalCallback &cb) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse \ + (void *p, \ + nsCycleCollectionTraversalCallback &cb) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ diff --git a/xpcom/glue/nsCycleCollectionParticipant.cpp b/xpcom/glue/nsCycleCollectionParticipant.cpp index 86868c60e1e1..c9d8fae9d50e 100644 --- a/xpcom/glue/nsCycleCollectionParticipant.cpp +++ b/xpcom/glue/nsCycleCollectionParticipant.cpp @@ -6,9 +6,8 @@ #include "nsCycleCollectionParticipant.h" #include "nsCOMPtr.h" -void -nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name, - void *aClosure) +static void +NoteChild(void *aScriptThing, const char *name, void *aClosure) { nsCycleCollectionTraversalCallback *cb = static_cast(aClosure); @@ -16,8 +15,15 @@ nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name, cb->NoteJSChild(aScriptThing); } +void +nsScriptObjectTracer::TraverseScriptObjects(void *p, + nsCycleCollectionTraversalCallback &cb) +{ + Trace(p, NoteChild, &cb); +} + nsresult -nsXPCOMCycleCollectionParticipant::RootImpl(void *p) +nsXPCOMCycleCollectionParticipant::Root(void *p) { nsISupports *s = static_cast(p); NS_ADDREF(s); @@ -25,13 +31,13 @@ nsXPCOMCycleCollectionParticipant::RootImpl(void *p) } nsresult -nsXPCOMCycleCollectionParticipant::UnlinkImpl(void *p) +nsXPCOMCycleCollectionParticipant::Unlink(void *p) { return NS_OK; } nsresult -nsXPCOMCycleCollectionParticipant::UnrootImpl(void *p) +nsXPCOMCycleCollectionParticipant::Unroot(void *p) { nsISupports *s = static_cast(p); NS_RELEASE(s); @@ -39,21 +45,20 @@ nsXPCOMCycleCollectionParticipant::UnrootImpl(void *p) } nsresult -nsXPCOMCycleCollectionParticipant::TraverseImpl - (nsXPCOMCycleCollectionParticipant* that, void *p, - nsCycleCollectionTraversalCallback &cb) +nsXPCOMCycleCollectionParticipant::Traverse + (void *p, nsCycleCollectionTraversalCallback &cb) { return NS_OK; } void -nsXPCOMCycleCollectionParticipant::UnmarkIfPurpleImpl(nsISupports *n) +nsXPCOMCycleCollectionParticipant::UnmarkIfPurple(nsISupports *n) { } NS_IMETHODIMP_(void) -nsXPCOMCycleCollectionParticipant::TraceImpl(void *p, TraceCallback cb, - void *closure) +nsXPCOMCycleCollectionParticipant::Trace(void *p, TraceCallback cb, + void *closure) { } diff --git a/xpcom/glue/nsCycleCollectionParticipant.h b/xpcom/glue/nsCycleCollectionParticipant.h index e0f403c7b569..adb832a29210 100644 --- a/xpcom/glue/nsCycleCollectionParticipant.h +++ b/xpcom/glue/nsCycleCollectionParticipant.h @@ -6,7 +6,6 @@ #ifndef nsCycleCollectionParticipant_h__ #define nsCycleCollectionParticipant_h__ -#include "mozilla/TypeTraits.h" #include "nsISupports.h" #define NS_CYCLECOLLECTIONPARTICIPANT_IID \ @@ -44,18 +43,7 @@ public: NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionISupports, NS_CYCLECOLLECTIONISUPPORTS_IID) -/** - * Forward declarations - */ class nsCycleCollectionParticipant; -class nsScriptObjectTracer; -class nsXPCOMCycleCollectionParticipant; - -/** - * Callback definitions - */ -typedef void -(* TraceCallback)(void *p, const char *name, void *closure); class NS_NO_VTABLE nsCycleCollectionTraversalCallback { @@ -109,162 +97,27 @@ protected: PRUint32 mFlags; }; -/** - * VTables - * - * When using global scope static initialization for simple types with virtual - * member functions, GCC creates static initializer functions. In order to - * avoid this from happening, cycle collection participants are defined as - * function tables. - * - * The Traverse function may require calling another function from the cycle - * collection participant function table, so a pointer to the function table - * is given to it. Using member function pointers would be less awkward, but - * in MSVC, the size of such a member function pointer depends on the class - * the function is member of. This makes it hard to make them compatible with - * a generic function table. Moreover, static initialization of the function - * table then uses a static initializer function. - * - * Finally, it is not possible to use an initializer list for non-aggregate - * types. Separate types are thus required for static initialization. For - * convenience and to avoid repetitions that could lead to discrepancies, - * function table members for sub-types are declared independently, and - * different aggregate types are defined for static initialization. - */ - -/* Base functions for nsCycleCollectionParticipant */ -template -struct nsCycleCollectionParticipantVTableCommon -{ - nsresult (NS_STDCALL *TraverseReal) - (T *that, void *p, nsCycleCollectionTraversalCallback &cb); - - nsresult (NS_STDCALL *Root)(void *p); - nsresult (NS_STDCALL *Unlink)(void *p); - nsresult (NS_STDCALL *Unroot)(void *p); - - bool (NS_STDCALL *CanSkipReal)(void *p, bool aRemovingAllowed); - bool (NS_STDCALL *CanSkipInCCReal)(void *p); - bool (NS_STDCALL *CanSkipThisReal)(void *p); -}; - -typedef nsCycleCollectionParticipantVTableCommon - nsCycleCollectionParticipantVTable; - -/* Additional functions for nsScriptObjectTracer */ -struct nsScriptObjectTracerVTable -{ - void (NS_STDCALL *Trace)(void *p, TraceCallback cb, void *closure); -}; - -/* Additional functions for nsXPCOMCycleCollectionParticipant */ -struct nsXPCOMCycleCollectionParticipantVTable -{ - void (NS_STDCALL *UnmarkIfPurple)(nsISupports *p); -}; - -/** - * Types for static initialization - * - * Considering T, the cycle collection participant class, subclass of either - * nsCycleCollectionParticipant, nsScriptObjectTracer or - * nsXPCOMCycleCollectionParticipant, static initialization goes as follows: - * - * CCParticipantVTable::type T::_cycleCollectorGlobal = {{...} ...}; - * - * CCParticipantVTable::type automatically defines the right type considering - * what particular cycle collection participant class T derives from. - * - * The NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(classname), - * NS_IMPL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_VTABLE(classname), and - * NS_IMPL_CYCLE_COLLECTION_VTABLE(classname) macros may be used as helpers - * for static initialization: - * - * CCParticipantVTable::type T::_cycleCollectorGlobal = { - * NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(classname); - * }; - */ - -enum nsCycleCollectionParticipantType -{ - eInvalid, - eCycleCollectionParticipant, - eScriptObjectTracer, - eXPCOMCycleCollectionParticipant -}; - -template -struct CCParticipantVTableImpl { }; - -/* CCParticipantVTable for nsCycleCollectionParticipant */ -template -struct CCParticipantVTableImpl -{ - nsCycleCollectionParticipant *GetParticipant() - { - return reinterpret_cast(this); - } - nsCycleCollectionParticipantVTableCommon cycleCollectionParticipant; -}; - -/* CCParticipantVTable for nsScriptObjectTracer */ -template -struct CCParticipantVTableImpl -{ - nsScriptObjectTracer *GetParticipant() - { - return reinterpret_cast(this); - } - nsCycleCollectionParticipantVTableCommon cycleCollectionParticipant; - nsScriptObjectTracerVTable scriptObjectTracer; -}; - -/* CCParticipantVTable for nsXPCOMCycleCollectionParticipant */ -template -struct CCParticipantVTableImpl -{ - nsXPCOMCycleCollectionParticipant *GetParticipant() - { - return reinterpret_cast(this); - } - nsCycleCollectionParticipantVTableCommon cycleCollectionParticipant; - nsScriptObjectTracerVTable scriptObjectTracer; - nsXPCOMCycleCollectionParticipantVTable XPCOMCycleCollectionParticipant; -}; - -template -struct CCParticipantVTable -{ - static const enum nsCycleCollectionParticipantType ParticipantType = - mozilla::IsBaseOf::value ? eXPCOMCycleCollectionParticipant : - mozilla::IsBaseOf::value ? eScriptObjectTracer : - mozilla::IsBaseOf::value ? eCycleCollectionParticipant : - eInvalid; - typedef CCParticipantVTableImpl Type; -}; - -/** - * Participant implementation classes - */ -class nsCycleCollectionParticipant : public nsCycleCollectionParticipantVTable +class NS_NO_VTABLE nsCycleCollectionParticipant { public: - static const bool isSkippable = false; - + nsCycleCollectionParticipant() : mMightSkip(false) {} + nsCycleCollectionParticipant(bool aSkip) : mMightSkip(aSkip) {} + NS_DECLARE_STATIC_IID_ACCESSOR(NS_CYCLECOLLECTIONPARTICIPANT_IID) - // Helper function to avoid painful syntax for member function call using - // the VTable entry. - NS_METHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb) { - return TraverseReal(this, p, cb); - } + NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb) = 0; + + NS_IMETHOD Root(void *p) = 0; + NS_IMETHOD Unlink(void *p) = 0; + NS_IMETHOD Unroot(void *p) = 0; + // If CanSkip returns true, p is removed from the purple buffer during // a call to nsCycleCollector_forgetSkippable(). // Note, calling CanSkip may remove objects from the purple buffer! // If aRemovingAllowed is true, p can be removed from the purple buffer. bool CanSkip(void *p, bool aRemovingAllowed) { - return CanSkipReal ? CanSkipReal(p, aRemovingAllowed) : false; + return mMightSkip ? CanSkipReal(p, aRemovingAllowed) : false; } // If CanSkipInCC returns true, p is skipped when selecting roots for the @@ -272,7 +125,7 @@ public: // Note, calling CanSkipInCC may remove other objects from the purple buffer! bool CanSkipInCC(void *p) { - return CanSkipInCCReal ? CanSkipInCCReal(p) : false; + return mMightSkip ? CanSkipInCCReal(p) : false; } // If CanSkipThis returns true, p is not added to the graph. @@ -280,39 +133,73 @@ public: // change the state of any objects! bool CanSkipThis(void *p) { - return CanSkipThisReal ? CanSkipThisReal(p) : false; + return mMightSkip ? CanSkipThisReal(p) : false; } +protected: + NS_IMETHOD_(bool) CanSkipReal(void *p, bool aRemovingAllowed) + { + NS_ASSERTION(false, "Forgot to implement CanSkipReal?"); + return false; + } + NS_IMETHOD_(bool) CanSkipInCCReal(void *p) + { + NS_ASSERTION(false, "Forgot to implement CanSkipInCCReal?"); + return false; + } + NS_IMETHOD_(bool) CanSkipThisReal(void *p) + { + NS_ASSERTION(false, "Forgot to implement CanSkipThisReal?"); + return false; + } + + bool mMightSkip; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, NS_CYCLECOLLECTIONPARTICIPANT_IID) -class nsScriptObjectTracer - : public nsCycleCollectionParticipant, public nsScriptObjectTracerVTable +#undef IMETHOD_VISIBILITY +#define IMETHOD_VISIBILITY NS_COM_GLUE + +typedef void +(* TraceCallback)(void *p, const char *name, void *closure); + +class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant { public: - static void NS_COM_GLUE NoteJSChild(void *aScriptThing, const char *name, - void *aClosure); + nsScriptObjectTracer() : nsCycleCollectionParticipant(false) {} + nsScriptObjectTracer(bool aSkip) : nsCycleCollectionParticipant(aSkip) {} + + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure) = 0; + void NS_COM_GLUE TraverseScriptObjects(void *p, + nsCycleCollectionTraversalCallback &cb); }; -class nsXPCOMCycleCollectionParticipant - : public nsScriptObjectTracer, public nsXPCOMCycleCollectionParticipantVTable +class NS_COM_GLUE nsXPCOMCycleCollectionParticipant + : public nsScriptObjectTracer { public: - static NS_METHOD TraverseImpl(nsXPCOMCycleCollectionParticipant *that, - void *p, nsCycleCollectionTraversalCallback &cb); + nsXPCOMCycleCollectionParticipant() + : nsScriptObjectTracer(false) {} + nsXPCOMCycleCollectionParticipant(bool aSkip) + : nsScriptObjectTracer(aSkip) {} - static NS_METHOD RootImpl(void *p); - static NS_METHOD UnlinkImpl(void *p); - static NS_METHOD UnrootImpl(void *p); + NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb); - static NS_METHOD_(void) TraceImpl(void *p, TraceCallback cb, void *closure); + NS_IMETHOD Root(void *p); + NS_IMETHOD Unlink(void *p); + NS_IMETHOD Unroot(void *p); - static NS_METHOD_(void) UnmarkIfPurpleImpl(nsISupports *p); + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure); - static bool CheckForRightISupports(nsISupports *s); + NS_IMETHOD_(void) UnmarkIfPurple(nsISupports *p); + + bool CheckForRightISupports(nsISupports *s); }; +#undef IMETHOD_VISIBILITY +#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN + /////////////////////////////////////////////////////////////////////////////// // Helpers for implementing a QI to nsXPCOMCycleCollectionParticipant /////////////////////////////////////////////////////////////////////////////// @@ -326,12 +213,12 @@ public: #define NS_CYCLE_COLLECTION_INNERNAME \ _cycleCollectorGlobal -#define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \ - _class::NS_CYCLE_COLLECTION_INNERNAME.GetParticipant() +#define NS_CYCLE_COLLECTION_NAME(_class) \ + _class::NS_CYCLE_COLLECTION_INNERNAME #define NS_IMPL_QUERY_CYCLE_COLLECTION(_class) \ if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) { \ - *aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(_class); \ + *aInstancePtr = & NS_CYCLE_COLLECTION_NAME(_class); \ return NS_OK; \ } else @@ -370,7 +257,7 @@ public: NS_PRECONDITION(aInstancePtr, "null out param"); \ \ if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) { \ - *aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(_class); \ + *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(_class); \ return NS_OK; \ } \ nsresult rv; @@ -383,8 +270,8 @@ public: /////////////////////////////////////////////////////////////////////////////// #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(_class) \ - NS_METHOD_(bool) \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipImpl(void *p, \ + NS_IMETHODIMP_(bool) \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipReal(void *p, \ bool aRemovingAllowed) \ { \ nsISupports *s = static_cast(p); \ @@ -398,8 +285,8 @@ public: } #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(_class) \ - NS_METHOD_(bool) \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipInCCImpl(void *p) \ + NS_IMETHODIMP_(bool) \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipInCCReal(void *p) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ @@ -412,8 +299,8 @@ public: } #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(_class) \ - NS_METHOD_(bool) \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipThisImpl(void *p) \ + NS_IMETHODIMP_(bool) \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipThisReal(void *p) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ @@ -430,8 +317,8 @@ public: /////////////////////////////////////////////////////////////////////////////// #define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ @@ -439,18 +326,18 @@ public: _class *tmp = Downcast(s); #define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ "not the nsISupports pointer we expect"); \ _class *tmp = static_cast<_class*>(Downcast(s)); \ - NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::UnlinkImpl(s); + NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Unlink(s); #define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p) \ { \ _class *tmp = static_cast<_class*>(p); @@ -469,8 +356,8 @@ public: } #define NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p) \ { \ NS_ASSERTION(CheckForRightISupports(static_cast(p)), \ "not the nsISupports pointer we expect"); \ @@ -478,8 +365,8 @@ public: } #define NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p) \ { \ return NS_OK; \ } @@ -493,9 +380,9 @@ public: cb.DescribeRefCountedNode(_refcnt, sizeof(_class), #_class); #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraverseImpl \ - (NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, void *p,\ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse \ + (void *p, \ nsCycleCollectionTraversalCallback &cb) \ { \ nsISupports *s = static_cast(p); \ @@ -515,15 +402,15 @@ public: #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base_class) \ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \ - if (NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::TraverseImpl(that, s, cb) \ - == NS_SUCCESS_INTERRUPTED_TRAVERSE) { \ + if (NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Traverse(s, cb) == \ + NS_SUCCESS_INTERRUPTED_TRAVERSE) { \ return NS_SUCCESS_INTERRUPTED_TRAVERSE; \ } #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(_class) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraverseImpl \ - (NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, void *p,\ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse \ + (void *p, \ nsCycleCollectionTraversalCallback &cb) \ { \ _class *tmp = static_cast<_class*>(p); \ @@ -566,7 +453,7 @@ public: #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(_ptr, _ptr_class, _name) \ PR_BEGIN_MACRO \ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, _name); \ - cb.NoteNativeChild(_ptr, NS_CYCLE_COLLECTION_PARTICIPANT(_ptr_class)); \ + cb.NoteNativeChild(_ptr, &NS_CYCLE_COLLECTION_NAME(_ptr_class)); \ PR_END_MACRO; #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(_field, _field_class) \ @@ -598,7 +485,7 @@ public: #_field) #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS \ - that->Trace(p, &nsScriptObjectTracer::NoteJSChild, &cb); + TraverseScriptObjects(p, cb); #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \ return NS_OK; \ @@ -610,9 +497,9 @@ public: #define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class) \ void \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraceImpl(void *p, \ - TraceCallback aCallback, \ - void *aClosure) \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p, \ + TraceCallback aCallback, \ + void *aClosure) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ @@ -621,23 +508,23 @@ public: #define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(_class, _base_class) \ void \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraceImpl(void *p, \ - TraceCallback aCallback, \ - void *aClosure) \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p, \ + TraceCallback aCallback, \ + void *aClosure) \ { \ nsISupports *s = static_cast(p); \ NS_ASSERTION(CheckForRightISupports(s), \ "not the nsISupports pointer we expect"); \ _class *tmp = static_cast<_class*>(Downcast(s)); \ - NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::TraceImpl(s, \ - aCallback, \ - aClosure); + NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Trace(s, \ + aCallback, \ + aClosure); #define NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(_class) \ void \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraceImpl(void *p, \ - TraceCallback aCallback, \ - void *aClosure) \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p, \ + TraceCallback aCallback, \ + void *aClosure) \ { \ _class *tmp = static_cast<_class*>(p); @@ -666,14 +553,13 @@ public: /////////////////////////////////////////////////////////////////////////////// #define NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE \ - static CCParticipantVTable::Type \ - NS_CYCLE_COLLECTION_INNERNAME; + static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; #define NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base) \ public: \ - static NS_METHOD TraverseImpl(NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, \ - void *p, nsCycleCollectionTraversalCallback &cb); \ - static NS_METHOD_(void) UnmarkIfPurpleImpl(nsISupports *s) \ + NS_IMETHOD Traverse(void *p, \ + nsCycleCollectionTraversalCallback &cb); \ + NS_IMETHOD_(void) UnmarkIfPurple(nsISupports *s) \ { \ Downcast(s)->UnmarkIfPurple(); \ } \ @@ -688,7 +574,7 @@ public: \ #define NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \ NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base) \ - static NS_METHOD UnlinkImpl(void *p); + NS_IMETHOD Unlink(void *p); #define NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _base) \ class NS_CYCLE_COLLECTION_INNERCLASS \ @@ -706,11 +592,13 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsXPCOMCycleCollectionParticipant \ { \ +public: \ + NS_CYCLE_COLLECTION_INNERCLASS () : nsXPCOMCycleCollectionParticipant(true) {} \ NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \ - static const bool isSkippable = true; \ - static NS_METHOD_(bool) CanSkipImpl(void *p, bool aRemovingAllowed); \ - static NS_METHOD_(bool) CanSkipInCCImpl(void *p); \ - static NS_METHOD_(bool) CanSkipThisImpl(void *p); \ +protected: \ + NS_IMETHOD_(bool) CanSkipReal(void *p, bool aRemovingAllowed); \ + NS_IMETHOD_(bool) CanSkipInCCReal(void *p); \ + NS_IMETHOD_(bool) CanSkipThisReal(void *p); \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE @@ -725,15 +613,15 @@ class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsXPCOMCycleCollectionParticipant \ { \ NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _class) \ - static NS_METHOD RootImpl(void *p) \ + NS_IMETHOD Root(void *p) \ { \ return NS_OK; \ } \ - static NS_METHOD UnlinkImpl(void *p) \ + NS_IMETHOD Unlink(void *p) \ { \ return NS_OK; \ } \ - static NS_METHOD UnrootImpl(void *p) \ + NS_IMETHOD Unroot(void *p) \ { \ return NS_OK; \ } \ @@ -745,7 +633,7 @@ class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsXPCOMCycleCollectionParticipant \ { \ NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \ - static NS_METHOD_(void) TraceImpl(void *p, TraceCallback cb, void *closure); \ + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure); \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE @@ -753,12 +641,14 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsXPCOMCycleCollectionParticipant \ { \ +public: \ + NS_CYCLE_COLLECTION_INNERCLASS () : nsXPCOMCycleCollectionParticipant(true) {} \ NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \ - static const bool isSkippable = true; \ - static NS_METHOD_(void) TraceImpl(void *p, TraceCallback cb, void *closure); \ - static NS_METHOD_(bool) CanSkipImpl(void *p, bool aRemovingAllowed); \ - static NS_METHOD_(bool) CanSkipInCCImpl(void *p); \ - static NS_METHOD_(bool) CanSkipThisImpl(void *p); \ + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure); \ +protected: \ + NS_IMETHOD_(bool) CanSkipReal(void *p, bool aRemovingAllowed); \ + NS_IMETHOD_(bool) CanSkipInCCReal(void *p); \ + NS_IMETHOD_(bool) CanSkipThisReal(void *p); \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE @@ -770,12 +660,18 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE class NS_CYCLE_COLLECTION_INNERCLASS \ : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) \ { \ +public: \ + NS_CYCLE_COLLECTION_INNERCLASS () \ + : NS_CYCLE_COLLECTION_CLASSNAME(_base_class)() \ + { \ + mMightSkip = true; \ + } \ + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure); \ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \ - static const bool isSkippable = true; \ - static NS_METHOD_(void) TraceImpl(void *p, TraceCallback cb, void *closure); \ - static NS_METHOD_(bool) CanSkipImpl(void *p, bool aRemovingAllowed); \ - static NS_METHOD_(bool) CanSkipInCCImpl(void *p); \ - static NS_METHOD_(bool) CanSkipThisImpl(void *p); \ +protected: \ + NS_IMETHOD_(bool) CanSkipReal(void *p, bool aRemovingAllowed); \ + NS_IMETHOD_(bool) CanSkipInCCReal(void *p); \ + NS_IMETHOD_(bool) CanSkipThisReal(void *p); \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE @@ -785,8 +681,8 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, \ _base_class) \ public: \ - static NS_METHOD TraverseImpl(NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, \ - void *p, nsCycleCollectionTraversalCallback &cb); \ + NS_IMETHOD Traverse(void *p, \ + nsCycleCollectionTraversalCallback &cb); \ static _class* Downcast(nsISupports* s) \ { \ return static_cast<_class*>(static_cast<_base_class*>( \ @@ -795,7 +691,7 @@ public: \ #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, _base_class) \ - static NS_METHOD UnlinkImpl(void *p); + NS_IMETHOD Unlink(void *p); #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class) \ class NS_CYCLE_COLLECTION_INNERCLASS \ @@ -821,8 +717,9 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE class NS_CYCLE_COLLECTION_INNERCLASS \ : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) \ { \ +public: \ + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure); \ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \ - static NS_METHOD_(void) TraceImpl(void *p, TraceCallback cb, void *closure); \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE @@ -837,76 +734,22 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE { \ } \ -/** - * Dummy class with a definition for CanSkip* function members, but no - * implementation. - * Implementation was added to please Win PGO. (See bug 765159) - */ -struct SkippableDummy -{ - static NS_METHOD_(bool) CanSkipImpl(void *p, bool aRemovingAllowed) { return false; } - static NS_METHOD_(bool) CanSkipInCCImpl(void *p) { return false; } - static NS_METHOD_(bool) CanSkipThisImpl(void *p) { return false; } -}; - -/** - * Skippable defines a class that always has definitions for CanSkip* - * function members, so that T::isSkippable ? &Skippable::CanSkip* : NULL - * can compile when T::isSkippable is false and T doesn't have CanSkip* - * definitions (which, as not being skippable, it's not supposed to have). - */ -template -struct Skippable - : public mozilla::Conditional::Type -{ }; - -#define NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(_class) \ - { \ - &_class::TraverseImpl, \ - &_class::RootImpl, \ - &_class::UnlinkImpl, \ - &_class::UnrootImpl, \ - _class::isSkippable ? &Skippable<_class>::CanSkipImpl : NULL, \ - _class::isSkippable ? &Skippable<_class>::CanSkipInCCImpl : NULL, \ - _class::isSkippable ? &Skippable<_class>::CanSkipThisImpl : NULL \ - } - -#define NS_IMPL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_VTABLE(_class) \ - NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(_class), \ - { &_class::TraceImpl } - -#define NS_IMPL_CYCLE_COLLECTION_VTABLE(_class) \ - NS_IMPL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_VTABLE(_class), \ - { &_class::UnmarkIfPurpleImpl } - -#define NS_IMPL_CYCLE_COLLECTION_NATIVE_CLASS(_class) \ - CCParticipantVTable \ - ::Type _class::NS_CYCLE_COLLECTION_INNERNAME = \ - { NS_IMPL_CYCLE_COLLECTION_NATIVE_VTABLE(NS_CYCLE_COLLECTION_CLASSNAME(_class)) }; - -#define NS_IMPL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class) \ - CCParticipantVTable \ - ::Type _class::NS_CYCLE_COLLECTION_INNERNAME = \ - { NS_IMPL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_VTABLE(NS_CYCLE_COLLECTION_CLASSNAME(_class)) }; - #define NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \ - CCParticipantVTable \ - ::Type _class::NS_CYCLE_COLLECTION_INNERNAME = \ - { NS_IMPL_CYCLE_COLLECTION_VTABLE(NS_CYCLE_COLLECTION_CLASSNAME(_class)) }; + NS_CYCLE_COLLECTION_CLASSNAME(_class) NS_CYCLE_COLLECTION_NAME(_class); -#define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \ +#define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY \ public: \ - static NS_METHOD RootImpl(void *n); \ - static NS_METHOD UnlinkImpl(void *n); \ - static NS_METHOD UnrootImpl(void *n); \ - static NS_METHOD TraverseImpl(NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, \ - void *n, nsCycleCollectionTraversalCallback &cb); + NS_IMETHOD Root(void *n); \ + NS_IMETHOD Unlink(void *n); \ + NS_IMETHOD Unroot(void *n); \ + NS_IMETHOD Traverse(void *n, \ + nsCycleCollectionTraversalCallback &cb); #define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(_class) \ class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsCycleCollectionParticipant \ { \ - NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \ + NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE @@ -914,15 +757,14 @@ struct Skippable class NS_CYCLE_COLLECTION_INNERCLASS \ : public nsScriptObjectTracer \ { \ - NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \ - static NS_METHOD_(void) TraceImpl(void *p, TraceCallback cb, \ - void *closure); \ + NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY \ + NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure); \ }; \ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE #define NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(_class, _root_function) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::RootImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Root(void *p) \ { \ _class *tmp = static_cast<_class*>(p); \ tmp->_root_function(); \ @@ -930,8 +772,8 @@ struct Skippable } #define NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(_class, _unroot_function) \ - NS_METHOD \ - NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnrootImpl(void *p) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unroot(void *p) \ { \ _class *tmp = static_cast<_class*>(p); \ tmp->_unroot_function(); \