зеркало из https://github.com/mozilla/gecko-dev.git
Bug 906503 - Remove nsIExceptionProvider; r=bholley
It is replaced by a direct special case in the caller.
This commit is contained in:
Родитель
74462466d7
Коммит
05f294ce31
|
@ -22,6 +22,7 @@ EXPORTS += [
|
||||||
'nsDOMCID.h',
|
'nsDOMCID.h',
|
||||||
'nsDOMClassInfoClasses.h',
|
'nsDOMClassInfoClasses.h',
|
||||||
'nsDOMClassInfoID.h',
|
'nsDOMClassInfoID.h',
|
||||||
|
'nsDOMException.h',
|
||||||
'nsDOMJSUtils.h',
|
'nsDOMJSUtils.h',
|
||||||
'nsDOMNavigationTiming.h',
|
'nsDOMNavigationTiming.h',
|
||||||
'nsDOMString.h',
|
'nsDOMString.h',
|
||||||
|
|
|
@ -33,8 +33,6 @@
|
||||||
|
|
||||||
using mozilla::dom::GetNameSpaceManager;
|
using mozilla::dom::GetNameSpaceManager;
|
||||||
|
|
||||||
nsIExceptionProvider* gExceptionProvider = nullptr;
|
|
||||||
|
|
||||||
nsDOMScriptObjectFactory::nsDOMScriptObjectFactory()
|
nsDOMScriptObjectFactory::nsDOMScriptObjectFactory()
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIObserverService> observerService =
|
nsCOMPtr<nsIObserverService> observerService =
|
||||||
|
@ -43,20 +41,6 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory()
|
||||||
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIExceptionProvider> provider = new nsDOMExceptionProvider();
|
|
||||||
nsCOMPtr<nsIExceptionService> xs =
|
|
||||||
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
|
|
||||||
|
|
||||||
if (xs) {
|
|
||||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM);
|
|
||||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_SVG);
|
|
||||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH);
|
|
||||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
||||||
xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_FILEHANDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_ASSERTION(!gExceptionProvider, "Registered twice?!");
|
|
||||||
provider.swap(gExceptionProvider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory)
|
NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory)
|
||||||
|
@ -121,26 +105,6 @@ nsDOMScriptObjectFactory::Observe(nsISupports *aSubject,
|
||||||
|
|
||||||
nsGlobalWindow::ShutDown();
|
nsGlobalWindow::ShutDown();
|
||||||
nsDOMClassInfo::ShutDown();
|
nsDOMClassInfo::ShutDown();
|
||||||
|
|
||||||
if (gExceptionProvider) {
|
|
||||||
nsCOMPtr<nsIExceptionService> xs =
|
|
||||||
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
|
|
||||||
|
|
||||||
if (xs) {
|
|
||||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
|
||||||
NS_ERROR_MODULE_DOM);
|
|
||||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
|
||||||
NS_ERROR_MODULE_SVG);
|
|
||||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
|
||||||
NS_ERROR_MODULE_DOM_XPATH);
|
|
||||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
|
||||||
NS_ERROR_MODULE_DOM_INDEXEDDB);
|
|
||||||
xs->UnregisterExceptionProvider(gExceptionProvider,
|
|
||||||
NS_ERROR_MODULE_DOM_FILEHANDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_RELEASE(gExceptionProvider);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -166,31 +130,3 @@ nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName,
|
||||||
aHasClassInterface,
|
aHasClassInterface,
|
||||||
aConstructorCID);
|
aConstructorCID);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsDOMExceptionProvider::GetException(nsresult result,
|
|
||||||
nsIException *aDefaultException,
|
|
||||||
nsIException **_retval)
|
|
||||||
{
|
|
||||||
if (!NS_IsMainThread()) {
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (NS_ERROR_GET_MODULE(result))
|
|
||||||
{
|
|
||||||
case NS_ERROR_MODULE_DOM:
|
|
||||||
case NS_ERROR_MODULE_SVG:
|
|
||||||
case NS_ERROR_MODULE_DOM_XPATH:
|
|
||||||
case NS_ERROR_MODULE_DOM_FILE:
|
|
||||||
case NS_ERROR_MODULE_DOM_INDEXEDDB:
|
|
||||||
case NS_ERROR_MODULE_DOM_FILEHANDLE:
|
|
||||||
return NS_NewDOMException(result, aDefaultException, _retval);
|
|
||||||
default:
|
|
||||||
NS_WARNING("Trying to create an exception for the wrong error module.");
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
NS_NOTREACHED("Not reached");
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include "nsIDOMScriptObjectFactory.h"
|
#include "nsIDOMScriptObjectFactory.h"
|
||||||
#include "nsIObserver.h"
|
#include "nsIObserver.h"
|
||||||
#include "nsIExceptionService.h"
|
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
|
||||||
class nsDOMScriptObjectFactory MOZ_FINAL : public nsIDOMScriptObjectFactory,
|
class nsDOMScriptObjectFactory MOZ_FINAL : public nsIDOMScriptObjectFactory,
|
||||||
|
@ -47,9 +46,3 @@ public:
|
||||||
const nsCID *aConstructorCID) MOZ_OVERRIDE;
|
const nsCID *aConstructorCID) MOZ_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
class nsDOMExceptionProvider MOZ_FINAL : public nsIExceptionProvider
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
|
||||||
NS_DECL_NSIEXCEPTIONPROVIDER
|
|
||||||
};
|
|
||||||
|
|
|
@ -2853,10 +2853,10 @@ nsJSContext::EnsureStatics()
|
||||||
obs->AddObserver(observer, "memory-pressure", false);
|
obs->AddObserver(observer, "memory-pressure", false);
|
||||||
obs->AddObserver(observer, "quit-application", false);
|
obs->AddObserver(observer, "quit-application", false);
|
||||||
|
|
||||||
// We need to explicitly get the nsIDOMScriptObjectFactory service in order
|
// Bug 907848 - We need to explicitly get the nsIDOMScriptObjectFactory
|
||||||
// to force its constructor to run, which registers various exceptions
|
// service in order to force its constructor to run, which registers a
|
||||||
// providers and other things. It would be nice to make this more explicit
|
// shutdown observer. It would be nice to make this more explicit and less
|
||||||
// and less side-effect-y.
|
// side-effect-y.
|
||||||
nsCOMPtr<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID);
|
nsCOMPtr<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID);
|
||||||
if (!factory) {
|
if (!factory) {
|
||||||
MOZ_CRASH();
|
MOZ_CRASH();
|
||||||
|
|
|
@ -3,16 +3,18 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "nsExceptionService.h"
|
||||||
|
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/DebugOnly.h"
|
#include "mozilla/DebugOnly.h"
|
||||||
|
#include "mozilla/Services.h"
|
||||||
#include "nsISupports.h"
|
|
||||||
#include "nsExceptionService.h"
|
|
||||||
#include "nsIServiceManager.h"
|
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsDOMException.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsThreadUtils.h"
|
||||||
#include "pratom.h"
|
#include "pratom.h"
|
||||||
#include "prthread.h"
|
#include "prthread.h"
|
||||||
#include "mozilla/Services.h"
|
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
@ -21,24 +23,6 @@ static const unsigned BAD_TLS_INDEX = (unsigned) -1;
|
||||||
#define CHECK_SERVICE_USE_OK() if (!sLock) return NS_ERROR_NOT_INITIALIZED
|
#define CHECK_SERVICE_USE_OK() if (!sLock) return NS_ERROR_NOT_INITIALIZED
|
||||||
#define CHECK_MANAGER_USE_OK() if (!mService || !nsExceptionService::sLock) return NS_ERROR_NOT_INITIALIZED
|
#define CHECK_MANAGER_USE_OK() if (!mService || !nsExceptionService::sLock) return NS_ERROR_NOT_INITIALIZED
|
||||||
|
|
||||||
// A key for our registered module providers hashtable
|
|
||||||
class nsProviderKey : public nsHashKey {
|
|
||||||
protected:
|
|
||||||
uint32_t mKey;
|
|
||||||
public:
|
|
||||||
nsProviderKey(uint32_t key) : mKey(key) {}
|
|
||||||
uint32_t HashCode(void) const {
|
|
||||||
return mKey;
|
|
||||||
}
|
|
||||||
bool Equals(const nsHashKey *aKey) const {
|
|
||||||
return mKey == ((const nsProviderKey *) aKey)->mKey;
|
|
||||||
}
|
|
||||||
nsHashKey *Clone() const {
|
|
||||||
return new nsProviderKey(mKey);
|
|
||||||
}
|
|
||||||
uint32_t GetValue() { return mKey; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Exception Manager definition **/
|
/** Exception Manager definition **/
|
||||||
class nsExceptionManager MOZ_FINAL : public nsIExceptionManager
|
class nsExceptionManager MOZ_FINAL : public nsIExceptionManager
|
||||||
{
|
{
|
||||||
|
@ -129,7 +113,6 @@ NS_IMPL_ISUPPORTS3(nsExceptionService,
|
||||||
nsIObserver)
|
nsIObserver)
|
||||||
|
|
||||||
nsExceptionService::nsExceptionService()
|
nsExceptionService::nsExceptionService()
|
||||||
: mProviders(4, true) /* small, thread-safe hashtable */
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (PR_ATOMIC_INCREMENT(&totalInstances)!=1) {
|
if (PR_ATOMIC_INCREMENT(&totalInstances)!=1) {
|
||||||
|
@ -174,7 +157,6 @@ void nsExceptionService::ThreadDestruct( void *data )
|
||||||
|
|
||||||
void nsExceptionService::Shutdown()
|
void nsExceptionService::Shutdown()
|
||||||
{
|
{
|
||||||
mProviders.Reset();
|
|
||||||
if (sLock) {
|
if (sLock) {
|
||||||
DropAllThreads();
|
DropAllThreads();
|
||||||
delete sLock;
|
delete sLock;
|
||||||
|
@ -230,30 +212,6 @@ NS_IMETHODIMP nsExceptionService::GetCurrentExceptionManager(nsIExceptionManager
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* void registerErrorProvider (in nsIExceptionProvider provider, in uint32_t moduleCode); */
|
|
||||||
NS_IMETHODIMP nsExceptionService::RegisterExceptionProvider(nsIExceptionProvider *provider, uint32_t errorModule)
|
|
||||||
{
|
|
||||||
CHECK_SERVICE_USE_OK();
|
|
||||||
|
|
||||||
nsProviderKey key(errorModule);
|
|
||||||
if (mProviders.Put(&key, provider)) {
|
|
||||||
NS_WARNING("Registration of exception provider overwrote another provider with the same module code!");
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* void unregisterErrorProvider (in nsIExceptionProvider provider, in uint32_t errorModule); */
|
|
||||||
NS_IMETHODIMP nsExceptionService::UnregisterExceptionProvider(nsIExceptionProvider *provider, uint32_t errorModule)
|
|
||||||
{
|
|
||||||
CHECK_SERVICE_USE_OK();
|
|
||||||
nsProviderKey key(errorModule);
|
|
||||||
if (!mProviders.Remove(&key)) {
|
|
||||||
NS_WARNING("Attempt to unregister an unregistered exception provider!");
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// nsIObserver
|
// nsIObserver
|
||||||
NS_IMETHODIMP nsExceptionService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
|
NS_IMETHODIMP nsExceptionService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
|
||||||
{
|
{
|
||||||
|
@ -275,18 +233,26 @@ nsExceptionService::DoGetExceptionFromProvider(nsresult errCode,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
NS_RELEASE(*_exc);
|
NS_RELEASE(*_exc);
|
||||||
}
|
}
|
||||||
nsProviderKey key(NS_ERROR_GET_MODULE(errCode));
|
|
||||||
nsCOMPtr<nsIExceptionProvider> provider =
|
|
||||||
dont_AddRef((nsIExceptionProvider *)mProviders.Get(&key));
|
|
||||||
|
|
||||||
// No provider so we'll return the default exception
|
switch (NS_ERROR_GET_MODULE(errCode)) {
|
||||||
if (!provider) {
|
case NS_ERROR_MODULE_DOM:
|
||||||
*_exc = defaultException;
|
case NS_ERROR_MODULE_SVG:
|
||||||
NS_IF_ADDREF(*_exc);
|
case NS_ERROR_MODULE_DOM_XPATH:
|
||||||
return NS_OK;
|
case NS_ERROR_MODULE_DOM_INDEXEDDB:
|
||||||
|
case NS_ERROR_MODULE_DOM_FILEHANDLE:
|
||||||
|
if (NS_IsMainThread()) {
|
||||||
|
return NS_NewDOMException(errCode, defaultException, _exc);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider->GetException(errCode, defaultException, _exc);
|
// No provider so we'll return the default exception
|
||||||
|
*_exc = defaultException;
|
||||||
|
NS_IF_ADDREF(*_exc);
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// thread management
|
// thread management
|
||||||
|
|
|
@ -43,10 +43,7 @@ public:
|
||||||
static void DropAllThreads();
|
static void DropAllThreads();
|
||||||
static nsExceptionManager *firstThread;
|
static nsExceptionManager *firstThread;
|
||||||
|
|
||||||
nsSupportsHashtable mProviders;
|
/* Protects the thread list. */
|
||||||
|
|
||||||
/* single lock protects both providers hashtable
|
|
||||||
and thread list */
|
|
||||||
static mozilla::Mutex* sLock;
|
static mozilla::Mutex* sLock;
|
||||||
|
|
||||||
static unsigned tlsIndex;
|
static unsigned tlsIndex;
|
||||||
|
|
|
@ -6,16 +6,6 @@
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
#include "nsIException.idl"
|
#include "nsIException.idl"
|
||||||
|
|
||||||
// An exception provider. These can turn special nsresult codes
|
|
||||||
// into nsIExceptions
|
|
||||||
|
|
||||||
[scriptable, uuid(0577744c-c1d2-47f2-8bcc-ce7a9e5a88fc)]
|
|
||||||
interface nsIExceptionProvider : nsISupports
|
|
||||||
{
|
|
||||||
/** Gets an nsIException or returns NULL if not possible. **/
|
|
||||||
nsIException getException(in nsresult result, in nsIException defaultException);
|
|
||||||
};
|
|
||||||
|
|
||||||
// A ScriptErrorManager for a single thread. These objects
|
// A ScriptErrorManager for a single thread. These objects
|
||||||
// are _not_ thread-safe. Use the ScriptErrorService
|
// are _not_ thread-safe. Use the ScriptErrorService
|
||||||
// to get a script error manager for your current thread.
|
// to get a script error manager for your current thread.
|
||||||
|
@ -36,22 +26,11 @@ interface nsIExceptionManager : nsISupports
|
||||||
|
|
||||||
// The Exception Service. Allows you to get an set exceptions in a thread
|
// The Exception Service. Allows you to get an set exceptions in a thread
|
||||||
// safe manner, or to get an ExceptionManager for your specific thread.
|
// safe manner, or to get an ExceptionManager for your specific thread.
|
||||||
[scriptable, uuid(35A88F54-F267-4414-92A7-191F6454AB52)]
|
[scriptable, uuid(8f9ccabb-a68b-43e3-b570-dd8c3179d2fb)]
|
||||||
interface nsIExceptionService : nsIExceptionManager
|
interface nsIExceptionService : nsIExceptionManager
|
||||||
{
|
{
|
||||||
/** Obtains an exception manager for the current thread. */
|
/** Obtains an exception manager for the current thread. */
|
||||||
readonly attribute nsIExceptionManager currentExceptionManager;
|
readonly attribute nsIExceptionManager currentExceptionManager;
|
||||||
|
|
||||||
/** Installs an "exception provider" which is capable of
|
|
||||||
translating an nsresult into an exception. This enables
|
|
||||||
error providers to return simple nsresults and only provide
|
|
||||||
rich errors when specifically requested. It also has the
|
|
||||||
advantage of allowing code like the DOM to handle all errors
|
|
||||||
in a single function rather than at each XPCOM entry point.
|
|
||||||
NOTE: This interface must be thread-safe - it will be called
|
|
||||||
on whatever thread needs the error translation performed.*/
|
|
||||||
void registerExceptionProvider( in nsIExceptionProvider provider, in uint32_t moduleCode );
|
|
||||||
void unregisterExceptionProvider( in nsIExceptionProvider provider, in uint32_t moduleCode );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче