Don't ignore any errors returned by PostCreate. Also, don't override an exception if one is already reported, as the further away from the original problem we get, the less precise the error message will be. bug 326497, r=brendan sr=shaver

This commit is contained in:
mrbkap%gmail.com 2006-04-03 18:10:38 +00:00
Родитель 61c5a00566
Коммит f4b1446ece
3 изменённых файлов: 40 добавлений и 20 удалений

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

@ -2515,6 +2515,7 @@ private:
static void BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz);
static JSBool ThrowExceptionObject(JSContext* cx, nsIException* e);
static JSBool CheckForPendingException(nsresult result, XPCCallContext &ccx);
private:
static JSBool sVerbose;

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

@ -49,11 +49,41 @@ void
XPCThrower::Throw(nsresult rv, JSContext* cx)
{
const char* format;
if(JS_IsExceptionPending(cx))
return;
if(!nsXPCException::NameAndFormatForNSResult(rv, nsnull, &format))
format = "";
BuildAndThrowException(cx, rv, format);
}
/*
* If there has already been an exception thrown, see if we're throwing the
* same sort of exception, and if we are, don't clobber the old one. ccx
* should be the current call context.
*/
// static
JSBool
XPCThrower::CheckForPendingException(nsresult result, XPCCallContext &ccx)
{
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if(!xpc)
return JS_FALSE;
nsCOMPtr<nsIException> e;
xpc->GetPendingException(getter_AddRefs(e));
if(!e)
return JS_FALSE;
xpc->SetPendingException(nsnull);
nsresult e_result;
if(NS_FAILED(e->GetResult(&e_result)) || e_result != result)
return JS_FALSE;
if(!ThrowExceptionObject(ccx, e))
JS_ReportOutOfMemory(ccx);
return JS_TRUE;
}
// static
void
XPCThrower::Throw(nsresult rv, XPCCallContext& ccx)
@ -61,6 +91,9 @@ XPCThrower::Throw(nsresult rv, XPCCallContext& ccx)
char* sz;
const char* format;
if(CheckForPendingException(rv, ccx))
return;
if(!nsXPCException::NameAndFormatForNSResult(rv, nsnull, &format))
format = "";
@ -91,24 +124,8 @@ XPCThrower::ThrowBadResult(nsresult rv, nsresult result, XPCCallContext& ccx)
* call. So we'll just throw that exception into our JS.
*/
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
if(xpc)
{
nsCOMPtr<nsIException> e;
xpc->GetPendingException(getter_AddRefs(e));
if(e)
{
xpc->SetPendingException(nsnull);
nsresult e_result;
if(NS_SUCCEEDED(e->GetResult(&e_result)) && e_result == result)
{
if(!ThrowExceptionObject(ccx, e))
JS_ReportOutOfMemory(ccx);
return;
}
}
}
if(CheckForPendingException(result, ccx))
return;
// else...

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

@ -461,8 +461,10 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
XPCNativeScriptableInfo* si = wrapper->GetScriptableInfo();
if(si && si->GetFlags().WantPostCreate())
{
si->GetCallback()->
PostCreate(wrapper, ccx, wrapper->GetFlatJSObject());
rv = si->GetCallback()->
PostCreate(wrapper, ccx, wrapper->GetFlatJSObject());
if(NS_FAILED(rv))
return rv;
}
}