Bug 455417 - "Exception provider not threadsafe". r+sr=jst.

This commit is contained in:
Ben Turner 2008-09-26 15:48:45 -07:00
Родитель e34531f0f4
Коммит 8cd498054d
2 изменённых файлов: 70 добавлений и 46 удалений

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

@ -68,6 +68,8 @@
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
nsIExceptionProvider* gExceptionProvider = nsnull;
nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
mLoadedAllLanguages(PR_FALSE)
{
@ -78,18 +80,25 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
nsCOMPtr<nsIExceptionProvider> provider(new nsDOMExceptionProvider());
if (provider) {
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM_RANGE);
if (xs) {
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_RANGE);
#ifdef MOZ_SVG
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_SVG);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_SVG);
#endif
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM_XPATH);
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_XPCONNECT);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH);
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_XPCONNECT);
}
NS_ASSERTION(!gExceptionProvider, "Registered twice?!");
provider.swap(gExceptionProvider);
}
// And pre-create the javascript language.
NS_CreateJSRuntime(getter_AddRefs(mLanguageArray[NS_STID_INDEX(nsIProgrammingLanguage::JAVASCRIPT)]));
}
@ -97,7 +106,6 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory)
NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIExceptionProvider)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory)
NS_INTERFACE_MAP_END
@ -287,17 +295,26 @@ nsDOMScriptObjectFactory::Observe(nsISupports *aSubject,
nsGlobalWindow::ShutDown();
nsDOMClassInfo::ShutDown();
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (gExceptionProvider) {
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_DOM_RANGE);
if (xs) {
xs->UnregisterExceptionProvider(gExceptionProvider,
NS_ERROR_MODULE_DOM);
xs->UnregisterExceptionProvider(gExceptionProvider,
NS_ERROR_MODULE_DOM_RANGE);
#ifdef MOZ_SVG
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_SVG);
xs->UnregisterExceptionProvider(gExceptionProvider,
NS_ERROR_MODULE_SVG);
#endif
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_DOM_XPATH);
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_XPCONNECT);
xs->UnregisterExceptionProvider(gExceptionProvider,
NS_ERROR_MODULE_DOM_XPATH);
xs->UnregisterExceptionProvider(gExceptionProvider,
NS_ERROR_MODULE_XPCONNECT);
}
NS_RELEASE(gExceptionProvider);
}
}
@ -325,30 +342,6 @@ CreateXPConnectException(nsresult aResult, nsIException *aDefaultException,
return NS_OK;
}
NS_IMETHODIMP
nsDOMScriptObjectFactory::GetException(nsresult result,
nsIException *aDefaultException,
nsIException **_retval)
{
switch (NS_ERROR_GET_MODULE(result))
{
case NS_ERROR_MODULE_DOM_RANGE:
return NS_NewRangeException(result, aDefaultException, _retval);
#ifdef MOZ_SVG
case NS_ERROR_MODULE_SVG:
return NS_NewSVGException(result, aDefaultException, _retval);
#endif
case NS_ERROR_MODULE_DOM_XPATH:
return NS_NewXPathException(result, aDefaultException, _retval);
case NS_ERROR_MODULE_XPCONNECT:
return CreateXPConnectException(result, aDefaultException, _retval);
case NS_ERROR_MODULE_DOM_FILE:
return NS_NewFileException(result, aDefaultException, _retval);
default:
return NS_NewDOMException(result, aDefaultException, _retval);
}
}
NS_IMETHODIMP
nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName,
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
@ -394,3 +387,31 @@ nsresult NS_GetScriptRuntimeByID(PRUint32 aScriptTypeID,
return rv;
return factory->GetScriptRuntimeByID(aScriptTypeID, aLanguage);
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider)
NS_IMETHODIMP
nsDOMExceptionProvider::GetException(nsresult result,
nsIException *aDefaultException,
nsIException **_retval)
{
switch (NS_ERROR_GET_MODULE(result))
{
case NS_ERROR_MODULE_DOM_RANGE:
return NS_NewRangeException(result, aDefaultException, _retval);
#ifdef MOZ_SVG
case NS_ERROR_MODULE_SVG:
return NS_NewSVGException(result, aDefaultException, _retval);
#endif
case NS_ERROR_MODULE_DOM_XPATH:
return NS_NewXPathException(result, aDefaultException, _retval);
case NS_ERROR_MODULE_XPCONNECT:
return CreateXPConnectException(result, aDefaultException, _retval);
case NS_ERROR_MODULE_DOM_FILE:
return NS_NewFileException(result, aDefaultException, _retval);
default:
return NS_NewDOMException(result, aDefaultException, _retval);
}
NS_NOTREACHED("Not reached");
return NS_ERROR_UNEXPECTED;
}

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

@ -57,8 +57,7 @@
#include "nsIScriptGlobalObject.h" // for misplaced NS_STID_ macros.
class nsDOMScriptObjectFactory : public nsIDOMScriptObjectFactory,
public nsIObserver,
public nsIExceptionProvider
public nsIObserver
{
public:
nsDOMScriptObjectFactory();
@ -68,9 +67,6 @@ public:
// nsIObserver
NS_DECL_NSIOBSERVER
// nsIExceptionProvider
NS_DECL_NSIEXCEPTIONPROVIDER
// nsIDOMScriptObjectFactory
NS_IMETHOD GetScriptRuntime(const nsAString &aLanguageName,
nsIScriptRuntime **aLanguage);
@ -100,3 +96,10 @@ protected:
PRBool mLoadedAllLanguages;
nsCOMPtr<nsIScriptRuntime> mLanguageArray[NS_STID_ARRAY_UBOUND];
};
class nsDOMExceptionProvider : public nsIExceptionProvider
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEXCEPTIONPROVIDER
};