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
parent 205e1ce2f3
commit d79aacc7cc
3 changed files with 43 additions and 10 deletions

View File

@ -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)

View File

@ -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<nsIArray> inst = NS_IsMainThread() ? new nsArrayCC : new nsArray;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
return inst->QueryInterface(aIID, aResult);
}

View File

@ -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