Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes
XPCCallContext Class Reference

#include <xpcprivate.h>

Inheritance diagram for XPCCallContext:
Inheritance graph
[legend]
Collaboration diagram for XPCCallContext:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { NO_ARGS = (uintN) -1 }

Public Member Functions

 XPCCallContext (XPCContext::LangType callerLanguage, JSContext *cx=nsnull, JSObject *obj=nsnull, JSObject *funobj=nsnull, jsval id=0, uintN argc=NO_ARGS, jsval *argv=nsnull, jsval *rval=nsnull)
virtual ~XPCCallContext ()
JSBool IsValid () const
nsXPConnectGetXPConnect () const
XPCJSRuntimeGetRuntime () const
XPCPerThreadDataGetThreadData () const
XPCContextGetXPCContext () const
JSContextGetJSContext () const
JSContextGetSafeJSContext () const
JSBool GetContextPopRequired () const
XPCContext::LangType GetCallerLanguage () const
XPCContext::LangType GetPrevCallerLanguage () const
XPCCallContextGetPrevCallContext () const
JSObjectGetOperandJSObject () const
JSObjectGetCurrentJSObject () const
JSObjectGetFlattenedJSObject () const
nsISupports * GetIdentityObject () const
XPCWrappedNativeGetWrapper () const
JSBool CanGetTearOff () const
XPCWrappedNativeTearOffGetTearOff () const
XPCNativeScriptableInfoGetScriptableInfo () const
JSBool CanGetSet () const
XPCNativeSetGetSet () const
JSBool CanGetInterface () const
XPCNativeInterfaceGetInterface () const
XPCNativeMemberGetMember () const
JSBool HasInterfaceAndMember () const
jsval GetName () const
JSBool GetStaticMemberIsLocal () const
uintN GetArgc () const
jsvalGetArgv () const
jsvalGetRetVal () const
JSBool GetExceptionWasThrown () const
JSBool GetReturnValueWasSet () const
PRUint16 GetMethodIndex () const
void SetMethodIndex (PRUint16 index)
JSBool GetDestroyJSContextInDestructor () const
void SetDestroyJSContextInDestructor (JSBool b)
jsval GetResolveName () const
jsval SetResolveName (jsval name)
XPCWrappedNativeGetResolvingWrapper () const
XPCWrappedNativeSetResolvingWrapper (XPCWrappedNative *w)
void SetRetVal (jsval val)
JSObjectGetCallee () const
void SetCallee (JSObject *callee)
void SetName (jsval name)
void SetArgsAndResultPtr (uintN argc, jsval *argv, jsval *rval)
void SetCallInfo (XPCNativeInterface *iface, XPCNativeMember *member, JSBool isSetter)
nsresult CanCallNow ()
void SystemIsBeingShutDown ()
 operator JSContext * () const

Public Attributes

readonly attribute nsISupports Callee
readonly attribute PRUint16 CalleeMethodIndex
readonly attribute
nsIXPConnectWrappedNative 
CalleeWrapper
readonly attribute JSContextPtr JSContext
readonly attribute PRUint32 Argc
readonly attribute JSValPtr ArgvPtr
readonly attribute JSValPtr RetValPtr
 This may be NULL if the JS caller is ignoring the result of the call.
attribute PRBool ExceptionWasThrown
 Set this if JS_SetPendingException has been called.
attribute PRBool ReturnValueWasSet
 Set this to indicate that the callee has directly set the return value (using RetValPtr and the JSAPI).
readonly attribute nsIInterfaceInfo CalleeInterface
readonly attribute nsIClassInfo CalleeClassInfo

Private Types

enum  State {
  INIT_FAILED, SYSTEM_SHUTDOWN, HAVE_CONTEXT, HAVE_OBJECT,
  HAVE_NAME, HAVE_ARGS, READY_TO_CALL, CALL_DONE
}

Private Member Functions

 XPCCallContext (const XPCCallContext &r)
XPCCallContextoperator= (const XPCCallContext &r)

Private Attributes

State mState
nsXPConnectmXPC
XPCPerThreadDatamThreadData
XPCContextmXPCContext
JSContextmJSContext
JSBool mContextPopRequired
JSBool mDestroyJSContextInDestructor
XPCContext::LangType mCallerLanguage
XPCContext::LangType mPrevCallerLanguage
XPCCallContextmPrevCallContext
JSObjectmOperandJSObject
JSObjectmCurrentJSObject
JSObjectmFlattenedJSObject
XPCWrappedNativemWrapper
XPCWrappedNativeTearOffmTearOff
XPCNativeScriptableInfomScriptableInfo
XPCNativeSetmSet
XPCNativeInterfacemInterface
XPCNativeMembermMember
jsval mName
JSBool mStaticMemberIsLocal
uintN mArgc
jsvalmArgv
jsvalmRetVal
JSBool mExceptionWasThrown
JSBool mReturnValueWasSet
PRUint16 mMethodIndex
JSObjectmCallee

Detailed Description

Definition at line 822 of file xpcprivate.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
NO_ARGS 

Definition at line 828 of file xpcprivate.h.

{NO_ARGS = (uintN) -1};
enum XPCCallContext::State [private]
Enumerator:
INIT_FAILED 
SYSTEM_SHUTDOWN 
HAVE_CONTEXT 
HAVE_OBJECT 
HAVE_NAME 
HAVE_ARGS 
READY_TO_CALL 
CALL_DONE 

Definition at line 924 of file xpcprivate.h.


Constructor & Destructor Documentation

XPCCallContext::XPCCallContext ( XPCContext::LangType  callerLanguage,
JSContext cx = nsnull,
JSObject obj = nsnull,
JSObject funobj = nsnull,
jsval  id = 0,
uintN  argc = NO_ARGS,
jsval argv = nsnull,
jsval rval = nsnull 
)

Definition at line 45 of file xpccallcontext.cpp.

    :   mState(INIT_FAILED),
        mXPC(nsXPConnect::GetXPConnect()),
        mThreadData(nsnull),
        mXPCContext(nsnull),
        mJSContext(cx),
        mContextPopRequired(JS_FALSE),
        mDestroyJSContextInDestructor(JS_FALSE),
        mCallerLanguage(callerLanguage),
        mCallee(nsnull)
{
    if(!mXPC)
        return;

    NS_ADDREF(mXPC);

    if(!(mThreadData = XPCPerThreadData::GetData()))
        return;

    XPCJSContextStack* stack = mThreadData->GetJSContextStack();
    JSContext* topJSContext;

    if(!stack || NS_FAILED(stack->Peek(&topJSContext)))
    {
        NS_ERROR("bad!");
        mJSContext = nsnull;
        return;
    }

    if(!mJSContext)
    {
        // This is slightly questionable. If called without an explicit
        // JSContext (generally a call to a wrappedJS) we will use the JSContext
        // on the top of the JSContext stack - if there is one - *before*
        // falling back on the safe JSContext.
        // This is good AND bad because it makes calls from JS -> native -> JS
        // have JS stack 'continuity' for purposes of stack traces etc.
        // Note: this *is* what the pre-XPCCallContext xpconnect did too.

        if(topJSContext)
            mJSContext = topJSContext;
        else if(NS_FAILED(stack->GetSafeJSContext(&mJSContext)) || !mJSContext)
            return;
    }

    // Get into the request as early as we can to avoid problems with scanning
    // callcontexts on other threads from within the gc callbacks.

    if(mCallerLanguage == NATIVE_CALLER && JS_GetContextThread(mJSContext))
        JS_BeginRequest(mJSContext);

    if(topJSContext != mJSContext)
    {
        if(NS_FAILED(stack->Push(mJSContext)))
        {
            NS_ERROR("bad!");
            return;
        }
        mContextPopRequired = JS_TRUE;
    }

    // Try to get the JSContext -> XPCContext mapping from the cache.
    // FWIW... quicky tests show this hitting ~ 95% of the time.
    // That is a *lot* of locking we can skip in nsXPConnect::GetContext.
    mXPCContext = mThreadData->GetRecentXPCContext(mJSContext);

    if(!mXPCContext)
    {
        if(!(mXPCContext = nsXPConnect::GetContext(mJSContext, mXPC)))
            return;

        // Fill the cache.
        mThreadData->SetRecentContext(mJSContext, mXPCContext);
    }

    mPrevCallerLanguage = mXPCContext->SetCallingLangType(mCallerLanguage);

    // hook into call context chain for our thread
    mPrevCallContext = mThreadData->SetCallContext(this);

    mState = HAVE_CONTEXT;

    if(!obj)
        return;

    mMethodIndex = 0xDEAD;
    mOperandJSObject = obj;

    mState = HAVE_OBJECT;

    mTearOff = nsnull;
    mWrapper = XPCWrappedNative::GetWrappedNativeOfJSObject(mJSContext, obj,
                                                            funobj,
                                                            &mCurrentJSObject,
                                                            &mTearOff);
    if(!mWrapper)
        return;

    DEBUG_CheckWrapperThreadSafety(mWrapper);

    mFlattenedJSObject = mWrapper->GetFlatJSObject();

    if(mTearOff)
        mScriptableInfo = nsnull;
    else
        mScriptableInfo = mWrapper->GetScriptableInfo();

    if(name)
        SetName(name);

    if(argc != NO_ARGS)
        SetArgsAndResultPtr(argc, argv, rval);

    CHECK_STATE(HAVE_OBJECT);
}

Here is the call graph for this function:

Definition at line 292 of file xpccallcontext.cpp.

{
    NS_ASSERTION(mRefCnt == 0, "Someone is holding a bad reference to a XPCCallContext");

    // do cleanup...

    if(mXPCContext)
    {
        mXPCContext->SetCallingLangType(mPrevCallerLanguage);

#ifdef DEBUG
        XPCCallContext* old = mThreadData->SetCallContext(mPrevCallContext);
        NS_ASSERTION(old == this, "bad pop from per thread data");
#else
        (void) mThreadData->SetCallContext(mPrevCallContext);
#endif
    }

    if(mContextPopRequired)
    {
        XPCJSContextStack* stack = mThreadData->GetJSContextStack();
        NS_ASSERTION(stack, "bad!");
        if(stack)
        {
#ifdef DEBUG
            JSContext* poppedCX;
            nsresult rv = stack->Pop(&poppedCX);
            NS_ASSERTION(NS_SUCCEEDED(rv) && poppedCX == mJSContext, "bad pop");
#else
            (void) stack->Pop(nsnull);
#endif
        }
    }

    if(mJSContext)
    {
        if(mCallerLanguage == NATIVE_CALLER && JS_GetContextThread(mJSContext))
            JS_EndRequest(mJSContext);
        
        if(mDestroyJSContextInDestructor)
        {
#ifdef DEBUG_xpc_hacker
            printf("!xpc - doing deferred destruction of JSContext @ %0x\n", 
                   mJSContext);
#endif
            NS_ASSERTION(!mThreadData->GetJSContextStack() || 
                         !mThreadData->GetJSContextStack()->
                            DEBUG_StackHasJSContext(mJSContext),
                         "JSContext still in threadjscontextstack!");
        
            JS_DestroyContext(mJSContext);
            mXPC->SyncJSContexts();
        }
        else
        {
            // Don't clear newborns if JS frames (compilation or execution)
            // are active!  Doing so violates ancient invariants in the JS
            // engine, and it's not necessary to fix JS component leaks.
            if (!mJSContext->fp)
                JS_ClearNewbornRoots(mJSContext);
        }
    }

    NS_IF_RELEASE(mXPC);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 252 of file xpccallcontext.cpp.

{
    nsresult rv;
    
    if(!HasInterfaceAndMember())
        return NS_ERROR_UNEXPECTED;
    if(mState < HAVE_ARGS)
        return NS_ERROR_UNEXPECTED;

    if(!mTearOff)
    {
        mTearOff = mWrapper->FindTearOff(*this, mInterface, JS_FALSE, &rv);
        if(!mTearOff || mTearOff->GetInterface() != mInterface)
        {
            mTearOff = nsnull;    
            return NS_FAILED(rv) ? rv : NS_ERROR_UNEXPECTED;
        }
    }

    // Refresh in case FindTearOff extended the set
    mSet = mWrapper->GetSet();

    mState = READY_TO_CALL;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 199 of file xpcinlines.h.

{
    return mState >= HAVE_NAME;
}

Here is the caller graph for this function:

JSBool XPCCallContext::CanGetSet ( ) const [inline]

Definition at line 186 of file xpcinlines.h.

{
    return mState >= HAVE_NAME;
}

Here is the caller graph for this function:

Definition at line 166 of file xpcinlines.h.

{
    return mState >= HAVE_OBJECT;
}

Here is the caller graph for this function:

uintN XPCCallContext::GetArgc ( ) const [inline]

Definition at line 430 of file xpccallcontext.cpp.

{
    *aArgc = (PRUint32) mArgc;
    return NS_OK;
}

Here is the caller graph for this function:

jsval * XPCCallContext::GetArgv ( ) const [inline]

Definition at line 250 of file xpcinlines.h.

Here is the caller graph for this function:

JSObject * XPCCallContext::GetCallee ( ) const [inline]

Definition at line 374 of file xpccallcontext.cpp.

{
    nsISupports* temp = mWrapper ? mWrapper->GetIdentityObject() : nsnull;
    NS_IF_ADDREF(temp);
    *aCallee = temp;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 107 of file xpcinlines.h.

Definition at line 100 of file xpcinlines.h.

Definition at line 135 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 344 of file xpcinlines.h.

Definition at line 454 of file xpccallcontext.cpp.

{
    *aExceptionWasThrown = mExceptionWasThrown;
    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 142 of file xpcinlines.h.

Here is the caller graph for this function:

nsISupports * XPCCallContext::GetIdentityObject ( ) const [inline]

Definition at line 149 of file xpcinlines.h.

Here is the call graph for this function:

Definition at line 205 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 422 of file xpccallcontext.cpp.

{
    *aJSContext = mJSContext;
    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 212 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 330 of file xpcinlines.h.

Here is the caller graph for this function:

jsval XPCCallContext::GetName ( ) const [inline]

Definition at line 229 of file xpcinlines.h.

{
    CHECK_STATE(HAVE_NAME);
    return mName;
}

Here is the caller graph for this function:

Definition at line 128 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 121 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 114 of file xpcinlines.h.

Definition at line 286 of file xpcinlines.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 300 of file xpcinlines.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 468 of file xpccallcontext.cpp.

{
    *aReturnValueWasSet = mReturnValueWasSet;
    return NS_OK;
}

Here is the caller graph for this function:

jsval * XPCCallContext::GetRetVal ( ) const [inline]

Definition at line 257 of file xpcinlines.h.

Definition at line 62 of file xpcinlines.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 90 of file xpcinlines.h.

{
    CHECK_STATE(HAVE_CONTEXT);
    JSContext* cx;
    if(NS_SUCCEEDED(mThreadData->GetJSContextStack()->GetSafeJSContext(&cx)))
        return cx;
    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 179 of file xpcinlines.h.

XPCNativeSet * XPCCallContext::GetSet ( ) const [inline]

Definition at line 192 of file xpcinlines.h.

{
    CHECK_STATE(HAVE_NAME);
    return mSet;
}

Here is the caller graph for this function:

Definition at line 236 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 172 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 69 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 156 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 76 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 55 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 219 of file xpcinlines.h.

{
    return mState >= HAVE_NAME && mInterface && (mMember
#ifdef XPC_IDISPATCH_SUPPORT
        || mIDispatchMember
#endif
        );
}

Here is the caller graph for this function:

JSBool XPCCallContext::IsValid ( ) const [inline]

Definition at line 49 of file xpcinlines.h.

{
    return mState != INIT_FAILED;
}

Here is the caller graph for this function:

XPCCallContext::operator JSContext * ( ) const [inline]

Definition at line 905 of file xpcprivate.h.

{return GetJSContext();}

Here is the call graph for this function:

XPCCallContext& XPCCallContext::operator= ( const XPCCallContext r) [private]
void XPCCallContext::SetArgsAndResultPtr ( uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 237 of file xpccallcontext.cpp.

Here is the caller graph for this function:

void XPCCallContext::SetCallee ( JSObject callee) [inline]

Definition at line 322 of file xpcinlines.h.

{
    NS_ASSERTION(mCallerLanguage == NATIVE_CALLER,
                 "SetCallee() doesn't make sense");
    mCallee = callee;
}

Here is the caller graph for this function:

Definition at line 213 of file xpccallcontext.cpp.

{
    // We are going straight to the method info and need not do a lookup
    // by id.

    // don't be tricked if method is called with wrong 'this'
    if(mTearOff && mTearOff->GetInterface() != iface)
        mTearOff = nsnull;

    mSet = nsnull;
    mInterface = iface;
    mMember = member;
    mMethodIndex = mMember->GetIndex() + (isSetter ? 1 : 0);
    mName = mMember->GetName();

    if(mState < HAVE_NAME)
        mState = HAVE_NAME;
#ifdef XPC_IDISPATCH_SUPPORT
    mIDispatchMember = nsnull;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 337 of file xpcinlines.h.

Definition at line 169 of file xpccallcontext.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 293 of file xpcinlines.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 307 of file xpcinlines.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 278 of file xpcinlines.h.

Here is the caller graph for this function:

Definition at line 279 of file xpccallcontext.cpp.

{
    // XXX This is pretty questionable since the per thread cleanup stuff
    // can be making this call on one thread for call contexts on another
    // thread.
    NS_WARNING("Shutting Down XPConnect even through there is a live XPCCallContext");
    mThreadData = nsnull;
    mXPCContext = nsnull;
    mState = SYSTEM_SHUTDOWN;
    if(mPrevCallContext)
        mPrevCallContext->SystemIsBeingShutDown();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 271 of file nsIXPConnect.idl.

Definition at line 272 of file nsIXPConnect.idl.

readonly attribute nsISupports nsIXPCNativeCallContext::Callee [inherited]

Definition at line 267 of file nsIXPConnect.idl.

Definition at line 294 of file nsIXPConnect.idl.

Definition at line 293 of file nsIXPConnect.idl.

Definition at line 268 of file nsIXPConnect.idl.

Definition at line 269 of file nsIXPConnect.idl.

Set this if JS_SetPendingException has been called.

Return NS_OK or else this will be ignored and the native method's nsresult will be converted into an exception and thrown into JS as is the normal case.

Definition at line 282 of file nsIXPConnect.idl.

Definition at line 270 of file nsIXPConnect.idl.

Definition at line 975 of file xpcprivate.h.

Definition at line 976 of file xpcprivate.h.

Definition at line 990 of file xpcprivate.h.

Definition at line 952 of file xpcprivate.h.

Definition at line 949 of file xpcprivate.h.

Definition at line 961 of file xpcprivate.h.

Definition at line 950 of file xpcprivate.h.

Definition at line 979 of file xpcprivate.h.

Definition at line 962 of file xpcprivate.h.

Definition at line 969 of file xpcprivate.h.

Definition at line 948 of file xpcprivate.h.

Definition at line 970 of file xpcprivate.h.

Definition at line 984 of file xpcprivate.h.

Definition at line 972 of file xpcprivate.h.

Definition at line 960 of file xpcprivate.h.

Definition at line 958 of file xpcprivate.h.

Definition at line 956 of file xpcprivate.h.

Definition at line 980 of file xpcprivate.h.

Definition at line 977 of file xpcprivate.h.

Definition at line 966 of file xpcprivate.h.

Definition at line 968 of file xpcprivate.h.

Definition at line 942 of file xpcprivate.h.

Definition at line 973 of file xpcprivate.h.

Definition at line 964 of file xpcprivate.h.

Definition at line 946 of file xpcprivate.h.

Definition at line 963 of file xpcprivate.h.

Definition at line 944 of file xpcprivate.h.

Definition at line 947 of file xpcprivate.h.

Set this to indicate that the callee has directly set the return value (using RetValPtr and the JSAPI).

If set then xpconnect will not attempt to overwrite it with the converted retval from the C++ callee.

Definition at line 289 of file nsIXPConnect.idl.

This may be NULL if the JS caller is ignoring the result of the call.

Definition at line 276 of file nsIXPConnect.idl.


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