Bug 471296 nsArray (NS_ARRAY_CONTRACTID) can't be used on a single thread of its creator's choice, r=bsmedberg

This commit is contained in:
timeless@mozdev.org 2009-01-15 20:02:22 -08:00
Родитель 60874a794b
Коммит 266462dbca
3 изменённых файлов: 43 добавлений и 10 удалений

Просмотреть файл

@ -199,7 +199,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsArray)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init)
NS_DECL_CLASSINFO(nsConsoleService) NS_DECL_CLASSINFO(nsConsoleService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService)

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsArray.h" #include "nsArray.h"
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsThreadUtils.h"
// used by IndexOf() // used by IndexOf()
struct findIndexOfClosure struct findIndexOfClosure
@ -50,7 +51,13 @@ struct findIndexOfClosure
static PRBool FindElementCallback(void* aElement, void* aClosure); 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(nsIArray)
NS_INTERFACE_MAP_ENTRY(nsIMutableArray) NS_INTERFACE_MAP_ENTRY(nsIMutableArray)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMutableArray) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMutableArray)
@ -61,14 +68,18 @@ nsArray::~nsArray()
Clear(); Clear();
} }
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsArray)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsArray)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsArray) NS_IMPL_ADDREF(nsArray)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(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(); tmp->Clear();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END 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_NSCOMARRAY(mArray)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -215,3 +226,14 @@ FindElementCallback(void *aElement, void* aClosure)
return PR_TRUE; return PR_TRUE;
} }
NS_METHOD nsArrayConstructor(nsISupports *aOuter, const nsIID& aIID, void **aResult) {
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsCOMPtr<nsIArray> inst = NS_IsMainThread() ? new nsArrayCC : new nsArray;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
return inst->QueryInterface(aIID, aResult);
}

Просмотреть файл

@ -64,15 +64,27 @@ public:
nsArray(const nsCOMArray_base& aBaseArray) : mArray(aBaseArray) nsArray(const nsCOMArray_base& aBaseArray) : mArray(aBaseArray)
{ } { }
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(nsArray)
NS_DECL_NSIARRAY NS_DECL_NSIARRAY
NS_DECL_NSIMUTABLEARRAY NS_DECL_NSIMUTABLEARRAY
private: protected:
~nsArray(); ~nsArray();
nsCOMArray_base mArray; 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 #endif