Bug 83426 - Remove DOM exception hack. r=jst, r=dbradley, sr=jband

This commit is contained in:
dbradley%netscape.com 2001-11-01 15:52:53 +00:00
Родитель a025322e1e
Коммит e80e70e9e7
15 изменённых файлов: 313 добавлений и 355 удалений

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

@ -67,12 +67,3 @@ interface nsIDOMDOMException : nsISupports
readonly attribute unsigned long code;
};
[scriptable, uuid(6c88a337-68d3-4409-b0ed-9df34c562cc1)]
interface nsIDOMNSDOMException : nsISupports
{
readonly attribute unsigned long result;
readonly attribute DOMString message;
readonly attribute DOMString name;
DOMString toString();
};

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

@ -60,6 +60,7 @@ enum nsDOMClassInfoID {
eDOMClassInfo_XMLDocument_id,
eDOMClassInfo_DocumentType_id,
eDOMClassInfo_DOMImplementation_id,
eDOMClassInfo_DOMException_id,
eDOMClassInfo_DocumentFragment_id,
eDOMClassInfo_Element_id,
eDOMClassInfo_Attr_id,

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

@ -403,6 +403,8 @@ static nsDOMClassInfoData sClassInfoData[] = {
NODE_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DOMImplementation, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DOMException, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DocumentFragment, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Element, nsElementSH,
@ -1009,6 +1011,11 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMImplementation)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DOMException, nsIDOMDOMException)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMException)
DOM_CLASSINFO_MAP_ENTRY(nsIException)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DocumentFragment, nsIDOMDocumentFragment)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentFragment)
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)

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

@ -39,188 +39,285 @@
#include "nsIDOMDOMException.h"
#include "nsDOMError.h"
#include "nsDOMClassInfo.h"
#include "nsCRT.h"
#include "prprf.h"
#include "nsIScriptGlobalObject.h"
#include "nsReadableUtils.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
class nsDOMException : public nsIDOMNSDOMException
#define DOM_MSG_DEF(val, message) {(val), #val, message},
static struct ResultStruct
{
nsresult mNSResult;
const char* mName;
const char* mMessage;
} gDOMErrorMsgMap[] = {
#include "domerr.msg"
{0, nsnull, nsnull} // sentinel to mark end of array
};
#undef DOM_MSG_DEF
static const ResultStruct *
NSResultToResultStruct(nsresult aNSResult)
{
ResultStruct* result_struct = gDOMErrorMsgMap;
while (result_struct->mName) {
if (aNSResult == result_struct->mNSResult) {
return result_struct;
}
++result_struct;
}
NS_WARNING("Huh, someone is throwing non-DOM errors using the DOM module!");
return nsnull;
}
class nsDOMException : public nsIException,
public nsIDOMDOMException
{
public:
nsDOMException(nsresult aResult,
const char* aName,
const char* aMessage,
const char* aLocation);
nsDOMException(nsresult aNSResult, nsIException* aInner);
virtual ~nsDOMException();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMDOMEXCEPTION
NS_DECL_NSIDOMNSDOMEXCEPTION
// nsIException
NS_DECL_NSIEXCEPTION
protected:
nsresult mResult;
char* mName;
char* mMessage;
char* mLocation;
nsCOMPtr<nsIException> mInner;
};
nsresult
NS_NewDOMException(nsIDOMDOMException** aException,
nsresult aResult,
const char* aName,
const char* aMessage,
const char* aLocation)
nsresult
NS_NewDOMException(nsresult aNSResult, nsIException* aDefaultException,
nsIException** aException)
{
NS_PRECONDITION(nsnull != aException, "null ptr");
if (nsnull == aException) {
return NS_ERROR_NULL_POINTER;
}
*aException = new nsDOMException(aNSResult, aDefaultException);
NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY);
nsDOMException* it = new nsDOMException(aResult,
aName,
aMessage,
aLocation);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(NS_GET_IID(nsIDOMDOMException),
(void**)aException);
NS_ADDREF(*aException);
return NS_OK;
}
nsDOMException::nsDOMException(nsresult aResult,
const char* aName,
const char* aMessage,
const char* aLocation)
: mResult(aResult),
mName(nsnull),
mMessage(nsnull),
mLocation(nsnull)
nsDOMException::nsDOMException(nsresult aNSResult, nsIException* aInner)
: mResult(aNSResult), mInner(aInner)
{
NS_INIT_ISUPPORTS();
if (aName) {
mName = nsCRT::strdup(aName);
}
if (aMessage) {
mMessage = nsCRT::strdup(aMessage);
}
if (aLocation) {
mLocation = nsCRT::strdup(aLocation);
}
}
nsDOMException::~nsDOMException()
{
if (mName) {
nsCRT::free(mName);
}
if (mMessage) {
nsCRT::free(mMessage);
}
if (mLocation) {
nsCRT::free(mLocation);
}
}
// XPConnect interface list for nsDOMException
NS_CLASSINFO_MAP_BEGIN(DOMException)
NS_CLASSINFO_MAP_ENTRY(nsIException)
NS_CLASSINFO_MAP_ENTRY(nsIDOMDOMException)
NS_CLASSINFO_MAP_END
// QueryInterface implementation for nsDOMException
NS_INTERFACE_MAP_BEGIN(nsDOMException)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException)
NS_INTERFACE_MAP_ENTRY(nsIException)
NS_INTERFACE_MAP_ENTRY(nsIDOMDOMException)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMException)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMException)
NS_IMPL_RELEASE(nsDOMException)
NS_IMETHODIMP
nsDOMException::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(NS_GET_IID(nsIDOMDOMException))) {
*aInstancePtrResult = (void*) ((nsIDOMDOMException*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*)(nsISupports*)(nsIDOMDOMException*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsDOMException::GetCode(PRUint32* aCode)
{
if (NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM) {
*aCode = NS_ERROR_GET_CODE(mResult);
}
else {
} else {
NS_WARNING("Non DOM nsresult passed to a DOM exception!");
*aCode = (PRUint32)mResult;
}
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsDOMException::GetMessage(char **aMessage)
{
const ResultStruct *rs = NSResultToResultStruct(mResult);
if (rs) {
*aMessage = nsCRT::strdup(rs->mMessage);
} else {
*aMessage = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetResult(PRUint32* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mResult;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetMessage(nsAWritableString& aMessage)
NS_IMETHODIMP
nsDOMException::GetName(char **aName)
{
if (mMessage) {
CopyASCIItoUCS2(nsDependentCString(mMessage), aMessage);
NS_ENSURE_ARG_POINTER(aName);
const ResultStruct *rs = NSResultToResultStruct(mResult);
if (rs) {
*aName = nsCRT::strdup(rs->mName);
} else {
*aName = nsnull;
}
else {
aMessage.Truncate();
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetName(nsAWritableString& aName)
NS_IMETHODIMP
nsDOMException::GetFilename(char **aFilename)
{
if (mName) {
CopyASCIItoUCS2(nsDependentCString(mName), aName);
if (mInner) {
return mInner->GetFilename(aFilename);
}
else {
aName.Truncate();
}
NS_ENSURE_ARG_POINTER(aFilename);
*aFilename = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::ToString(nsAWritableString& aReturn)
NS_IMETHODIMP
nsDOMException::GetLineNumber(PRUint32 *aLineNumber)
{
if (mInner) {
return mInner->GetLineNumber(aLineNumber);
}
NS_ENSURE_ARG_POINTER(aLineNumber);
*aLineNumber = 0;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetColumnNumber(PRUint32 *aColumnNumber)
{
if (mInner) {
return mInner->GetColumnNumber(aColumnNumber);
}
NS_ENSURE_ARG_POINTER(aColumnNumber);
*aColumnNumber = 0;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetLocation(nsIStackFrame **aLocation)
{
if (mInner) {
return mInner->GetLocation(aLocation);
}
NS_ENSURE_ARG_POINTER(aLocation);
*aLocation = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetInner(nsIException **aInner)
{
NS_ENSURE_ARG_POINTER(aInner);
*aInner = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::GetData(nsISupports **aData)
{
if (mInner) {
return mInner->GetData(aData);
}
NS_ENSURE_ARG_POINTER(aData);
*aData = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMException::ToString(char **aReturn)
{
*aReturn = nsCRT::strdup("foo");
const ResultStruct *rs = NSResultToResultStruct(mResult);
static const char defaultMsg[] = "<no message>";
static const char defaultLocation[] = "<unknown>";
static const char defaultName[] = "<unknown>";
static const char format[] =
"[Exception... \"%s\" code: \"%d\" nsresult: \"0x%x (%s)\" location: \"%s\"]";
const char* msg = mMessage ? mMessage : defaultMsg;
const char* location = mLocation ? mLocation : defaultLocation;
const char* resultName = mName ? mName : defaultName;
nsCAutoString location;
if (mInner) {
nsXPIDLCString filename;
mInner->GetFilename(getter_Copies(filename));
if (!filename.IsEmpty()) {
PRUint32 line_nr = 0;
mInner->GetLineNumber(&line_nr);
char *temp = PR_smprintf("%s Line: %d", filename.get(), line_nr);
if (temp) {
location.Assign(temp);
PR_smprintf_free(temp);
}
}
}
if (location.IsEmpty()) {
location = defaultLocation;
}
const char* msg = rs ? rs->mMessage : defaultMsg;
const char* resultName = rs ? rs->mName : defaultName;
PRUint32 code;
GetCode(&code);
char* temp = PR_smprintf(format, msg, code, mResult, resultName, location);
if (temp) {
CopyASCIItoUCS2(nsDependentCString(temp), aReturn);
PR_smprintf_free(temp);
}
return NS_OK;
*aReturn = PR_smprintf(format, msg, code, mResult, resultName,
location.get());
return *aReturn ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

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

@ -1611,8 +1611,6 @@ nsJSEnvironment::nsJSEnvironment()
nsJSEnvironment::~nsJSEnvironment()
{
if (--globalCount == 0) {
nsJSUtils::ClearCachedSecurityManager();
delete gNameSpaceManager;
gNameSpaceManager = nsnull;
}

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

@ -48,48 +48,13 @@
#include "jsapi.h"
#include "jsdbgapi.h"
#include "prprf.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsString.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIComponentManager.h"
#include "nsIScriptEventListener.h"
#include "nsIServiceManager.h"
#include "nsIXPConnect.h"
#include "nsIDOMDOMException.h"
#include "nsDOMError.h"
#include "nsCOMPtr.h"
#include "nsIScriptSecurityManager.h"
#include "nsIJSNativeInitializer.h"
static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);
static struct ResultMap
{nsresult rv; const char* name; const char* format;} map[] = {
#define DOM_MSG_DEF(val, format) \
{(val), #val, format},
#include "domerr.msg"
#undef DOM_MSG_DEF
{0,0,0} // sentinel to mark end of array
};
PRBool
nsJSUtils::NameAndFormatForNSResult(nsresult rv, const char** name,
const char** format)
{
for (ResultMap* p = map; p->name; p++)
{
if (rv == p->rv)
{
if (name) *name = p->name;
if (format) *format = p->format;
return PR_TRUE;
}
}
return PR_FALSE;
}
JSBool
nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename,
@ -126,55 +91,6 @@ nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename,
return JS_FALSE;
}
JSBool
nsJSUtils::ReportError(JSContext* aContext, JSObject* aObj, nsresult aResult,
const char* aMessage)
{
const char* name = nsnull;
const char* format = nsnull;
// Get the name and message
if (!aMessage)
NameAndFormatForNSResult(aResult, &name, &format);
else
format = aMessage;
const char* filename;
PRUint32 lineno;
char* location = nsnull;
if (nsJSUtils::GetCallingLocation(aContext, &filename, &lineno))
location = PR_smprintf("%s Line: %d", filename, lineno);
nsCOMPtr<nsIDOMDOMException> exc;
nsresult rv = NS_NewDOMException(getter_AddRefs(exc),
aResult,
name,
format,
location);
if (location) {
PR_smprintf_free(location);
}
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(exc);
if (owner) {
nsCOMPtr<nsIScriptContext> scriptCX;
GetStaticScriptContext(aContext, aObj, getter_AddRefs(scriptCX));
if (scriptCX) {
JSObject* obj;
rv = owner->GetScriptObject(scriptCX, (void**)&obj);
if (NS_SUCCEEDED(rv)) {
::JS_SetPendingException(aContext, OBJECT_TO_JSVAL(obj));
}
}
}
}
return JS_FALSE;
}
void
nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext,
jsval* aReturn)
@ -198,7 +114,7 @@ nsJSUtils::ConvertJSValToXPCObject(nsISupports** aSupports, REFNSIID aIID,
}
else if (JSVAL_IS_OBJECT(aValue)) {
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(kXPConnectCID, &rv));
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
if (NS_FAILED(rv))
return JS_FALSE;
@ -322,51 +238,3 @@ nsJSUtils::GetDynamicScriptContext(JSContext *aContext,
(void**)aScriptContext);
}
JSBool PR_CALLBACK
nsJSUtils::CheckAccess(JSContext *cx, JSObject *obj, jsid id,
JSAccessMode mode, jsval *vp)
{
if (mode == JSACC_WATCH) {
jsval value, dummy;
if (!::JS_IdToValue(cx, id, &value))
return JS_FALSE;
JSString *str = ::JS_ValueToString(cx, value);
if (!str)
return JS_FALSE;
return ::JS_GetUCProperty(cx, obj, ::JS_GetStringChars(str),
::JS_GetStringLength(str), &dummy);
}
return JS_TRUE;
}
nsIScriptSecurityManager *
nsJSUtils::GetSecurityManager(JSContext *cx, JSObject *obj)
{
if (!mCachedSecurityManager) {
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
nsJSUtils::ReportError(cx, obj, NS_ERROR_DOM_SECMAN_ERR);
return nsnull;
}
mCachedSecurityManager = secMan;
NS_ADDREF(mCachedSecurityManager);
}
return mCachedSecurityManager;
}
void
nsJSUtils::ClearCachedSecurityManager()
{
if (mCachedSecurityManager) {
NS_RELEASE(mCachedSecurityManager);
mCachedSecurityManager = nsnull;
}
}
nsIScriptSecurityManager *nsJSUtils::mCachedSecurityManager;

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

@ -60,9 +60,6 @@ public:
static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename,
PRUint32 *aLineno);
static JSBool ReportError(JSContext* aContext, JSObject* aObj,
nsresult aResult, const char* aMessage=nsnull);
static void ConvertStringToJSVal(const nsString& aProp, JSContext* aContext,
jsval* aReturn);
@ -86,20 +83,6 @@ public:
static nsresult GetDynamicScriptContext(JSContext *aContext,
nsIScriptContext** aScriptContext);
static JSBool PR_CALLBACK CheckAccess(JSContext *cx, JSObject *obj,
jsid id, JSAccessMode mode, jsval *vp);
static nsIScriptSecurityManager *GetSecurityManager(JSContext *cx,
JSObject *obj);
static void ClearCachedSecurityManager();
protected:
static PRBool NameAndFormatForNSResult(nsresult rv, const char** name,
const char** format);
static nsIScriptSecurityManager *mCachedSecurityManager;
};
#endif /* nsJSUtils_h__ */

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

@ -46,6 +46,7 @@
#include "nsGlobalWindow.h"
#include "nsIObserverService.h"
#include "nsIJSContextStack.h"
#include "nsIExceptionService.h"
extern nsresult NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
@ -57,11 +58,16 @@ extern nsresult NS_NewJSEventListener(nsIDOMEventListener **aInstancePtrResult,
extern nsresult NS_NewScriptGlobalObject(nsIScriptGlobalObject **aGlobal);
extern nsresult NS_NewDOMException(nsresult aResult,
nsIException* aDefaultException,
nsIException** aException);
//////////////////////////////////////////////////////////////////////
class nsDOMSOFactory : public nsIDOMScriptObjectFactory,
public nsIObserver
public nsIObserver,
public nsIExceptionProvider
{
public:
nsDOMSOFactory();
@ -72,6 +78,9 @@ public:
// nsIObserver
NS_DECL_NSIOBSERVER
// nsIExceptionProvider
NS_DECL_NSIEXCEPTIONPROVIDER
NS_IMETHOD NewScriptContext(nsIScriptGlobalObject *aGlobal,
nsIScriptContext **aContext);
@ -94,6 +103,13 @@ nsDOMSOFactory::nsDOMSOFactory()
if (observerService) {
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
}
}
nsDOMSOFactory::~nsDOMSOFactory()
@ -104,6 +120,7 @@ nsDOMSOFactory::~nsDOMSOFactory()
NS_INTERFACE_MAP_BEGIN(nsDOMSOFactory)
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
@ -162,10 +179,25 @@ nsDOMSOFactory::Observe(nsISupports *aSubject,
GlobalWindowImpl::ShutDown();
nsDOMClassInfo::ShutDown();
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMSOFactory::GetException(nsresult result, nsIException *aDefaultException,
nsIException **_retval)
{
return NS_NewDOMException(result, aDefaultException, _retval);
}
//////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSOFactory);

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

@ -50,37 +50,6 @@ interface nsIXPCException : nsIException
in nsIException aInner);
};
// XXX this is a hack that will be fixed later with integration to
// the nsIErrorService and a scheme to let the DOM make its own
// exceptions on demand.
[scriptable, uuid(84279040-40ce-11d5-90bb-0010a4e73d9a)]
interface nsIXPCDOMException : nsIXPCException
{
const unsigned short INDEX_SIZE_ERR = 1;
const unsigned short DOMSTRING_SIZE_ERR = 2;
const unsigned short HIERARCHY_REQUEST_ERR = 3;
const unsigned short WRONG_DOCUMENT_ERR = 4;
const unsigned short INVALID_CHARACTER_ERR = 5;
const unsigned short NO_DATA_ALLOWED_ERR = 6;
const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7;
const unsigned short NOT_FOUND_ERR = 8;
const unsigned short NOT_SUPPORTED_ERR = 9;
const unsigned short INUSE_ATTRIBUTE_ERR = 10;
// Introduced in DOM Level 2:
const unsigned short INVALID_STATE_ERR = 11;
// Introduced in DOM Level 2:
const unsigned short SYNTAX_ERR = 12;
// Introduced in DOM Level 2:
const unsigned short INVALID_MODIFICATION_ERR = 13;
// Introduced in DOM Level 2:
const unsigned short NAMESPACE_ERR = 14;
// Introduced in DOM Level 2:
const unsigned short INVALID_ACCESS_ERR = 15;
readonly attribute unsigned long code;
};
/* this goes into the C++ header verbatim. */
%{ C++
/********************************************************/

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

@ -116,7 +116,6 @@ nsXPCException::GetNSResultCount()
NS_INTERFACE_MAP_BEGIN(nsXPCException)
NS_INTERFACE_MAP_ENTRY(nsIException)
NS_INTERFACE_MAP_ENTRY(nsIXPCException)
NS_INTERFACE_MAP_ENTRY(nsIXPCDOMException)
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
#endif
@ -127,7 +126,7 @@ NS_INTERFACE_MAP_END_THREADSAFE
NS_IMPL_THREADSAFE_ADDREF(nsXPCException)
NS_IMPL_THREADSAFE_RELEASE(nsXPCException)
NS_IMPL_CI_INTERFACE_GETTER2(nsXPCException, nsIXPCException, nsIXPCDOMException)
NS_IMPL_CI_INTERFACE_GETTER1(nsXPCException, nsIXPCException)
nsXPCException::nsXPCException()
: mMessage(nsnull),
@ -137,7 +136,6 @@ nsXPCException::nsXPCException()
mData(nsnull),
mFilename(nsnull),
mLineNumber(0),
mColumnNumber(0),
mInner(nsnull),
mInitialized(PR_FALSE)
{
@ -169,7 +167,7 @@ nsXPCException::Reset()
nsMemory::Free(mFilename);
mFilename = nsnull;
}
mLineNumber = mColumnNumber = (PRUint32)-1;
mLineNumber = (PRUint32)-1;
NS_IF_RELEASE(mLocation);
NS_IF_RELEASE(mData);
NS_IF_RELEASE(mInner);
@ -196,21 +194,6 @@ nsXPCException::GetResult(nsresult *aResult)
return NS_OK;
}
NS_IMETHODIMP
nsXPCException::GetCode(PRUint32* aCode)
{
if(!aCode)
return NS_ERROR_NULL_POINTER;
if(!mInitialized)
return NS_ERROR_NOT_INITIALIZED;
if(NS_ERROR_GET_MODULE(mResult) == NS_ERROR_MODULE_DOM)
*aCode = NS_ERROR_GET_CODE(mResult);
else
*aCode = (PRUint32) mResult;
return NS_OK;
}
/* readonly attribute string name; */
NS_IMETHODIMP
nsXPCException::GetName(char * *aName)
@ -251,7 +234,7 @@ NS_IMETHODIMP nsXPCException::GetColumnNumber(PRUint32 *aColumnNumber)
return NS_ERROR_NULL_POINTER;
if(!mInitialized)
return NS_ERROR_NOT_INITIALIZED;
*aColumnNumber = mColumnNumber;
*aColumnNumber = -1;
return NS_OK;
}
@ -330,8 +313,6 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a
return rc;
if(NS_FAILED(rc = aLocation->GetLineNumber(&mLineNumber)))
return rc;
if(NS_FAILED(rc = aLocation->GetLineNumber(&mColumnNumber)))
return rc;
}
else
{
@ -520,8 +501,7 @@ nsXPCException::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, ch
NS_IMETHODIMP
nsXPCException::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
static const char* allowed[] = { "message", "result", "code", "name",
nsnull};
static const char* allowed[] = { "message", "result", "name", nsnull};
*_retval = xpc_CheckAccessList(propertyName, allowed);
return NS_OK;

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

@ -2429,7 +2429,7 @@ private:
/***************************************************************************/
class nsXPCException :
public nsIXPCDOMException
public nsIXPCException
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
, public nsISecurityCheckedComponent
#endif
@ -2440,7 +2440,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEXCEPTION
NS_DECL_NSIXPCEXCEPTION
NS_DECL_NSIXPCDOMEXCEPTION
#ifdef XPC_USE_SECURITY_CHECKED_COMPONENT
NS_DECL_NSISECURITYCHECKEDCOMPONENT
#endif
@ -2475,7 +2474,6 @@ private:
nsISupports* mData;
char* mFilename;
int mLineNumber;
int mColumnNumber;
nsIException* mInner;
PRBool mInitialized;
};

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

@ -179,12 +179,35 @@ XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
/* no need to set an expection if the security manager already has */
if(rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO && JS_IsExceptionPending(cx))
return;
nsCOMPtr<nsIException> e;
nsXPCException::NewException(sz, rv, nsnull, nsnull, getter_AddRefs(e));
if(e)
success = ThrowExceptionObject(cx, e);
nsCOMPtr<nsIException> finalException;
nsCOMPtr<nsIException> defaultException;
nsXPCException::NewException(sz, rv, nsnull, nsnull, getter_AddRefs(defaultException));
XPCPerThreadData* tls = XPCPerThreadData::GetData();
if(tls)
{
nsIExceptionManager * exceptionManager = tls->GetExceptionManager();
if(exceptionManager)
{
// Ask the provider for the exception, if there is no provider
// we expect it to set e to null
exceptionManager->GetExceptionFromProvider(
rv,
defaultException,
getter_AddRefs(finalException));
// We should get at least the defaultException back,
// but just in case
if(finalException == nsnull)
{
finalException = defaultException;
}
}
}
// XXX Should we put the following test and call to JS_ReportOutOfMemory
// inside this test?
if(finalException)
success = ThrowExceptionObject(cx, finalException);
// If we weren't able to build or throw an exception we're
// most likely out of memory
if(!success)
JS_ReportOutOfMemory(cx);
}

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

@ -130,12 +130,12 @@ NS_IMETHODIMP nsExceptionManager::GetCurrentException(nsIException **_retval)
return NS_OK;
}
/* nsIException GetExceptionFromProvider(in nsresult rc); */
NS_IMETHODIMP nsExceptionManager::GetExceptionFromProvider(nsresult rc, nsIException **_retval)
/* nsIException getExceptionFromProvider( in nsresult rc, in nsIException defaultException); */
NS_IMETHODIMP nsExceptionManager::GetExceptionFromProvider(nsresult rc, nsIException * defaultException, nsIException **_retval)
{
CHECK_MANAGER_USE_OK();
// Just delegate back to the service with the provider map.
return mService->GetExceptionFromProvider(rc, _retval);
return mService->GetExceptionFromProvider(rc, defaultException, _retval);
}
/* The Exception Service */
@ -236,11 +236,12 @@ NS_IMETHODIMP nsExceptionService::GetCurrentException(nsIException **_retval)
return sm->GetCurrentException(_retval);
}
/* nsIException GetExceptionFromProvider (in nsresult rc); */
NS_IMETHODIMP nsExceptionService::GetExceptionFromProvider(nsresult rc, nsIException **_retval)
/* nsIException getExceptionFromProvider( in nsresult rc, in nsIException defaultException); */
NS_IMETHODIMP nsExceptionService::GetExceptionFromProvider(nsresult rc,
nsIException * defaultException, nsIException **_retval)
{
CHECK_SERVICE_USE_OK();
return DoGetExceptionFromProvider(rc, _retval);
return DoGetExceptionFromProvider(rc, defaultException, _retval);
}
/* readonly attribute nsIExceptionManager currentExceptionManager; */
@ -296,15 +297,23 @@ NS_IMETHODIMP nsExceptionService::Observe(nsISupports *aSubject, const char *aTo
return NS_OK;
}
nsresult nsExceptionService::DoGetExceptionFromProvider( nsresult errCode, nsIException **_exc)
nsresult
nsExceptionService::DoGetExceptionFromProvider(nsresult errCode,
nsIException * defaultException,
nsIException **_exc)
{
nsProviderKey key(NS_ERROR_GET_MODULE(errCode));
nsCOMPtr<nsIExceptionProvider> provider((nsIExceptionProvider *)mProviders.Get(&key));
nsCOMPtr<nsIExceptionProvider> provider =
(nsIExceptionProvider *)mProviders.Get(&key);
// No provider so we'll return the default exception
if (!provider) {
*_exc = nsnull;
return NS_COMFALSE;
*_exc = defaultException;
NS_IF_ADDREF(*_exc);
return NS_OK;
}
return provider->GetException(errCode, _exc);
return provider->GetException(errCode, defaultException, _exc);
}
// thread management

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

@ -61,7 +61,9 @@ public:
virtual ~nsExceptionService();
/* additional members */
nsresult DoGetExceptionFromProvider( nsresult errCode, nsIException **_richError );
nsresult DoGetExceptionFromProvider(nsresult errCode,
nsIException *defaultException,
nsIException **_richError);
void Shutdown();

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

@ -46,7 +46,7 @@
interface nsIExceptionProvider : nsISupports
{
/** Gets an nsIException or returns NULL if not possible. **/
nsIException getException(in nsresult result);
nsIException getException(in nsresult result, in nsIException defaultException);
};
// A ScriptErrorManager for a single thread. These objects
@ -63,7 +63,7 @@ interface nsIExceptionManager : nsISupports
/** Gets an exception from a registered exception provider..
This has no effect on the "current exception" */
nsIException getExceptionFromProvider( in nsresult rc );
nsIException getExceptionFromProvider( in nsresult rc, in nsIException defaultException);
};