Back to index

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

#include <xpcprivate.h>

Collaboration diagram for XPCWrappedNativeScope:
Collaboration graph
[legend]

List of all members.

Public Member Functions

XPCJSRuntimeGetRuntime () const
Native2WrappedNativeMapGetWrappedNativeMap () const
ClassInfo2WrappedNativeProtoMapGetWrappedNativeProtoMap () const
nsXPCComponentsGetComponents () const
JSObjectGetGlobalJSObject () const
JSObjectGetPrototypeJSObject () const
JSObjectGetPrototypeJSFunction () const
void RemoveWrappedNativeProtos ()
void DebugDump (PRInt16 depth)
JSBool IsValid () const
void SetComponents (nsXPCComponents *aComponents)
void SetGlobal (XPCCallContext &ccx, JSObject *aGlobal)

Static Public Member Functions

static XPCWrappedNativeScopeGetNewOrUsed (XPCCallContext &ccx, JSObject *aGlobal)
static XPCWrappedNativeScopeFindInJSObjectScope (XPCCallContext &ccx, JSObject *obj, JSBool OKIfNotInitialized=JS_FALSE)
static void SystemIsBeingShutDown (XPCCallContext &ccx)
static void FinishedMarkPhaseOfGC (JSContext *cx, XPCJSRuntime *rt)
static void FinishedFinalizationPhaseOfGC (JSContext *cx)
static void MarkAllWrappedNativesAndProtos ()
static nsresult ClearAllWrappedNativeSecurityPolicies (XPCCallContext &ccx)
static void SweepAllWrappedNativeTearOffs ()
static void DebugDumpAllScopes (PRInt16 depth)
static void InitStatics ()

Protected Member Functions

 XPCWrappedNativeScope (XPCCallContext &ccx, JSObject *aGlobal)
virtual ~XPCWrappedNativeScope ()
 XPCWrappedNativeScope ()

Static Protected Member Functions

static void KillDyingScopes ()

Private Attributes

XPCJSRuntimemRuntime
Native2WrappedNativeMapmWrappedNativeMap
ClassInfo2WrappedNativeProtoMapmWrappedNativeProtoMap
nsXPCComponentsmComponents
XPCWrappedNativeScopemNext
JSObjectmGlobalJSObject
JSObjectmPrototypeJSObject
JSObjectmPrototypeJSFunction

Static Private Attributes

static XPCWrappedNativeScopegScopes = nsnull
static XPCWrappedNativeScopegDyingScopes = nsnull

Detailed Description

Definition at line 1040 of file xpcprivate.h.


Constructor & Destructor Documentation

Definition at line 217 of file xpcwrappednativescope.cpp.

{
    MOZ_COUNT_DTOR(XPCWrappedNativeScope);
    DEBUG_TrackDeleteScope(this);

    // We can do additional cleanup assertions here...

    if(mWrappedNativeMap)
    {
        NS_ASSERTION(0 == mWrappedNativeMap->Count(), "scope has non-empty map");
        delete mWrappedNativeMap;
    }

    if(mWrappedNativeProtoMap)
    {
        NS_ASSERTION(0 == mWrappedNativeProtoMap->Count(), "scope has non-empty map");
        delete mWrappedNativeProtoMap;
    }

    // XXX we should assert that we are dead or that xpconnect has shutdown
    // XXX might not want to do this at xpconnect shutdown time???
    NS_IF_RELEASE(mComponents);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 654 of file xpcwrappednativescope.cpp.

{
    // Hold the lock throughout.
    XPCAutoLock lock(ccx.GetRuntime()->GetMapLock());

    for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
    {
        cur->mWrappedNativeProtoMap->Enumerate(WNProtoSecPolicyClearer, nsnull);
        cur->mWrappedNativeMap->Enumerate(WNSecPolicyClearer, nsnull);
    }

    DEBUG_TrackScopeTraversal();

    return NS_OK;
}

Here is the call graph for this function:

Definition at line 736 of file xpcwrappednativescope.cpp.

{
#ifdef DEBUG
    depth-- ;
    XPC_LOG_ALWAYS(("XPCWrappedNativeScope @ %x", this));
    XPC_LOG_INDENT();
        XPC_LOG_ALWAYS(("mRuntime @ %x", mRuntime));
        XPC_LOG_ALWAYS(("mNext @ %x", mNext));
        XPC_LOG_ALWAYS(("mComponents @ %x", mComponents));
        XPC_LOG_ALWAYS(("mGlobalJSObject @ %x", mGlobalJSObject));
        XPC_LOG_ALWAYS(("mPrototypeJSObject @ %x", mPrototypeJSObject));
        XPC_LOG_ALWAYS(("mPrototypeJSFunction @ %x", mPrototypeJSFunction));

        XPC_LOG_ALWAYS(("mWrappedNativeMap @ %x with %d wrappers(s)", \
                         mWrappedNativeMap, \
                         mWrappedNativeMap ? mWrappedNativeMap->Count() : 0));
        // iterate contexts...
        if(depth && mWrappedNativeMap && mWrappedNativeMap->Count())
        {
            XPC_LOG_INDENT();
            mWrappedNativeMap->Enumerate(WrappedNativeMapDumpEnumerator, &depth);
            XPC_LOG_OUTDENT();
        }

        XPC_LOG_ALWAYS(("mWrappedNativeProtoMap @ %x with %d protos(s)", \
                         mWrappedNativeProtoMap, \
                         mWrappedNativeProtoMap ? mWrappedNativeProtoMap->Count() : 0));
        // iterate contexts...
        if(depth && mWrappedNativeProtoMap && mWrappedNativeProtoMap->Count())
        {
            XPC_LOG_INDENT();
            mWrappedNativeProtoMap->Enumerate(WrappedNativeProtoMapDumpEnumerator, &depth);
            XPC_LOG_OUTDENT();
        }
    XPC_LOG_OUTDENT();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 697 of file xpcwrappednativescope.cpp.

{
#ifdef DEBUG
    depth-- ;

    // get scope count.
    int count = 0;
    XPCWrappedNativeScope* cur;
    for(cur = gScopes; cur; cur = cur->mNext)
        count++ ;

    XPC_LOG_ALWAYS(("chain of %d XPCWrappedNativeScope(s)", count));
    XPC_LOG_INDENT();
        XPC_LOG_ALWAYS(("gDyingScopes @ %x", gDyingScopes));
        if(depth)
            for(cur = gScopes; cur; cur = cur->mNext)
                cur->DebugDump(depth);
    XPC_LOG_OUTDENT();
#endif
}

Here is the call graph for this function:

Definition at line 583 of file xpcwrappednativescope.cpp.

{
    XPCWrappedNativeScope* scope;

    if(!obj)
        return nsnull;

    // If this object is itself a wrapped native then we can get the
    // scope directly.

    scope = GetScopeOfObject(ccx, obj);
    if(scope)
        return scope;

    // Else we'll have to look up the parent chain to get the scope

    JSObject* parent;

    while(nsnull != (parent = JS_GetParent(ccx, obj)))
        obj = parent;

    // XXX We are assuming that the scope count is low enough that traversing
    // the linked list is more reasonable then doing a hashtable lookup.
    {   // scoped lock
        XPCAutoLock lock(ccx.GetRuntime()->GetMapLock());

        DEBUG_TrackScopeTraversal();

        for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
        {
            if(obj == cur->GetGlobalJSObject())
            {
                DEBUG_CheckForComponentsInScope(ccx, obj, OKIfNotInitialized);
                return cur;
            }
        }
    }

    // Failure to find the scope is only OK if the caller told us it might fail.
    // This flag would only be set in the call from
    // XPCWrappedNativeScope::GetNewOrUsed
    NS_ASSERTION(OKIfNotInitialized, "No scope has this global object!");
    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 315 of file xpcwrappednativescope.cpp.

{
    XPCJSRuntime* rt = nsXPConnect::GetRuntime();
    if(!rt)
        return;

    // Hold the lock until return...
    XPCAutoLock lock(rt->GetMapLock());
    KillDyingScopes();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 257 of file xpcwrappednativescope.cpp.

{
    // Hold the lock until return...
    XPCAutoLock lock(rt->GetMapLock());

    XPCWrappedNativeScope* cur;
    
    // Do JS_MarkGCThing for all wrapperednatives with external references.
    for(cur = gScopes; cur; cur = cur->mNext)
    {
        cur->mWrappedNativeMap->Enumerate(WrappedNativeJSGCThingMarker, cx);
    }

    // Since the JSGC_END call happens outside of a lock,
    // it is possible for us to get called here twice before the FinshedGC
    // call happens. So, we allow for gDyingScopes not being null.

    XPCWrappedNativeScope* prev = nsnull;
    cur = gScopes;

    while(cur)
    {
        XPCWrappedNativeScope* next = cur->mNext;
        if(cur->mGlobalJSObject &&
           JS_IsAboutToBeFinalized(cx, cur->mGlobalJSObject))
        {
            cur->mGlobalJSObject = nsnull;

            // Move this scope from the live list to the dying list.
            if(prev)
                prev->mNext = next;
            else
                gScopes = next;
            cur->mNext = gDyingScopes;
            gDyingScopes = cur;
            cur = nsnull;
        }
        else
        {
            if(cur->mPrototypeJSObject &&
               JS_IsAboutToBeFinalized(cx, cur->mPrototypeJSObject))
            {
                cur->mPrototypeJSObject = nsnull;
            }
            if(cur->mPrototypeJSFunction &&
               JS_IsAboutToBeFinalized(cx, cur->mPrototypeJSFunction))
            {
                cur->mPrototypeJSFunction = nsnull;
            }
        }
        if(cur)
            prev = cur;
        cur = next;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1057 of file xpcprivate.h.

{return mComponents;}

Here is the caller graph for this function:

Definition at line 1060 of file xpcprivate.h.

{return mGlobalJSObject;}

Here is the caller graph for this function:

Definition at line 115 of file xpcwrappednativescope.cpp.

{

    XPCWrappedNativeScope* scope = FindInJSObjectScope(ccx, aGlobal, JS_TRUE);
    if(!scope)
        scope = new XPCWrappedNativeScope(ccx, aGlobal);
    else
    {
        // We need to call SetGlobal in order to refresh our cached 
        // mPrototypeJSObject and mPrototypeJSFunction in the case where
        // the global object is being reused (JS_ClearScope has been
        // called).
        // NOTE: We are only called by nsXPConnect::InitClasses. 
        scope->SetGlobal(ccx, aGlobal);
    }
    return scope;
}

Here is the call graph for this function:

Definition at line 1066 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 1063 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 1048 of file xpcprivate.h.

{return mRuntime;}

Here is the caller graph for this function:

Definition at line 1051 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 1054 of file xpcprivate.h.

Here is the caller graph for this function:

static void XPCWrappedNativeScope::InitStatics ( ) [inline, static]

Definition at line 1109 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 1104 of file xpcprivate.h.

{return mRuntime != nsnull;}

Definition at line 408 of file xpcwrappednativescope.cpp.

{
    // always called inside the lock!
    XPCWrappedNativeScope* cur = gDyingScopes;
    while(cur)
    {
        XPCWrappedNativeScope* next = cur->mNext;
        delete cur;
        cur = next;
    }
    gDyingScopes = nsnull;
}

Here is the caller graph for this function:

Definition at line 346 of file xpcwrappednativescope.cpp.

{
    for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
    {
        cur->mWrappedNativeMap->Enumerate(WrappedNativeMarker, nsnull);
        cur->mWrappedNativeProtoMap->Enumerate(WrappedNativeProtoMarker, nsnull);
    }

    DEBUG_TrackScopeTraversal();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 685 of file xpcwrappednativescope.cpp.

{
    XPCAutoLock al(mRuntime->GetMapLock());
    
    mWrappedNativeProtoMap->Enumerate(WNProtoRemover, 
        GetRuntime()->GetDetachedWrappedNativeProtoMap());
}

Here is the call graph for this function:

Definition at line 167 of file xpcwrappednativescope.cpp.

{
    NS_IF_ADDREF(aComponents);
    NS_IF_RELEASE(mComponents);
    mComponents = aComponents;
}

Here is the caller graph for this function:

Definition at line 175 of file xpcwrappednativescope.cpp.

{
    // We allow for calling this more than once. This feature is used by
    // nsXPConnect::InitClassesWithNewWrappedGlobal.

    mGlobalJSObject = aGlobal;

    // Lookup 'globalObject.Object.prototype' for our wrapper's proto
    {
        AutoJSErrorAndExceptionEater eater(ccx); // scoped error eater

        jsval val;
        jsid idObj = mRuntime->GetStringID(XPCJSRuntime::IDX_OBJECT);
        jsid idFun = mRuntime->GetStringID(XPCJSRuntime::IDX_FUNCTION);
        jsid idProto = mRuntime->GetStringID(XPCJSRuntime::IDX_PROTOTYPE);

        if(OBJ_GET_PROPERTY(ccx, aGlobal, idObj, &val) &&
           !JSVAL_IS_PRIMITIVE(val) &&
           OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
           !JSVAL_IS_PRIMITIVE(val))
        {
            mPrototypeJSObject = JSVAL_TO_OBJECT(val);
        }
        else
        {
            NS_ERROR("Can't get globalObject.Object.prototype");
        }

        if(OBJ_GET_PROPERTY(ccx, aGlobal, idFun, &val) &&
           !JSVAL_IS_PRIMITIVE(val) &&
           OBJ_GET_PROPERTY(ccx, JSVAL_TO_OBJECT(val), idProto, &val) &&
           !JSVAL_IS_PRIMITIVE(val))
        {
            mPrototypeJSFunction = JSVAL_TO_OBJECT(val);
        }
        else
        {
            NS_ERROR("Can't get globalObject.Function.prototype");
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 398 of file xpcwrappednativescope.cpp.

{
    for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
        cur->mWrappedNativeMap->Enumerate(WrappedNativeTearoffSweeper, nsnull);

    DEBUG_TrackScopeTraversal();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 462 of file xpcwrappednativescope.cpp.

{
    DEBUG_TrackScopeTraversal();
    DEBUG_TrackScopeShutdown();

    int liveScopeCount = 0;

    ShutdownData data(ccx);

    XPCWrappedNativeScope* cur;

    // First move all the scopes to the dying list.

    cur = gScopes;
    while(cur)
    {
        XPCWrappedNativeScope* next = cur->mNext;
        cur->mNext = gDyingScopes;
        gDyingScopes = cur;
        cur = next;
        liveScopeCount++;
    }
    gScopes = nsnull;

    // Walk the unified dying list and call shutdown on all wrappers and protos

    for(cur = gDyingScopes; cur; cur = cur->mNext)
    {
        // Give the Components object a chance to try to clean up.
        if(cur->mComponents)
            cur->mComponents->SystemIsBeingShutDown();

        // Walk the protos first. Wrapper shutdown can leave dangling
        // proto pointers in the proto map.
        cur->mWrappedNativeProtoMap->
                Enumerate(WrappedNativeProtoShutdownEnumerator,  &data);
        cur->mWrappedNativeMap->
                Enumerate(WrappedNativeShutdownEnumerator,  &data);
    }

    // Now it is safe to kill all the scopes.
    KillDyingScopes();

#ifdef XPC_DUMP_AT_SHUTDOWN
    if(data.wrapperCount)
        printf("deleting nsXPConnect  with %d live XPCWrappedNatives\n",
               data.wrapperCount);
    if(data.sharedProtoCount + data.nonSharedProtoCount)
        printf("deleting nsXPConnect  with %d live XPCWrappedNativeProtos (%d shared)\n",
               data.sharedProtoCount + data.nonSharedProtoCount,
               data.sharedProtoCount);
    if(liveScopeCount)
        printf("deleting nsXPConnect  with %d live XPCWrappedNativeScopes\n",
               liveScopeCount);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1121 of file xpcprivate.h.

Definition at line 1120 of file xpcprivate.h.

Definition at line 1126 of file xpcprivate.h.

Definition at line 1128 of file xpcprivate.h.

Definition at line 1127 of file xpcprivate.h.

Definition at line 1130 of file xpcprivate.h.

Definition at line 1129 of file xpcprivate.h.

Definition at line 1123 of file xpcprivate.h.

Definition at line 1124 of file xpcprivate.h.

Definition at line 1125 of file xpcprivate.h.


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