WARNING: Most of this content (with the exception of the Mozilla 1.9 XPCOM reference) is very old, and can be expected to be out of date and possibly obsolete. For better XUL documentation, please visit the XUL hub at the Mozilla Developer Center.

nsIXPConnect

IID:20df9082-5b83-416d-ba80-0422af516d57
Inherits From:nsISupports

Constants

PRUint32 INIT_JS_STANDARD_CLASSES = 1
PRUint32 FLAG_SYSTEM_GLOBAL_OBJECT = 2
Tells updateXOWs to clear the scope of all of the XOWs it finds.
PRUint32 XPC_XOW_CLEARSCOPE = 1

Properties

readonly nsIStackFrame CurrentJSStack

readonly nsAXPCNativeCallContextPtr* CurrentNativeCallContext

nsIException PendingException


Methods

[noscript] void addJSHolder ( voidPtr* holder , nsScriptObjectTracerPtr* tracer ) void clearAllWrappedNativeSecurityPolicies ( ) [noscript] nsIXPConnectJSObjectHolder createSandbox ( JSContextPtr* cx , nsIPrincipal principal ) nsIStackFrame createStackFrameLocation ( PRUint32 language , char* filename , char* functionName , PRInt32 lineNumber , nsIStackFrame caller ) void debugDump ( PRInt16 depth ) void debugDumpEvalInJSStackFrame ( PRUint32 frameNumber , char* sourceText ) void debugDumpJSStack ( PRBool showArgs , PRBool showLocals , PRBool showThisProps ) void debugDumpObject ( nsISupports COMObj , PRInt16 depth ) [noscript] JSVal evalInSandboxObject ( AString source , JSContextPtr* cx , nsIXPConnectJSObjectHolder sandbox , PRBool returnStringOnly ) void flagSystemFilenamePrefix ( char* filenamePrefix , PRBool wantNativeWrappers ) void getDefaultSecurityManager ( out nsIXPCSecurityManager manager , out PRUint16 flags ) nsIXPCFunctionThisTranslator getFunctionThisTranslator ( nsIIDRef IID ) void getSecurityManagerForJSContext ( JSContextPtr* JSContext , out nsIXPCSecurityManager manager , out PRUint16 flags ) nsIXPConnectWrappedNative getWrappedNativeOfJSObject ( JSContextPtr* JSContext , JSObjectPtr* JSObj ) nsIXPConnectWrappedNative getWrappedNativeOfNativeObject ( JSContextPtr* JSContext , JSObjectPtr* scope , nsISupports COMObj , nsIIDRef IID ) nsIXPConnectJSObjectHolder getWrappedNativePrototype ( JSContextPtr* JSContext , JSObjectPtr* scope , nsIClassInfo classInfo ) [noscript] JSVal getXOWForObject ( JSContextPtr* JSContext , JSObjectPtr* parent , JSObjectPtr* wrappedObj ) void GetXPCWrappedNativeJSClassInfo ( out JSClassConstPtr* clazz , out JSGetObjectOps ops1 , out JSGetObjectOps ops2 ) void initClasses ( JSContextPtr* JSContext , JSObjectPtr* globalJSObj ) nsIXPConnectJSObjectHolder initClassesWithNewWrappedGlobal ( JSContextPtr* JSContext , nsISupports COMObj , nsIIDRef IID , PRUint32 flags ) nsIVariant JSToVariant ( JSContextPtr* ctx , JSVal value ) [noscript][notxpcom] void noteJSContext ( JSContextPtr* JSContext , nsCCTraversalCallbackRef cb ) void releaseJSContext ( JSContextPtr* JSContext , PRBool noGC ) [noscript] void removeJSHolder ( voidPtr* holder ) void reparentScopeAwareWrappers ( JSContextPtr* JSContext , JSObjectPtr* oldScope , JSObjectPtr* newScope ) nsIXPConnectJSObjectHolder reparentWrappedNativeIfFound ( JSContextPtr* JSContext , JSObjectPtr* scope , JSObjectPtr* newParent , nsISupports COMObj ) void restoreWrappedNativePrototype ( JSContextPtr* JSContext , JSObjectPtr* scope , nsIClassInfo classInfo , nsIXPConnectJSObjectHolder prototype ) void setDefaultSecurityManager ( nsIXPCSecurityManager manager , PRUint16 flags ) nsIXPCFunctionThisTranslator setFunctionThisTranslator ( nsIIDRef IID , nsIXPCFunctionThisTranslator translator ) void setSafeJSContextForCurrentThread ( JSContextPtr* cx ) void setSecurityManagerForJSContext ( JSContextPtr* JSContext , nsIXPCSecurityManager manager , PRUint16 flags ) void syncJSContexts ( ) [noscript] void updateXOWs ( JSContextPtr* JSContext , nsIXPConnectWrappedNative object , PRUint32 way ) JSVal variantToJS ( JSContextPtr* ctx , JSObjectPtr* scope , nsIVariant value ) void wrapJS ( JSContextPtr* JSContext , JSObjectPtr* JSObj , nsIIDRef IID , out nsQIResult* result ) void wrapJSAggregatedToNative ( nsISupports outer , JSContextPtr* JSContext , JSObjectPtr* JSObj , nsIIDRef IID , out nsQIResult* result ) nsIXPConnectJSObjectHolder wrapNative ( JSContextPtr* JSContext , JSObjectPtr* scope , nsISupports COMObj , nsIIDRef IID )

void addJSHolder ( voidPtr* holder , nsScriptObjectTracerPtr* tracer )

Root JS objects held by holder.

Arguments:
holder: The object that hold the JS objects that should be rooted.
tracer

void clearAllWrappedNativeSecurityPolicies ( )


nsIXPConnectJSObjectHolder createSandbox ( JSContextPtr* cx , nsIPrincipal principal )

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

Arguments:
cx: A context to use when creating the sandbox object.
principal: The principal (or NULL to use the null principal) to use when evaluating code in this sandbox.

nsIStackFrame createStackFrameLocation ( PRUint32 language , char* filename , char* functionName , PRInt32 lineNumber , nsIStackFrame caller )

Arguments:
language
filename
functionName
lineNumber
caller

void debugDump ( PRInt16 depth )

Arguments:
depth

void debugDumpEvalInJSStackFrame ( PRUint32 frameNumber , char* sourceText )

Arguments:
frameNumber
sourceText

void debugDumpJSStack ( PRBool showArgs , PRBool showLocals , PRBool showThisProps )

Arguments:
showArgs
showLocals
showThisProps

void debugDumpObject ( nsISupports COMObj , PRInt16 depth )

Arguments:
COMObj
depth

JSVal evalInSandboxObject ( AString source , JSContextPtr* cx , nsIXPConnectJSObjectHolder sandbox , PRBool returnStringOnly )

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

Arguments:
source: The source of the script to evaluate.
cx: The context to use when setting up the evaluation of the script. The actual evaluation will happen on a new temporary context.
sandbox: The sandbox object to evaluate the script in.
returnStringOnly: The 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.

void flagSystemFilenamePrefix ( char* filenamePrefix , PRBool wantNativeWrappers )

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.

Arguments:
filenamePrefix: the UTF-8 filename prefix to match, which should end with a slash (/) character
wantNativeWrappers: whether XPConnect should produce native wrappers for scripts whose paths begin with this prefix

void getDefaultSecurityManager ( out nsIXPCSecurityManager manager , out PRUint16 flags )

Arguments:
manager
flags

nsIXPCFunctionThisTranslator getFunctionThisTranslator ( nsIIDRef IID )

Arguments:
IID

void getSecurityManagerForJSContext ( JSContextPtr* JSContext , out nsIXPCSecurityManager manager , out PRUint16 flags )

Arguments:
JSContext
manager
flags

nsIXPConnectWrappedNative getWrappedNativeOfJSObject ( JSContextPtr* JSContext , JSObjectPtr* JSObj )

This only succeeds if the JSObject is a nsIXPConnectWrappedNative. A new wrapper is *never* constructed.

Arguments:
JSContext
JSObj

nsIXPConnectWrappedNative getWrappedNativeOfNativeObject ( JSContextPtr* JSContext , JSObjectPtr* scope , nsISupports COMObj , nsIIDRef IID )

This only succeeds if the native object is already wrapped by xpconnect. A new wrapper is *never* constructed.

Arguments:
JSContext
scope
COMObj
IID

nsIXPConnectJSObjectHolder getWrappedNativePrototype ( JSContextPtr* JSContext , JSObjectPtr* scope , nsIClassInfo classInfo )

Arguments:
JSContext
scope
classInfo

JSVal getXOWForObject ( JSContextPtr* JSContext , JSObjectPtr* parent , JSObjectPtr* wrappedObj )

Wrap a jsval in a cross origin wrapper.

Arguments:
JSContext: A context to use to create objects.
parent: The parent to create the wrapper with.
wrappedObj: The object to wrap.

void GetXPCWrappedNativeJSClassInfo ( out JSClassConstPtr* clazz , out JSGetObjectOps ops1 , out JSGetObjectOps ops2 )

Get the JSClass and JSGetObjectOps pointers to use for identifying JSObjects that hold nsIXPConnectWrappedNative pointers in their private date. See IS_WRAPPER_CLASS in xpcprivate.h for details.

Arguments:
clazz
ops1
ops2

void initClasses ( JSContextPtr* JSContext , JSObjectPtr* globalJSObj )

Arguments:
JSContext
globalJSObj

nsIXPConnectJSObjectHolder initClassesWithNewWrappedGlobal ( JSContextPtr* JSContext , nsISupports COMObj , nsIIDRef IID , PRUint32 flags )

Arguments:
JSContext
COMObj
IID
flags

nsIVariant JSToVariant ( JSContextPtr* ctx , JSVal value )

Arguments:
ctx
value

[notxpcom] void noteJSContext ( JSContextPtr* JSContext , nsCCTraversalCallbackRef cb )

Note jSContext as a child to the cycle collector.

Arguments:
JSContext: The JSContext to note.
cb: The cycle collection traversal callback.

void releaseJSContext ( JSContextPtr* JSContext , PRBool noGC )

Arguments:
JSContext
noGC

void removeJSHolder ( voidPtr* holder )

Stop rooting the JS objects held by holder.

Arguments:
holder: The object that hold the rooted JS objects.

void reparentScopeAwareWrappers ( JSContextPtr* JSContext , JSObjectPtr* oldScope , JSObjectPtr* newScope )

Arguments:
JSContext
oldScope
newScope

nsIXPConnectJSObjectHolder reparentWrappedNativeIfFound ( JSContextPtr* JSContext , JSObjectPtr* scope , JSObjectPtr* newParent , nsISupports COMObj )

Arguments:
JSContext
scope
newParent
COMObj

void restoreWrappedNativePrototype ( JSContextPtr* JSContext , JSObjectPtr* scope , nsIClassInfo classInfo , nsIXPConnectJSObjectHolder prototype )

Restore an old prototype for wrapped natives of type classInfo. This should be used only when restoring an old scope into a state close to where it was prior to being reinitialized.

Arguments:
JSContext
scope
classInfo
prototype

void setDefaultSecurityManager ( nsIXPCSecurityManager manager , PRUint16 flags )

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

Arguments:
manager
flags

nsIXPCFunctionThisTranslator setFunctionThisTranslator ( nsIIDRef IID , nsIXPCFunctionThisTranslator translator )

Arguments:
IID
translator

void setSafeJSContextForCurrentThread ( JSContextPtr* cx )

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.

Arguments:
cx

void setSecurityManagerForJSContext ( JSContextPtr* JSContext , nsIXPCSecurityManager manager , PRUint16 flags )

Arguments:
JSContext
manager
flags

void syncJSContexts ( )

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.


void updateXOWs ( JSContextPtr* JSContext , nsIXPConnectWrappedNative object , PRUint32 way )

Performs an operation over all of object's XOWs such as clearing their scopes or updating their concept of the current principal.

Arguments:
JSContext: A context to use to perform JS operations.
object: Which XPCWrappedNative we should find the XOWs for.
way: What operation to perform.

JSVal variantToJS ( JSContextPtr* ctx , JSObjectPtr* scope , nsIVariant value )

Arguments:
ctx
scope
value

void wrapJS ( JSContextPtr* JSContext , JSObjectPtr* JSObj , nsIIDRef IID , out nsQIResult* result )

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

Arguments:
JSContext
JSObj
IID
result

void wrapJSAggregatedToNative ( nsISupports outer , JSContextPtr* JSContext , JSObjectPtr* JSObj , nsIIDRef IID , 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. 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

Arguments:
outer
JSContext
JSObj
IID
result

nsIXPConnectJSObjectHolder wrapNative ( JSContextPtr* JSContext , JSObjectPtr* scope , nsISupports COMObj , nsIIDRef IID )

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

Arguments:
JSContext
scope
COMObj
IID

References

This interface is the type of the following properties:

nsIXPConnectWrappedNative.XPConnect

Reference documentation is generated from Mozilla's source.