Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Private Member Functions | Static Private Attributes
XPCThrower Class Reference

#include <xpcprivate.h>

List of all members.

Static Public Member Functions

static void Throw (nsresult rv, JSContext *cx)
static void Throw (nsresult rv, XPCCallContext &ccx)
static void ThrowBadResult (nsresult rv, nsresult result, XPCCallContext &ccx)
static void ThrowBadParam (nsresult rv, uintN paramNum, XPCCallContext &ccx)
static JSBool SetVerbosity (JSBool state)

Static Private Member Functions

static void Verbosify (XPCCallContext &ccx, char **psz, PRBool own)
static void BuildAndThrowException (JSContext *cx, nsresult rv, const char *sz)
static JSBool ThrowExceptionObject (JSContext *cx, nsIException *e)
static JSBool CheckForPendingException (nsresult result, XPCCallContext &ccx)

Static Private Attributes

static JSBool sVerbose = JS_TRUE

Detailed Description

Definition at line 2520 of file xpcprivate.h.


Member Function Documentation

void XPCThrower::BuildAndThrowException ( JSContext cx,
nsresult  rv,
const char *  sz 
) [static, private]

Definition at line 223 of file xpcthrower.cpp.

{
    JSBool success = JS_FALSE;

    /* 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> 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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool XPCThrower::CheckForPendingException ( nsresult  result,
XPCCallContext ccx 
) [static, private]

Definition at line 66 of file xpcthrower.cpp.

{
    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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool XPCThrower::SetVerbosity ( JSBool  state) [inline, static]

Definition at line 2532 of file xpcprivate.h.

        {JSBool old = sVerbose; sVerbose = state; return old;}
void XPCThrower::Throw ( nsresult  rv,
JSContext cx 
) [static]

Definition at line 49 of file xpcthrower.cpp.

{
    const char* format;
    if(JS_IsExceptionPending(cx))
        return;
    if(!nsXPCException::NameAndFormatForNSResult(rv, nsnull, &format))
        format = "";
    BuildAndThrowException(cx, rv, format);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XPCThrower::Throw ( nsresult  rv,
XPCCallContext ccx 
) [static]

Definition at line 89 of file xpcthrower.cpp.

{
    char* sz;
    const char* format;

    if(CheckForPendingException(rv, ccx))
        return;

    if(!nsXPCException::NameAndFormatForNSResult(rv, nsnull, &format))
        format = "";

    sz = (char*) format;

    if(sz && sVerbose)
        Verbosify(ccx, &sz, PR_FALSE);

    BuildAndThrowException(ccx, rv, sz);

    if(sz && sz != format)
        JS_smprintf_free(sz);
}

Here is the call graph for this function:

void XPCThrower::ThrowBadParam ( nsresult  rv,
uintN  paramNum,
XPCCallContext ccx 
) [static]

Definition at line 151 of file xpcthrower.cpp.

{
    char* sz;
    const char* format;

    if(!nsXPCException::NameAndFormatForNSResult(rv, nsnull, &format))
        format = "";

    sz = JS_smprintf("%s arg %d", format, paramNum);

    if(sz && sVerbose)
        Verbosify(ccx, &sz, PR_TRUE);

    BuildAndThrowException(ccx, rv, sz);

    if(sz)
        JS_smprintf_free(sz);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XPCThrower::ThrowBadResult ( nsresult  rv,
nsresult  result,
XPCCallContext ccx 
) [static]

Definition at line 114 of file xpcthrower.cpp.

{
    char* sz;
    const char* format;
    const char* name;

    /*
    *  If there is a pending exception when the native call returns and
    *  it has the same error result as returned by the native call, then
    *  the native call may be passing through an error from a previous JS
    *  call. So we'll just throw that exception into our JS.
    */

    if(CheckForPendingException(result, ccx))
        return;

    // else...

    if(!nsXPCException::NameAndFormatForNSResult(rv, nsnull, &format) || !format)
        format = "";

    if(nsXPCException::NameAndFormatForNSResult(result, &name, nsnull) && name)
        sz = JS_smprintf("%s 0x%x (%s)", format, result, name);
    else
        sz = JS_smprintf("%s 0x%x", format, result);

    if(sz && sVerbose)
        Verbosify(ccx, &sz, PR_TRUE);

    BuildAndThrowException(ccx, result, sz);

    if(sz)
        JS_smprintf_free(sz);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool XPCThrower::ThrowExceptionObject ( JSContext cx,
nsIException e 
) [static, private]

Definition at line 275 of file xpcthrower.cpp.

{
    JSBool success = JS_FALSE;
    if(e)
    {
        nsXPConnect* xpc = nsXPConnect::GetXPConnect();
        if(xpc)
        {
            JSObject* glob = JS_GetScopeChain(cx);
            if(!glob)
                return JS_FALSE;
            glob = GetGlobalObject(cx, glob);

            nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
            nsresult rv = xpc->WrapNative(cx, glob, e,
                                          NS_GET_IID(nsIException),
                                          getter_AddRefs(holder));
            if(NS_SUCCEEDED(rv) && holder)
            {
                JSObject* obj;
                if(NS_SUCCEEDED(holder->GetJSObject(&obj)))
                {
                    JS_SetPendingException(cx, OBJECT_TO_JSVAL(obj));
                    success = JS_TRUE;
                }
            }
        }
    }
    return success;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XPCThrower::Verbosify ( XPCCallContext ccx,
char **  psz,
PRBool  own 
) [static, private]

Definition at line 173 of file xpcthrower.cpp.

{
    char* sz = nsnull;

    if(ccx.HasInterfaceAndMember())
    {
        XPCNativeInterface* iface = ccx.GetInterface();
#ifdef XPC_IDISPATCH_SUPPORT
        NS_ASSERTION(ccx.GetIDispatchMember() == nsnull || 
                        ccx.GetMember() == nsnull,
                     "Both IDispatch member and regular XPCOM member "
                     "were set in XPCCallContext");
        char const * name;
        if(ccx.GetIDispatchMember())
        {
            XPCDispInterface::Member * member = 
                NS_REINTERPRET_CAST(XPCDispInterface::Member*, 
                                    ccx.GetIDispatchMember());
            if(member && JSVAL_IS_STRING(member->GetName()))
            {
                name = JS_GetStringBytes(JSVAL_TO_STRING(member->GetName()));
            }
            else
                name = "Unknown";
        }
        else
            name = iface->GetMemberName(ccx, ccx.GetMember());
        sz = JS_smprintf("%s [%s.%s]",
                         *psz,
                         iface->GetNameString(),
                         name);
#else
        sz = JS_smprintf("%s [%s.%s]",
                         *psz,
                         iface->GetNameString(),
                         iface->GetMemberName(ccx, ccx.GetMember()));
#endif
    }

    if(sz)
    {
        if(own)
            JS_smprintf_free(*psz);
        *psz = sz;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

JSBool XPCThrower::sVerbose = JS_TRUE [static, private]

Definition at line 2544 of file xpcprivate.h.


The documentation for this class was generated from the following files: