diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index 7e387138c780..80239b529d9e 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -199,7 +199,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsArray) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init) NS_DECL_CLASSINFO(nsConsoleService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService) diff --git a/xpcom/ds/nsArray.cpp b/xpcom/ds/nsArray.cpp index 6f14b6b65a6c..7da90f3b101d 100644 --- a/xpcom/ds/nsArray.cpp +++ b/xpcom/ds/nsArray.cpp @@ -39,6 +39,7 @@ #include "nsArray.h" #include "nsArrayEnumerator.h" #include "nsWeakReference.h" +#include "nsThreadUtils.h" // used by IndexOf() struct findIndexOfClosure @@ -50,7 +51,13 @@ struct findIndexOfClosure static PRBool FindElementCallback(void* aElement, void* aClosure); -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsArray) +NS_INTERFACE_MAP_BEGIN(nsArray) + NS_INTERFACE_MAP_ENTRY(nsIArray) + NS_INTERFACE_MAP_ENTRY(nsIMutableArray) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMutableArray) +NS_INTERFACE_MAP_END + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsArrayCC) NS_INTERFACE_MAP_ENTRY(nsIArray) NS_INTERFACE_MAP_ENTRY(nsIMutableArray) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMutableArray) @@ -61,14 +68,18 @@ nsArray::~nsArray() Clear(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsArray) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsArray) -NS_IMPL_CYCLE_COLLECTION_CLASS(nsArray) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsArray) +NS_IMPL_ADDREF(nsArray) +NS_IMPL_RELEASE(nsArray) + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsArrayCC) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsArrayCC) + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsArrayCC) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsArrayCC) tmp->Clear(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsArray) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsArrayCC) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mArray) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -215,3 +226,14 @@ FindElementCallback(void *aElement, void* aClosure) return PR_TRUE; } + +NS_METHOD nsArrayConstructor(nsISupports *aOuter, const nsIID& aIID, void **aResult) { + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + nsCOMPtr inst = NS_IsMainThread() ? new nsArrayCC : new nsArray; + if (!inst) + return NS_ERROR_OUT_OF_MEMORY; + + return inst->QueryInterface(aIID, aResult); +} diff --git a/xpcom/ds/nsArray.h b/xpcom/ds/nsArray.h index 7f59888eb70d..2805a8e5bbc4 100644 --- a/xpcom/ds/nsArray.h +++ b/xpcom/ds/nsArray.h @@ -64,15 +64,27 @@ public: nsArray(const nsCOMArray_base& aBaseArray) : mArray(aBaseArray) { } - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(nsArray) + NS_DECL_ISUPPORTS NS_DECL_NSIARRAY NS_DECL_NSIMUTABLEARRAY -private: +protected: ~nsArray(); nsCOMArray_base mArray; }; +class nsArrayCC : public nsArray +{ +public: + nsArrayCC() : nsArray() { } + nsArrayCC(const nsCOMArray_base& aBaseArray) : nsArray(aBaseArray) + { } + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsArrayCC) +}; + +NS_METHOD nsArrayConstructor(nsISupports *aOuter, const nsIID& aIID, void **aResult); + #endif