Back to index

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

#include <xpcprivate.h>

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

List of all members.

Public Member Functions

nsIXPCSecurityManagerGetDefaultSecurityManager () const
PRUint16 GetDefaultSecurityManagerFlags () const
virtual ~nsXPConnect ()
JSBool IsShuttingDown () const
nsresult GetInfoForIID (const nsIID *aIID, nsIInterfaceInfo **info)
nsresult GetInfoForName (const char *name, nsIInterfaceInfo **info)
JSVal evalInSandboxObject2 (in AString source, in JSContextPtr cx, in nsIXPConnectJSObjectHolder sandbox, in PRBool returnStringOnly)
 Evaluate script in a sandbox, completely isolated from all other running scripts.
void reparentScopeAwareWrappers (in JSContextPtr aJSContext, in JSObjectPtr aOldScope, in JSObjectPtr aNewScope)
nsIXPConnectJSObjectHolder createSandbox (in JSContextPtr cx, in nsIPrincipal principal)
 Create a sandbox for evaluating code in isolation using evalInSandboxObject().
JSVal evalInSandboxObject (in AString source, in JSContextPtr cx, in nsIXPConnectJSObjectHolder sandbox)
 Evaluate script in a sandbox, completely isolated from all other running scripts.
void initClasses (in JSContextPtr aJSContext, in JSObjectPtr aGlobalJSObj)
nsIXPConnectJSObjectHolder initClassesWithNewWrappedGlobal (in JSContextPtr aJSContext, in nsISupports aCOMObj, in nsIIDRef aIID, in PRUint32 aFlags)
nsIXPConnectJSObjectHolder wrapNative (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDRef aIID)
 wrapNative will create a new JSObject or return an existing one.
void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID,[iid_is(aIID), retval] out nsQIResult result)
 wrapJS will yield a new or previously existing xpcom interface pointer to represent the JSObject passed in.
nsIXPConnectWrappedNative getWrappedNativeOfJSObject (in JSContextPtr aJSContext, in JSObjectPtr aJSObj)
 This only succeeds if the JSObject is a nsIXPConnectWrappedNative.
void setSecurityManagerForJSContext (in JSContextPtr aJSContext, in nsIXPCSecurityManager aManager, in PRUint16 flags)
void getSecurityManagerForJSContext (in JSContextPtr aJSContext, out nsIXPCSecurityManager aManager, out PRUint16 flags)
void setDefaultSecurityManager (in nsIXPCSecurityManager aManager, in PRUint16 flags)
 The security manager to use when the current JSContext has no security manager.
void getDefaultSecurityManager (out nsIXPCSecurityManager aManager, out PRUint16 flags)
nsIStackFrame createStackFrameLocation (in PRUint32 aLanguage, in string aFilename, in string aFunctionName, in PRInt32 aLineNumber, in nsIStackFrame aCaller)
void syncJSContexts ()
 XPConnect builds internal objects that parallel, and are one-to-one with, the JSContexts in the JSRuntime.
void debugDump (in short depth)
void debugDumpObject (in nsISupports aCOMObj, in short depth)
void debugDumpJSStack (in PRBool showArgs, in PRBool showLocals, in PRBool showThisProps)
void debugDumpEvalInJSStackFrame (in PRUint32 aFrameNumber, in string aSourceText)
void setSafeJSContextForCurrentThread (in JSContextPtr cx)
 Set fallback JSContext to use when xpconnect can't find an appropriate context to use to execute JavaScript.
void wrapJSAggregatedToNative (in nsISupports aOuter, in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID,[iid_is(aIID), retval] out nsQIResult result)
 wrapJSAggregatedToNative is just like wrapJS except it is used in cases where the JSObject is also aggregated to some native xpcom Object.
nsIXPConnectWrappedNative getWrappedNativeOfNativeObject (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDRef aIID)
 This only succeeds if the native object is already wrapped by xpconnect.
nsIXPCFunctionThisTranslator getFunctionThisTranslator (in nsIIDRef aIID)
nsIXPCFunctionThisTranslator setFunctionThisTranslator (in nsIIDRef aIID, in nsIXPCFunctionThisTranslator aTranslator)
nsIXPConnectJSObjectHolder reparentWrappedNativeIfFound (in JSContextPtr aJSContext, in JSObjectPtr aScope, in JSObjectPtr aNewParent, in nsISupports aCOMObj)
void clearAllWrappedNativeSecurityPolicies ()
nsIXPConnectJSObjectHolder getWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo)
void releaseJSContext (in JSContextPtr aJSContext, in PRBool noGC)
JSVal variantToJS (in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value)
nsIVariant JSToVariant (in JSContextPtr ctx, in JSVal value)
void flagSystemFilenamePrefix (in string aFilenamePrefix)
 Preconfigure XPCNativeWrapper automation so that when a scripted caller whose filename starts with filenamePrefix accesses a wrapped native that is not flagged as "system", the wrapped native will be automatically wrapped with an XPCNativeWrapper.
void restoreWrappedNativePrototype (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsIClassInfo aClassInfo, in nsIXPConnectJSObjectHolder aPrototype)
 Restore an old prototype for wrapped natives of type aClassInfo.
void willProcessEvents (in nsIEventQueue aQueue)
 Call before processing events.
void didProcessEvents (in nsIEventQueue aQueue)
 Call after processing events.

Static Public Member Functions

static nsXPConnectGetXPConnect ()
static XPCJSRuntimeGetRuntime (nsXPConnect *xpc=nsnull)
static XPCContextGetContext (JSContext *cx, nsXPConnect *xpc=nsnull)
static nsIJSRuntimeServiceGetJSRuntimeService (nsXPConnect *xpc=nsnull)
static nsresult GetInterfaceInfoManager (nsIInterfaceInfoSuperManager **iim, nsXPConnect *xpc=nsnull)
static nsresult GetContextStack (nsIThreadJSContextStack **stack, nsXPConnect *xpc=nsnull)
static JSBool IsISupportsDescendant (nsIInterfaceInfo *info)
static PRThreadGetMainThread ()
static nsXPConnectGetSingleton ()
static void InitStatics ()
static void ReleaseXPConnectSingleton ()

Public Attributes

const PRUint32 INIT_JS_STANDARD_CLASSES = 1 << 0
const PRUint32 FLAG_SYSTEM_GLOBAL_OBJECT = 1 << 1
readonly attribute nsIStackFrame CurrentJSStack
readonly attribute
nsIXPCNativeCallContext 
CurrentNativeCallContext
attribute nsIException PendingException
attribute PRBool collectGarbageOnMainThreadOnly
attribute PRBool deferReleasesUntilAfterGarbageCollection

Protected Member Functions

 nsXPConnect ()

Private Member Functions

JSBool EnsureRuntime ()
JSBool CreateRuntime ()

Static Private Member Functions

static PRThreadFindMainThread ()

Private Attributes

XPCJSRuntimemRuntime
nsIInterfaceInfoSuperManagermInterfaceInfoManager
nsIThreadJSContextStackmContextStack
nsIXPCSecurityManagermDefaultSecurityManager
PRUint16 mDefaultSecurityManagerFlags
JSBool mShuttingDown

Static Private Attributes

static nsXPConnectgSelf
static JSBool gOnceAliveNowDead
static PRThreadgMainThread = nsnull

Detailed Description

Definition at line 425 of file xpcprivate.h.


Constructor & Destructor Documentation

Definition at line 114 of file nsXPConnect.cpp.

{
    // XXX It would be nice if we could get away with doing a GC here and also
    // calling Release on the natives no longer reachable via XPConnect. As
    // noted all over the place, this makes bad things happen since shutdown is
    // an unstable time for so many modules who have not planned well for it.

    mShuttingDown = JS_TRUE;
    { // scoped callcontext
        XPCCallContext ccx(NATIVE_CALLER);
        if(ccx.IsValid())
        {
            XPCWrappedNativeScope::SystemIsBeingShutDown(ccx);
            if(mRuntime)
                mRuntime->SystemIsBeingShutDown(&ccx);
                
        }
    }

    NS_IF_RELEASE(mInterfaceInfoManager);
    NS_IF_RELEASE(mContextStack);
    NS_IF_RELEASE(mDefaultSecurityManager);

    // Unfortunately calling CleanupAllThreads before the stuff above
    // (esp. SystemIsBeingShutDown) causes too many bad things to happen
    // as the Release calls propagate. See the comment in this function in
    // revision 1.35 of this file.
    //
    // I filed a bug on xpcom regarding the bad things that happen
    // if people try to create components during shutdown.
    // http://bugzilla.mozilla.org/show_bug.cgi?id=37058
    //
    // Also, we just plain need the context stack for at least the current
    // thread to be in place. Unfortunately, this will leak stuff on the
    // stacks' safeJSContexts. But, this is a shutdown leak only.

    XPCPerThreadData::CleanupAllThreads();

    // shutdown the logging system
    XPC_LOG_FINISH();

    delete mRuntime;

    gSelf = nsnull;
    gOnceAliveNowDead = JS_TRUE;
}

Here is the call graph for this function:

nsXPConnect::nsXPConnect ( ) [protected]

Definition at line 69 of file nsXPConnect.cpp.

    :   mRuntime(nsnull),
        mInterfaceInfoManager(nsnull),
        mContextStack(nsnull),
        mDefaultSecurityManager(nsnull),
        mDefaultSecurityManagerFlags(0),
        mShuttingDown(JS_FALSE)
{
    // Ignore the result. If the runtime service is not ready to rumble
    // then we'll set this up later as needed.
    CreateRuntime();

    nsCOMPtr<nsIInterfaceInfoManager> iim = 
        dont_AddRef(XPTI_GetInterfaceInfoManager());
    CallQueryInterface(iim, &mInterfaceInfoManager);

    CallGetService(XPC_CONTEXT_STACK_CONTRACTID, &mContextStack);

#ifdef XPC_TOOLS_SUPPORT
  {
    char* filename = PR_GetEnv("MOZILLA_JS_PROFILER_OUTPUT");
    if(filename && *filename)
    {
        mProfilerOutputFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
        if(mProfilerOutputFile &&
           NS_SUCCEEDED(mProfilerOutputFile->InitWithNativePath(nsDependentCString(filename))))
        {
            mProfiler = do_GetService(XPCTOOLS_PROFILER_CONTRACTID);
            if(mProfiler)
            {
                if(NS_SUCCEEDED(mProfiler->Start()))
                {
#ifdef DEBUG
                    printf("***** profiling JavaScript. Output to: %s\n",
                           filename);
#endif
                }
            }
        }
    }
  }
#endif

}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 326 of file nsXPConnect.cpp.

{
    NS_ASSERTION(!mRuntime,"CreateRuntime called but mRuntime already init'd");
    nsresult rv;
    nsCOMPtr<nsIJSRuntimeService> rtsvc = 
             do_GetService(XPC_RUNTIME_CONTRACTID, &rv);
    if(NS_SUCCEEDED(rv) && rtsvc)
    {
        mRuntime = XPCJSRuntime::newXPCJSRuntime(this, rtsvc);
    }
    return nsnull != mRuntime;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Create a sandbox for evaluating code in isolation using evalInSandboxObject().

Parameters:
cxA context to use when creating the sandbox object.
principalThe principal (or NULL to use the null principal) to use when evaluating code in this sandbox.
nsIStackFrame nsIXPConnect::createStackFrameLocation ( in PRUint32  aLanguage,
in string  aFilename,
in string  aFunctionName,
in PRInt32  aLineNumber,
in nsIStackFrame  aCaller 
) [inherited]
void nsIXPConnect::debugDump ( in short  depth) [inherited]
void nsIXPConnect::debugDumpEvalInJSStackFrame ( in PRUint32  aFrameNumber,
in string  aSourceText 
) [inherited]
void nsIXPConnect::debugDumpJSStack ( in PRBool  showArgs,
in PRBool  showLocals,
in PRBool  showThisProps 
) [inherited]
void nsIXPConnect::debugDumpObject ( in nsISupports  aCOMObj,
in short  depth 
) [inherited]

Call after processing events.

Parameters:
aQueuethe queue that has processed events
JSBool nsXPConnect::EnsureRuntime ( ) [inline, private]

Definition at line 489 of file xpcprivate.h.

{return mRuntime ? JS_TRUE : CreateRuntime();}

Here is the call graph for this function:

Here is the caller graph for this function:

Evaluate script in a sandbox, completely isolated from all other running scripts.

Parameters:
sourceThe source of the script to evaluate.
cxThe context to use when setting up the evaluation of the script. The actual evaluation will happen on a new temporary context.
sandboxThe sandbox object to evaluate the script in.
Returns:
The result of the evaluation as a jsval. If the caller intends to use the return value from this call the caller is responsible for rooting the jsval before making a call to this method.
JSVal nsIXPConnect_MOZILLA_1_8_BRANCH2::evalInSandboxObject2 ( in AString  source,
in JSContextPtr  cx,
in nsIXPConnectJSObjectHolder  sandbox,
in PRBool  returnStringOnly 
) [inherited]

Evaluate script in a sandbox, completely isolated from all other running scripts.

Parameters:
sourceThe source of the script to evaluate.
cxThe context to use when setting up the evaluation of the script. The actual evaluation will happen on a new temporary context.
sandboxThe sandbox object to evaluate the script in.
returnStringOnlyThe only results to come out of the computation (including exceptions) will be coerced into strings created in the sandbox.
Returns:
The result of the evaluation as a jsval. If the caller intends to use the return value from this call the caller is responsible for rooting the jsval before making a call to this method.
PRThread * nsXPConnect::FindMainThread ( ) [static, private]

Definition at line 341 of file nsXPConnect.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIXPConnect::flagSystemFilenamePrefix ( in string  aFilenamePrefix) [inherited]

Preconfigure XPCNativeWrapper automation so that when a scripted caller whose filename starts with filenamePrefix accesses a wrapped native that is not flagged as "system", the wrapped native will be automatically wrapped with an XPCNativeWrapper.

Parameters:
aFilenamePrefixthe UTF-8 filename prefix to match, which should end with a slash (/) character
XPCContext * nsXPConnect::GetContext ( JSContext cx,
nsXPConnect xpc = nsnull 
) [static]

Definition at line 299 of file nsXPConnect.cpp.

{
    NS_PRECONDITION(cx,"bad param");

    XPCJSRuntime* rt = GetRuntime(xpc);
    if(!rt)
        return nsnull;

    if(rt->GetJSRuntime() != JS_GetRuntime(cx))
    {
        NS_WARNING("XPConnect was passed aJSContext from a foreign JSRuntime!");
        return nsnull;
    }
    return rt->GetXPCContext(cx);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 266 of file nsXPConnect.cpp.

{
    nsIThreadJSContextStack* temp;

    if(!xpc && !(xpc = GetXPConnect()))
        return NS_ERROR_FAILURE;

    *stack = temp = xpc->mContextStack;
    NS_IF_ADDREF(temp);
    return NS_OK;
}

Here is the call graph for this function:

Definition at line 458 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 461 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 402 of file nsXPConnect.cpp.

{
    return FindInfo(IIDTester, aIID, mInterfaceInfoManager, info);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 408 of file nsXPConnect.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 253 of file nsXPConnect.cpp.

{
    if(!xpc && !(xpc = GetXPConnect()))
        return NS_ERROR_FAILURE;

    *iim = xpc->mInterfaceInfoManager;
    NS_IF_ADDREF(*iim);
    return NS_OK;
}

Here is the call graph for this function:

Definition at line 291 of file nsXPConnect.cpp.

{
    XPCJSRuntime* rt = GetRuntime(xpc); 
    return rt ? rt->GetJSRuntimeService() : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRThread* nsXPConnect::GetMainThread ( ) [inline, static]

Definition at line 455 of file xpcprivate.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 281 of file nsXPConnect.cpp.

{
    if(!xpc && !(xpc = GetXPConnect()))
        return nsnull;

    return xpc->EnsureRuntime() ? xpc->mRuntime : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 201 of file nsXPConnect.cpp.

{
    nsXPConnect* xpc = nsXPConnect::GetXPConnect();
    NS_IF_ADDREF(xpc);
    return xpc;
}

Here is the call graph for this function:

This only succeeds if the JSObject is a nsIXPConnectWrappedNative.

A new wrapper is never constructed.

nsIXPConnectWrappedNative nsIXPConnect::getWrappedNativeOfNativeObject ( in JSContextPtr  aJSContext,
in JSObjectPtr  aScope,
in nsISupports  aCOMObj,
in nsIIDRef  aIID 
) [inherited]

This only succeeds if the native object is already wrapped by xpconnect.

A new wrapper is never constructed.

Definition at line 163 of file nsXPConnect.cpp.

{
    if(!gSelf)
    {
        if(gOnceAliveNowDead)
            return nsnull;
        gSelf = new nsXPConnect();
        if(!gSelf)
            return nsnull;

        if(!gSelf->mInterfaceInfoManager ||
           !gSelf->mContextStack)
        {
            // ctor failed to create an acceptable instance
            delete gSelf;
            gSelf = nsnull;
        }
        else
        {
            // Initial extra ref to keep the singleton alive
            // balanced by explicit call to ReleaseXPConnectSingleton()
            NS_ADDREF(gSelf);
        }
    }
    return gSelf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIXPConnect::initClasses ( in JSContextPtr  aJSContext,
in JSObjectPtr  aGlobalJSObj 
) [inherited]
nsIXPConnectJSObjectHolder nsIXPConnect::initClassesWithNewWrappedGlobal ( in JSContextPtr  aJSContext,
in nsISupports  aCOMObj,
in nsIIDRef  aIID,
in PRUint32  aFlags 
) [inherited]
static void nsXPConnect::InitStatics ( ) [inline, static]

Definition at line 470 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 317 of file nsXPConnect.cpp.

{
    PRBool found = PR_FALSE;
    if(info)
        info->HasAncestor(&NS_GET_IID(nsISupports), &found);
    return found;
}

Here is the caller graph for this function:

JSBool nsXPConnect::IsShuttingDown ( ) const [inline]

Definition at line 476 of file xpcprivate.h.

{return mShuttingDown;}
nsIVariant nsIXPConnect::JSToVariant ( in JSContextPtr  ctx,
in JSVal  value 
) [inherited]
void nsIXPConnect::releaseJSContext ( in JSContextPtr  aJSContext,
in PRBool  noGC 
) [inherited]

Definition at line 210 of file nsXPConnect.cpp.

{
    nsXPConnect* xpc = gSelf;
    if(xpc)
    {

#ifdef XPC_TOOLS_SUPPORT
        if(xpc->mProfiler)
        {
            xpc->mProfiler->Stop();
            xpc->mProfiler->WriteResults(xpc->mProfilerOutputFile);
        }
#endif

#ifdef GC_MARK_DEBUG
        // force a dump of the JavaScript gc heap if JS is still alive
        XPCCallContext ccx(NATIVE_CALLER);
        if(ccx.IsValid())
        {
            FILE* oldFileHandle = js_DumpGCHeap;
            js_DumpGCHeap = stdout;
            JS_GC(ccx);
            js_DumpGCHeap = oldFileHandle;
        }
#endif
#ifdef XPC_DUMP_AT_SHUTDOWN
        // NOTE: to see really interesting stuff turn on the prlog stuff.
        // See the comment at the top of xpclog.h to see how to do that.
        xpc->DebugDump(7);
#endif
        nsrefcnt cnt;
        NS_RELEASE2(xpc, cnt);
#ifdef XPC_DUMP_AT_SHUTDOWN
        if(0 != cnt)
            printf("*** dangling reference to nsXPConnect: refcnt=%d\n", cnt);
        else
            printf("+++ XPConnect had no dangling references.\n");
#endif
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIXPConnectJSObjectHolder nsIXPConnect::reparentWrappedNativeIfFound ( in JSContextPtr  aJSContext,
in JSObjectPtr  aScope,
in JSObjectPtr  aNewParent,
in nsISupports  aCOMObj 
) [inherited]
void nsIXPConnect::restoreWrappedNativePrototype ( in JSContextPtr  aJSContext,
in JSObjectPtr  aScope,
in nsIClassInfo  aClassInfo,
in nsIXPConnectJSObjectHolder  aPrototype 
) [inherited]

Restore an old prototype for wrapped natives of type aClassInfo.

This should be used only when restoring an old scope into a state close to where it was prior to being reinitialized.

The security manager to use when the current JSContext has no security manager.

Set fallback JSContext to use when xpconnect can't find an appropriate context to use to execute JavaScript.

NOTE: This method is DEPRECATED. Use nsIThreadJSContextStack::safeJSContext instead.

XPConnect builds internal objects that parallel, and are one-to-one with, the JSContexts in the JSRuntime.

It builds these objects as needed. This method tells XPConnect to resynchronize its representations with the list of JSContexts currently 'alive' in the JSRuntime. This allows it to cleanup any representations of JSContexts that are no longer valid.

JSVal nsIXPConnect::variantToJS ( in JSContextPtr  ctx,
in JSObjectPtr  scope,
in nsIVariant  value 
) [inherited]

Call before processing events.

Parameters:
aQueuethe queue that will process events

If this method throws, events should NOT be processed.

void nsIXPConnect::wrapJS ( in JSContextPtr  aJSContext,
in JSObjectPtr  aJSObj,
in nsIIDRef  aIID,
[iid_is(aIID), retval] out nsQIResult  result 
) [inherited]

wrapJS will yield a new or previously existing xpcom interface pointer to represent the JSObject passed in.

This method now correctly deals with cases where the passed in JSObject already has an associated xpcom interface for the cases: 1) The JSObject has already been wrapped as a nsIXPConnectWrappedJS. 2) The JSObject is in fact a nsIXPConnectWrappedNative and thus already has an underlying xpcom object. 3) The JSObject is of a jsclass which supports getting the nsISupports from the JSObject directly. This is used for idlc style objects (e.g. DOM objects).

It might be possible to QueryInterface the resulting interface pointer to nsIXPConnectWrappedJS.

Returns: success: NS_OK failure: NS_ERROR_XPC_BAD_CONVERT_JS NS_ERROR_FAILURE

void nsIXPConnect::wrapJSAggregatedToNative ( in nsISupports  aOuter,
in JSContextPtr  aJSContext,
in JSObjectPtr  aJSObj,
in nsIIDRef  aIID,
[iid_is(aIID), retval] out nsQIResult  result 
) [inherited]

wrapJSAggregatedToNative is just like wrapJS except it is used in cases where the JSObject is also aggregated to some native xpcom Object.

At present XBL is the only system that might want to do this.

XXX write more!

Returns: success: NS_OK failure: NS_ERROR_XPC_BAD_CONVERT_JS NS_ERROR_FAILURE

nsIXPConnectJSObjectHolder nsIXPConnect::wrapNative ( in JSContextPtr  aJSContext,
in JSObjectPtr  aScope,
in nsISupports  aCOMObj,
in nsIIDRef  aIID 
) [inherited]

wrapNative will create a new JSObject or return an existing one.

The JSObject is returned inside a refcounted nsIXPConnectJSObjectHolder. As long as this holder is held the JSObject will be protected from collection by JavaScript's garbage collector. It is a good idea to transfer the JSObject to some equally protected place before releasing the holder (i.e. use JS_SetProperty to make this object a property of some other JSObject).

This method now correctly deals with cases where the passed in xpcom object already has an associated JSObject for the cases: 1) The xpcom object has already been wrapped for use in the same scope as an nsIXPConnectWrappedNative. 2) The xpcom object is in fact a nsIXPConnectWrappedJS and thus already has an underlying JSObject. 3) The xpcom object implements nsIScriptObjectOwner; i.e. is an idlc style DOM object for which we can call GetScriptObject to get the JSObject it uses to represent itself into JavaScript.

It might be possible to QueryInterface the nsIXPConnectJSObjectHolder returned by the method into a nsIXPConnectWrappedNative or a nsIXPConnectWrappedJS.

This method will never wrap the JSObject involved in an XPCNativeWrapper before returning.

Returns: success: NS_OK failure: NS_ERROR_XPC_BAD_CONVERT_NATIVE NS_ERROR_XPC_CANT_GET_JSOBJECT_OF_DOM_OBJECT NS_ERROR_FAILURE


Member Data Documentation

Definition at line 656 of file nsIXPConnect.idl.

Definition at line 581 of file nsIXPConnect.idl.

Definition at line 582 of file nsIXPConnect.idl.

Definition at line 657 of file nsIXPConnect.idl.

Definition at line 467 of file nsIXPConnect.idl.

PRThread * nsXPConnect::gMainThread = nsnull [static, private]

Definition at line 498 of file xpcprivate.h.

Definition at line 497 of file xpcprivate.h.

nsXPConnect* nsXPConnect::gSelf [static, private]

Definition at line 496 of file xpcprivate.h.

Definition at line 466 of file nsIXPConnect.idl.

Definition at line 502 of file xpcprivate.h.

Definition at line 503 of file xpcprivate.h.

Definition at line 504 of file xpcprivate.h.

Definition at line 501 of file xpcprivate.h.

Definition at line 500 of file xpcprivate.h.

Definition at line 505 of file xpcprivate.h.

Definition at line 584 of file nsIXPConnect.idl.


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