Back to index

lightning-sunbird  0.9+nobinonly
Functions
XPCDispTearOff.cpp File Reference

Contains the implementation of the XPCDispTearoff class. More...

#include "xpcprivate.h"

Go to the source code of this file.

Functions

static HRESULT Error (HRESULT hResult, const CComBSTR &message)
 Sets the COM error from a result code and text message.
HRESULT Error (HRESULT hResult, const char *message)
 Sets the COM error from a result code and text message.
static void BuildMessage (nsIException *exception, nsCString &result)
 Helper function that converts an exception to a string.
static void SetCOMError (nsIException *exception)
 Sets the COM error given an nsIException.
static BOOL _IsEqualGUID (REFGUID rguid1, REFGUID rguid2)
void JS_DLL_CALLBACK xpcWrappedJSErrorReporter (JSContext *cx, const char *message, JSErrorReport *report)

Detailed Description

Contains the implementation of the XPCDispTearoff class.

Definition in file XPCDispTearOff.cpp.


Function Documentation

static BOOL _IsEqualGUID ( REFGUID  rguid1,
REFGUID  rguid2 
) [inline, static]

Definition at line 146 of file XPCDispTearOff.cpp.

{
   return (
         ((PLONG) &rguid1)[0] == ((PLONG) &rguid2)[0] &&
         ((PLONG) &rguid1)[1] == ((PLONG) &rguid2)[1] &&
         ((PLONG) &rguid1)[2] == ((PLONG) &rguid2)[2] &&
         ((PLONG) &rguid1)[3] == ((PLONG) &rguid2)[3]);
}

Here is the caller graph for this function:

static void BuildMessage ( nsIException exception,
nsCString result 
) [static]

Helper function that converts an exception to a string.

Parameters:
exception
Returns:
the description of the exception

Definition at line 96 of file XPCDispTearOff.cpp.

{
    nsXPIDLCString msg;
    exception->GetMessage(getter_Copies(msg));
    nsXPIDLCString filename;
    exception->GetFilename(getter_Copies(filename));

    PRUint32 lineNumber;
    if(NS_FAILED(exception->GetLineNumber(&lineNumber)))
        lineNumber = 0;
    result = "Error in file ";
    result += filename;
    result += ",#";
    result.AppendInt(lineNumber);
    result += " : ";
    result += msg;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HRESULT Error ( HRESULT  hResult,
const CComBSTR &  message 
) [static]

Sets the COM error from a result code and text message.

This is the base implementation for subsequent string based overrides

Parameters:
hResultthe COM error code to be used
messagethe message to put in the error
Returns:
the error code passed in via hResult

Definition at line 51 of file XPCDispTearOff.cpp.

{
    CComPtr<ICreateErrorInfo> pCreateError;
    CComPtr<IErrorInfo> pError;
    HRESULT result = CreateErrorInfo(&pCreateError);
    if(FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->QueryInterface(&pError);
    if(FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->SetDescription(message);
    if(FAILED(result))
        return E_NOTIMPL;
    result = pCreateError->SetGUID(IID_IDispatch);
    if(FAILED(result))
        return E_NOTIMPL;
    CComBSTR source(L"@mozilla.XPCDispatchTearOff");
    result = pCreateError->SetSource(source);
    if(FAILED(result))
        return E_NOTIMPL;
    result = SetErrorInfo(0, pError);
    if(FAILED(result))
        return E_NOTIMPL;
    return hResult;
}
HRESULT Error ( HRESULT  hResult,
const char *  message 
) [inline]

Sets the COM error from a result code and text message.

Parameters:
hResultthe COM error code to be used
messagethe message to put in the error
Returns:
the error code passed in via hResult

Definition at line 85 of file XPCDispTearOff.cpp.

{
    CComBSTR someText(message);
    return Error(hResult, someText);
}
static void SetCOMError ( nsIException exception) [inline, static]

Sets the COM error given an nsIException.

Parameters:
exceptionthe exception being set

Definition at line 119 of file XPCDispTearOff.cpp.

{
    nsCString message;
    BuildMessage(exception, message);
    Error(E_FAIL, message.get());
}

Here is the call graph for this function:

void JS_DLL_CALLBACK xpcWrappedJSErrorReporter ( JSContext cx,
const char *  message,
JSErrorReport report 
)

Definition at line 679 of file xpcwrappedjsclass.cpp.

{
    if(report)
    {
        // If it is an exception report, then we can just deal with the
        // exception later (if not caught in the JS code).
        if(JSREPORT_IS_EXCEPTION(report->flags))
        {
            // XXX We have a problem with error reports from uncaught exceptions.
            //
            // http://bugzilla.mozilla.org/show_bug.cgi?id=66453
            //
            // The issue is...
            //
            // We can't assume that the exception will *stay* uncaught. So, if
            // we build an nsIXPCException here and the underlying exception
            // really is caught before our script is done running then we blow
            // it by returning failure to our caller when the script didn't
            // really fail. However, This report contains error location info
            // that is no longer available after the script is done. So, if the
            // exception really is not caught (and is a non-engine exception)
            // then we've lost the oportunity to capture the script location
            // info that we *could* have captured here.
            //
            // This is expecially an issue with nested evaluations.
            //
            // Perhaps we could capture an expception here and store it as
            // 'provisional' and then later if there is a pending exception
            // when the script is done then we could maybe compare that in some
            // way with the 'provisional' one in which we captured location info.
            // We would not want to assume that the one discovered here is the
            // same one that is later detected. This could cause us to lie.
            //
            // The thing is. we do not currently store the right stuff to compare
            // these two nsIXPCExceptions (triggered by the same exception jsval
            // in the engine). Maybe we should store the jsval and compare that?
            // Maybe without even rooting it since we will not dereference it.
            // This is inexact, but maybe the right thing to do?
            //
            // if(report->errorNumber == JSMSG_UNCAUGHT_EXCEPTION)) ...
            //

            return;
        }

        if(JSREPORT_IS_WARNING(report->flags))
        {
            // XXX printf the warning (#ifdef DEBUG only!).
            // XXX send the warning to the console service.
            return;
        }
    }

    XPCCallContext ccx(NATIVE_CALLER, cx);
    if(!ccx.IsValid())
        return;

    nsCOMPtr<nsIException> e;
    XPCConvert::JSErrorToXPCException(ccx, message, nsnull, nsnull, report,
                                      getter_AddRefs(e));
    if(e)
        ccx.GetXPCContext()->SetException(e);
}

Here is the call graph for this function:

Here is the caller graph for this function: