Back to index

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

#include <xpcprivate.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
NS_DECL_NSIXPCONNECTWRAPPEDJS
NS_DECL_NSIXPCONNECTWRAPPEDJS_MOZILLA_1_8_BRANCH
NS_DECL_NSIPROPERTYBAG
NS_IMETHOD 
CallMethod (PRUint16 methodIndex, const nsXPTMethodInfo *info, nsXPTCMiniVariant *params)
JSObjectGetJSObject () const
nsXPCWrappedJSClassGetClass () const
REFNSIID GetIID () const
nsXPCWrappedJSGetRootWrapper () const
nsXPCWrappedJSGetNextWrapper () const
nsXPCWrappedJSFind (REFNSIID aIID)
nsXPCWrappedJSFindInherited (REFNSIID aIID)
JSBool IsValid () const
void SystemIsBeingShutDown (JSRuntime *rt)
JSBool IsSubjectToFinalization () const
JSBool IsAggregatedToNative () const
nsISupports * GetAggregatedNativeObject () const
virtual ~nsXPCWrappedJS ()
nsIWeakReference GetWeakReference ()
void debugDump (in short depth)
void aggregatedQueryInterface (in nsIIDRef uuid,[iid_is(uuid), retval] out nsQIResult result)
nsIVariant getProperty (in AString name)
 Get a property value for the given name.

Static Public Member Functions

static nsresult GetNewOrUsed (XPCCallContext &ccx, JSObject *aJSObj, REFNSIID aIID, nsISupports *aOuter, nsXPCWrappedJS **wrapper)

Public Attributes

readonly attribute nsIInterfaceInfo InterfaceInfo
readonly attribute nsIIDPtr InterfaceIID
readonly attribute JSObjectPtr JSObject
readonly attribute
nsISimpleEnumerator 
enumerator
 Get a nsISimpleEnumerator whose elements are nsIProperty objects.

Protected Member Functions

 nsXPCWrappedJS ()
 nsXPCWrappedJS (XPCCallContext &ccx, JSObject *aJSObj, nsXPCWrappedJSClass *aClass, nsXPCWrappedJS *root, nsISupports *aOuter)

Private Attributes

JSObjectmJSObj
nsXPCWrappedJSClassmClass
nsXPCWrappedJSmRoot
nsXPCWrappedJSmNext
nsISupports * mOuter

Detailed Description

Definition at line 2214 of file xpcprivate.h.


Constructor & Destructor Documentation

Definition at line 353 of file xpcwrappedjs.cpp.

{
    NS_PRECONDITION(0 == mRefCnt, "refcounting error");

    XPCJSRuntime* rt = nsXPConnect::GetRuntime();

    if(mRoot != this)
    {
        // unlink this wrapper
        nsXPCWrappedJS* cur = mRoot;
        while(1)
        {
            if(cur->mNext == this)
            {
                cur->mNext = mNext;
                break;
            }
            cur = cur->mNext;
            NS_ASSERTION(cur, "failed to find wrapper in its own chain");
        }
        // let the root go
        NS_RELEASE(mRoot);
    }
    else
    {
        NS_ASSERTION(!mNext, "root wrapper with non-empty chain being deleted");

        // Let the nsWeakReference object (if present) know of our demise.
        ClearWeakReferences();

        // remove this root wrapper from the map
        if(rt)
        {
            JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
            if(map)
            {
                XPCAutoLock lock(rt->GetMapLock());
                map->Remove(this);
            }
        }
    }

    if(IsValid())
    {
        NS_IF_RELEASE(mClass);
        if (mOuter)
        {
            if (rt && rt->GetThreadRunningGC())
            {
                rt->DeferredRelease(mOuter);
                mOuter = nsnull;
            }
            else
            {
                NS_RELEASE(mOuter);
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsXPCWrappedJS::nsXPCWrappedJS ( XPCCallContext ccx,
JSObject aJSObj,
nsXPCWrappedJSClass aClass,
nsXPCWrappedJS root,
nsISupports *  aOuter 
) [protected]

Definition at line 321 of file xpcwrappedjs.cpp.

    : mJSObj(aJSObj),
      mClass(aClass),
      mRoot(root ? root : this),
      mNext(nsnull),
      mOuter(root ? nsnull : aOuter)
#ifdef GC_MARK_DEBUG
      , mGCRootName(nsnull)
#endif
{
#ifdef DEBUG_stats_jband
    static int count = 0;
    static const int interval = 10;
    if(0 == (++count % interval))
        printf("//////// %d instances of nsXPCWrappedJS created\n", count);
#endif

    // intensionally do double addref - see Release().
    NS_ADDREF_THIS();
    NS_ADDREF_THIS();
    NS_ADDREF(aClass);
    NS_IF_ADDREF(mOuter);

    if(mRoot != this)
        NS_ADDREF(mRoot);

}

Here is the call graph for this function:


Member Function Documentation

void nsIXPConnectWrappedJS::aggregatedQueryInterface ( in nsIIDRef  uuid,
[iid_is(uuid), retval] out nsQIResult  result 
) [inherited]

Definition at line 461 of file xpcwrappedjs.cpp.

{
    if(!IsValid())
        return NS_ERROR_UNEXPECTED;
    return GetClass()->CallMethod(this, methodIndex, info, params);
}

Here is the call graph for this function:

void nsIXPConnectWrappedJS::debugDump ( in short  depth) [inherited]

Definition at line 414 of file xpcwrappedjs.cpp.

{
    if(aIID.Equals(NS_GET_IID(nsISupports)))
        return mRoot;

    for(nsXPCWrappedJS* cur = mRoot; cur; cur = cur->mNext)
    {
        if(aIID.Equals(cur->GetIID()))
            return cur;
    }

    return nsnull;
}

Here is the caller graph for this function:

Definition at line 430 of file xpcwrappedjs.cpp.

{
    NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsISupports)), "bad call sequence");

    for(nsXPCWrappedJS* cur = mRoot; cur; cur = cur->mNext)
    {
        PRBool found;
        if(NS_SUCCEEDED(cur->GetClass()->GetInterfaceInfo()->
                                HasAncestor(&aIID, &found)) && found)
            return cur;
    }

    return nsnull;
}

Here is the caller graph for this function:

nsISupports* nsXPCWrappedJS::GetAggregatedNativeObject ( ) const [inline]

Definition at line 2269 of file xpcprivate.h.

{return mRoot->mOuter;}

Definition at line 2249 of file xpcprivate.h.

{return mClass;}

Here is the caller graph for this function:

REFNSIID nsXPCWrappedJS::GetIID ( ) const [inline]

Definition at line 2250 of file xpcprivate.h.

{return GetClass()->GetIID();}

Here is the caller graph for this function:

Definition at line 2248 of file xpcprivate.h.

{return mJSObj;}

Here is the caller graph for this function:

nsresult nsXPCWrappedJS::GetNewOrUsed ( XPCCallContext ccx,
JSObject aJSObj,
REFNSIID  aIID,
nsISupports *  aOuter,
nsXPCWrappedJS **  wrapper 
) [static]

Definition at line 216 of file xpcwrappedjs.cpp.

{
    JSObject2WrappedJSMap* map;
    JSObject* rootJSObj;
    nsXPCWrappedJS* root;
    nsXPCWrappedJS* wrapper = nsnull;
    nsXPCWrappedJSClass* clazz = nsnull;
    XPCJSRuntime* rt = ccx.GetRuntime();

    map = rt->GetWrappedJSMap();
    if(!map)
    {
        NS_ASSERTION(map,"bad map");
        return NS_ERROR_FAILURE;
    }

    nsXPCWrappedJSClass::GetNewOrUsed(ccx, aIID, &clazz);
    if(!clazz)
        return NS_ERROR_FAILURE;
    // from here on we need to return through 'return_wrapper'

    // always find the root JSObject
    rootJSObj = clazz->GetRootJSObject(ccx, aJSObj);
    if(!rootJSObj)
        goto return_wrapper;

    // look for the root wrapper
    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        root = map->Find(rootJSObj);
    }
    if(root)
    {
        if((nsnull != (wrapper = root->Find(aIID))) ||
           (nsnull != (wrapper = root->FindInherited(aIID))))
        {
            NS_ADDREF(wrapper);
            goto return_wrapper;
        }
    }
    else
    {
        // build the root wrapper
        if(rootJSObj == aJSObj)
        {
            // the root will do double duty as the interface wrapper
            wrapper = root = new nsXPCWrappedJS(ccx, aJSObj, clazz, nsnull,
                                                aOuter);
            if(root)
            {   // scoped lock
                XPCAutoLock lock(rt->GetMapLock());
                map->Add(root);
            }
            goto return_wrapper;
        }
        else
        {
            // just a root wrapper
            nsXPCWrappedJSClass* rootClazz = nsnull;
            nsXPCWrappedJSClass::GetNewOrUsed(ccx, NS_GET_IID(nsISupports),
                                              &rootClazz);
            if(!rootClazz)
                goto return_wrapper;

            root = new nsXPCWrappedJS(ccx, rootJSObj, rootClazz, nsnull, aOuter);
            NS_RELEASE(rootClazz);

            if(!root)
                goto return_wrapper;
            {   // scoped lock
                XPCAutoLock lock(rt->GetMapLock());
                map->Add(root);
            }
        }
    }

    // at this point we have a root and may need to build the specific wrapper
    NS_ASSERTION(root,"bad root");
    NS_ASSERTION(clazz,"bad clazz");

    if(!wrapper)
    {
        wrapper = new nsXPCWrappedJS(ccx, aJSObj, clazz, root, aOuter);
        if(!wrapper)
            goto return_wrapper;
    }

    wrapper->mNext = root->mNext;
    root->mNext = wrapper;

return_wrapper:
    if(clazz)
        NS_RELEASE(clazz);

    if(!wrapper)
        return NS_ERROR_FAILURE;

    *wrapperResult = wrapper;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2252 of file xpcprivate.h.

{return mNext;}

Here is the caller graph for this function:

nsIVariant nsIPropertyBag::getProperty ( in AString  name) [inherited]

Get a property value for the given name.

Exceptions:
NS_ERROR_FAILUREif a property with that name doesn't exist.

Definition at line 2251 of file xpcprivate.h.

{return mRoot;}

Here is the caller graph for this function:

Definition at line 2268 of file xpcprivate.h.

{return mRoot->mOuter != nsnull;}

Definition at line 2266 of file xpcprivate.h.

{return IsValid() && mRefCnt == 1;}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool nsXPCWrappedJS::IsValid ( ) const [inline]

Definition at line 2257 of file xpcprivate.h.

{return mJSObj != nsnull;}

Here is the caller graph for this function:

Definition at line 480 of file xpcwrappedjs.cpp.

{
    // XXX It turns out that it is better to leak here then to do any Releases
    // and have them propagate into all sorts of mischief as the system is being
    // shutdown. This was learned the hard way :(

    // mJSObj == nsnull is used to indicate that the wrapper is no longer valid
    // and that calls should fail without trying to use any of the
    // xpconnect mechanisms. 'IsValid' is implemented by checking this pointer.

    // NOTE: that mClass is retained so that GetInterfaceInfo can continue to
    // work (and avoid crashing some platforms).
    mJSObj = nsnull;

    // There is no reason to keep this root any longer. Since we've cleared
    // mJSObj our dtor will not remove the root later. So, we do it now.
    JS_RemoveRootRT(rt, &mJSObj);

    // Notify other wrappers in the chain.
    if(mNext)
        mNext->SystemIsBeingShutDown(rt);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Get a nsISimpleEnumerator whose elements are nsIProperty objects.

Definition at line 53 of file nsIPropertyBag.idl.

readonly attribute nsIIDPtr nsIXPConnectWrappedJS::InterfaceIID [inherited]

Definition at line 220 of file nsIXPConnect.idl.

Definition at line 219 of file nsIXPConnect.idl.

Definition at line 156 of file nsIXPConnect.idl.

Definition at line 2282 of file xpcprivate.h.

Definition at line 2281 of file xpcprivate.h.

Definition at line 2284 of file xpcprivate.h.

nsISupports* nsXPCWrappedJS::mOuter [private]

Definition at line 2285 of file xpcprivate.h.

Definition at line 2283 of file xpcprivate.h.


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