Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
xpcprivate.h File Reference
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include "nscore.h"
#include "nsXPCOM.h"
#include "nsAutoPtr.h"
#include "nsISupports.h"
#include "nsIServiceManager.h"
#include "nsIClassInfo.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsISupportsPrimitives.h"
#include "nsIGenericFactory.h"
#include "nsMemory.h"
#include "nsIXPConnect.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIXPCScriptable.h"
#include "nsIXPCSecurityManager.h"
#include "nsIJSRuntimeService.h"
#include "nsWeakReference.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsAutoLock.h"
#include "xptcall.h"
#include "jsapi.h"
#include "jsdhash.h"
#include "jsprf.h"
#include "prprf.h"
#include "jsinterp.h"
#include "jscntxt.h"
#include "jsdbgapi.h"
#include "jsgc.h"
#include "xptinfo.h"
#include "xpcforwards.h"
#include "xpclog.h"
#include "xpccomponents.h"
#include "xpcexception.h"
#include "xpcjsid.h"
#include "prlong.h"
#include "prmem.h"
#include "prenv.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsXPIDLString.h"
#include "nsIThread.h"
#include "nsIJSContextStack.h"
#include "prthread.h"
#include "nsDeque.h"
#include "nsVoidArray.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsIExceptionService.h"
#include "nsVariant.h"
#include "nsIPropertyBag.h"
#include "nsIProperty.h"
#include "nsSupportsArray.h"
#include "nsTArray.h"
#include "nsIXPCScriptNotify.h"
#include "nsISecurityCheckedComponent.h"
#include "nsIEventQueueListener.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsIScriptObjectPrincipal.h"
#include "xpcinlines.h"
#include "xpcmaps.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  XPCAutoLock
class  XPCAutoUnlock
class  XPCAutoJSContext
class  nsXPConnect
class  XPCJSRuntime
class  XPCContext
class  XPCCallContext
class  XPCWrappedNativeScope
class  XPCNativeMember
class  XPCNativeInterface
class  XPCNativeSetKey
class  XPCNativeSet
class  XPCNativeScriptableFlags
class  XPCNativeScriptableShared
class  XPCNativeScriptableInfo
class  XPCNativeScriptableCreateInfo
class  XPCWrappedNativeProto
class  XPCWrappedNativeTearOff
class  XPCWrappedNativeTearOffChunk
class  XPCWrappedNative
class  nsIXPCWrappedJSClass
class  nsXPCWrappedJSClass
class  nsXPCWrappedJS
class  XPCJSObjectHolder
class  xpcProperty
class  xpcPropertyBagEnumerator
class  XPCConvert
class  XPCReadableJSStringWrapper
class  XPCStringConvert
class  XPCThrower
class  XPCJSStack
class  nsXPCException
class  nsJSID
class  nsJSIID
class  nsJSCID
struct  JSContextAndFrame
class  XPCJSContextStack
class  nsXPCJSContextStackIterator
class  XPCPerThreadData
class  nsXPCThreadJSContextStackImpl
class  BackstagePass
class  nsJSRuntimeServiceImpl
class  nsXPCComponents
class  nsXPCComponents_Interfaces
class  nsScriptError
class  AutoJSRequest
class  AutoJSSuspendRequest
class  AutoJSSuspendRequestWithNoCallContext
class  AutoJSRequestWithNoCallContext
class  AutoJSErrorAndExceptionEater
class  AutoScriptEvaluate
class  AutoResolveName
class  XPCMarkableJSVal
class  AutoMarkingPtr
class  XPCVariant

Defines

#define XPC_USE_SECURITY_CHECKED_COMPONENT
#define DEBUG_ReportShadowedMembers(set, wrapper, proto)   ((void)0)
#define DEBUG_CheckWrapperThreadSafety(w)   ((void)0)
#define XPC_CONTEXT_MAP_SIZE   16
#define XPC_JS_MAP_SIZE   64
#define XPC_JS_CLASS_MAP_SIZE   64
#define XPC_NATIVE_MAP_SIZE   64
#define XPC_NATIVE_PROTO_MAP_SIZE   16
#define XPC_DYING_NATIVE_PROTO_MAP_SIZE   16
#define XPC_DETACHED_NATIVE_PROTO_MAP_SIZE   32
#define XPC_NATIVE_INTERFACE_MAP_SIZE   64
#define XPC_NATIVE_SET_MAP_SIZE   64
#define XPC_NATIVE_JSCLASS_MAP_SIZE   32
#define XPC_THIS_TRANSLATOR_MAP_SIZE   8
#define XPC_NATIVE_WRAPPER_MAP_SIZE   16
#define XPC_STRING_GETTER_BODY(dest, src)
#define NATIVE_CALLER   XPCContext::LANG_NATIVE
#define JS_CALLER   XPCContext::LANG_JS
#define CHECK_STATE(s)   ((void)0)
#define IS_PROTO_CLASS(clazz)
#define XPC_NATIVE_IFACE_MARK_FLAG   ((PRUint16)JS_BIT(15))
#define XPC_NATIVE_SET_MARK_FLAG   ((PRUint16)JS_BIT(15))
#define XPC_WN_SJSFLAGS_MARK_FLAG   JS_BIT(31)
#define GET_IT(f_)   const {return 0 != (mFlags & nsIXPCScriptable:: f_ );}
#define GET_IT(f_)   const {return (JSBool)(mClassInfoFlags & nsIClassInfo:: f_ );}
#define XPC_PROTO_DONT_SHARE   JS_BIT(31)
#define XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK   1
#define XPC_SCOPE_TAG   ((jsword)0x1)
#define XPC_SCOPE_WORD(s)   ((jsword)(s))
#define HANDLE_POSSIBLE_NAME_CASE_ERROR(context, set, iface, name)   ((void)0)
#define NS_IXPCONNECT_WRAPPED_JS_CLASS_IID
#define NS_XPC_JSCONTEXT_STACK_ITERATOR_CID
#define BAD_TLS_INDEX   ((PRUint32) -1)
#define NS_XPC_THREAD_JSCONTEXT_STACK_CID
#define NS_JS_RUNTIME_SERVICE_CID
#define DEFINE_AUTO_MARKING_PTR_TYPE(class_, type_)
#define DEFINE_AUTO_MARKING_ARRAY_PTR_TYPE(class_, type_)
#define AUTO_MARK_JSVAL_HELPER2(tok, line)   tok##line
#define AUTO_MARK_JSVAL_HELPER(tok, line)   AUTO_MARK_JSVAL_HELPER2(tok, line)
#define AUTO_MARK_JSVAL(ccx, val)
#define XPCVARIANT_IID

Typedefs

typedef PRMonitor XPCLock

Functions

static void xpc_Wait (XPCLock *lock)
static void xpc_NotifyAll (XPCLock *lock)
JSObjectOps *JS_DLL_CALLBACK XPC_WN_GetObjectOpsNoCall (JSContext *cx, JSClass *clazz)
JSObjectOps *JS_DLL_CALLBACK XPC_WN_GetObjectOpsWithCall (JSContext *cx, JSClass *clazz)
JSBool JS_DLL_CALLBACK XPC_WN_CallMethod (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
JSBool JS_DLL_CALLBACK XPC_WN_GetterSetter (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
JSBool xpc_InitWrappedNativeJSOps ()
void xpc_MarkForValidWrapper (JSContext *cx, XPCWrappedNative *wrapper, void *arg)
JSBool JS_DLL_CALLBACK XPC_JSArgumentFormatter (JSContext *cx, const char *format, JSBool fromJS, jsval **vpp, va_list *app)
JSBool xpc_InitJSxIDClassObjects ()
void xpc_DestroyJSxIDClassObjects ()
JSObjectxpc_NewIDObject (JSContext *cx, JSObject *jsobj, const nsID &aID)
nsIDxpc_JSObjectToID (JSContext *cx, JSObject *obj)
JSBool xpc_JSObjectIsID (JSContext *cx, JSObject *obj)
JSBool xpc_DumpJSStack (JSContext *cx, JSBool showArgs, JSBool showLocals, JSBool showThisProps)
JSBool xpc_DumpEvalInJSStackFrame (JSContext *cx, JSUint32 frameno, const char *text)
JSBool xpc_DumpJSObject (JSObject *obj)
JSBool xpc_InstallJSDebuggerKeywordHandler (JSRuntime *rt)
 DEFINE_AUTO_MARKING_ARRAY_PTR_TYPE (AutoMarkingNativeInterfacePtrArrayPtr, XPCNativeInterface) extern char *xpc_CloneAllAccess()
char * xpc_CheckAccessList (const PRUnichar *wideName, const char *list[])
JSBool xpc_IsReportableErrorCode (nsresult code)
JSObjectxpc_CloneJSFunction (XPCCallContext &ccx, JSObject *funobj, JSObject *parent)
nsresult xpc_CreateSandboxObject (JSContext *cx, jsval *vp, nsISupports *prinOrSop)
nsresult xpc_EvalInSandbox (JSContext *cx, JSObject *sandbox, const nsAString &source, const char *filename, PRInt32 lineNo, PRBool returnStringOnly, jsval *rval)
JSBool xpc_ForcePropertyResolve (JSContext *cx, JSObject *obj, jsval idval)

Variables

const char * XPC_ARG_FORMATTER_FORMAT_STRINGS []
const char XPC_CONTEXT_STACK_CONTRACTID []
const char XPC_RUNTIME_CONTRACTID []
const char XPC_EXCEPTION_CONTRACTID []
const char XPC_CONSOLE_CONTRACTID []
const char XPC_SCRIPT_ERROR_CONTRACTID []
const char XPC_ID_CONTRACTID []
const char XPC_XPCONNECT_CONTRACTID []
const PRBool OBJ_IS_GLOBAL = PR_TRUE
const PRBool OBJ_IS_NOT_GLOBAL = PR_FALSE
JSExtendedClass XPC_WN_NoHelper_JSClass
JSClass XPC_WN_NoMods_Proto_JSClass
JSClass XPC_WN_ModsAllowed_Proto_JSClass
JSClass XPC_WN_Tearoff_JSClass

Define Documentation

#define AUTO_MARK_JSVAL (   ccx,
  val 
)
Value:
XPCMarkableJSVal AUTO_MARK_JSVAL_HELPER(_val_,__LINE__)(val);            \
    AutoMarkingJSVal AUTO_MARK_JSVAL_HELPER(_automarker_,__LINE__)           \
    (ccx, &AUTO_MARK_JSVAL_HELPER(_val_,__LINE__))
#define AUTO_MARK_JSVAL_HELPER2 (   tok,
  line 
)    tok##line

Definition at line 2784 of file xpcprivate.h.

#define CHECK_STATE (   s)    ((void)0)

Definition at line 938 of file xpcprivate.h.

Definition at line 195 of file xpcprivate.h.

#define DEBUG_ReportShadowedMembers (   set,
  wrapper,
  proto 
)    ((void)0)

Definition at line 186 of file xpcprivate.h.

#define DEFINE_AUTO_MARKING_ARRAY_PTR_TYPE (   class_,
  type_ 
)

Definition at line 3436 of file xpcprivate.h.

#define DEFINE_AUTO_MARKING_PTR_TYPE (   class_,
  type_ 
)
Value:
class class_ : public AutoMarkingPtr                                         \
{                                                                            \
public:                                                                      \
    class_ (XPCCallContext& ccx, type_ * ptr = nsnull)                       \
        : AutoMarkingPtr(ccx), mPtr(ptr) {}                                  \
    virtual ~ class_ () {}                                                   \
                                                                             \
    virtual void MarkBeforeJSFinalize(JSContext* cx)                         \
        {if(mPtr) {                                                          \
           mPtr->MarkBeforeJSFinalize(cx);                                   \
           mPtr->AutoMark(cx);                                               \
         }                                                                   \
         if(mNext) mNext->MarkBeforeJSFinalize(cx);}                         \
                                                                             \
    virtual void MarkAfterJSFinalize()                                       \
        {if(mPtr) mPtr->Mark();                                              \
         if(mNext) mNext->MarkAfterJSFinalize();}                            \
                                                                             \
    type_ * get()        const  {return mPtr;}                               \
    operator type_ *()   const  {return mPtr;}                               \
    type_ * operator->() const  {return mPtr;}                               \
                                                                             \
    class_ & operator =(type_ * p)                                           \
        {mPtr = p; return *this;}                                            \
                                                                             \
protected:                                                                   \
    type_ * mPtr;                                                            \
};

Definition at line 3397 of file xpcprivate.h.

#define GET_IT (   f_)    const {return 0 != (mFlags & nsIXPCScriptable:: f_ );}

Definition at line 1662 of file xpcprivate.h.

#define GET_IT (   f_)    const {return (JSBool)(mClassInfoFlags & nsIClassInfo:: f_ );}

Definition at line 1662 of file xpcprivate.h.

#define HANDLE_POSSIBLE_NAME_CASE_ERROR (   context,
  set,
  iface,
  name 
)    ((void)0)

Definition at line 1956 of file xpcprivate.h.

#define IS_PROTO_CLASS (   clazz)
Value:

Definition at line 1027 of file xpcprivate.h.

Definition at line 805 of file xpcprivate.h.

Definition at line 804 of file xpcprivate.h.

Value:
{ 0x2453eba0, 0xa9b8, 0x11d2,               \
  { 0xba, 0x64, 0x0, 0x80, 0x5f, 0x8a, 0x5d, 0xd7 } }

Definition at line 2102 of file xpcprivate.h.

Value:
{0xb5e65b52, 0x1dd1, 0x11b2, \
    { 0xae, 0x8f, 0xf0, 0x92, 0x8e, 0xd8, 0x84, 0x82 }}

Definition at line 2955 of file xpcprivate.h.

Value:
{ 0x05bae29d, 0x8aef, 0x486d, \
  { 0x84, 0xaa, 0x53, 0xf4, 0x8f, 0x14, 0x68, 0x11 } }

Definition at line 2766 of file xpcprivate.h.

Value:
{ 0xff8c4d10, 0x3194, 0x11d3, \
    { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }

Definition at line 2922 of file xpcprivate.h.

Definition at line 208 of file xpcprivate.h.

Definition at line 215 of file xpcprivate.h.

Definition at line 214 of file xpcprivate.h.

Definition at line 210 of file xpcprivate.h.

Definition at line 209 of file xpcprivate.h.

Definition at line 1252 of file xpcprivate.h.

Definition at line 216 of file xpcprivate.h.

Definition at line 218 of file xpcprivate.h.

Definition at line 212 of file xpcprivate.h.

Definition at line 213 of file xpcprivate.h.

Definition at line 217 of file xpcprivate.h.

Definition at line 1384 of file xpcprivate.h.

Definition at line 220 of file xpcprivate.h.

#define XPC_SCOPE_TAG   ((jsword)0x1)

Definition at line 1832 of file xpcprivate.h.

#define XPC_SCOPE_WORD (   s)    ((jsword)(s))

Definition at line 1833 of file xpcprivate.h.

#define XPC_STRING_GETTER_BODY (   dest,
  src 
)
Value:
NS_ENSURE_ARG_POINTER(dest); \
    char* result; \
    if(src) \
        result = (char*) nsMemory::Clone(src, \
                                sizeof(char)*(strlen(src)+1)); \
    else \
        result = nsnull; \
    *dest = result; \
    return (result || !src) ? NS_OK : NS_ERROR_OUT_OF_MEMORY

Definition at line 236 of file xpcprivate.h.

Definition at line 219 of file xpcprivate.h.

Definition at line 114 of file xpcprivate.h.

Definition at line 1431 of file xpcprivate.h.

Definition at line 1804 of file xpcprivate.h.

Value:
{0x1809fd50, 0x91e8, 0x11d5, \
      { 0x90, 0xf9, 0x0, 0x10, 0xa4, 0xe7, 0x3d, 0x9a } }

Definition at line 3520 of file xpcprivate.h.


Typedef Documentation

typedef PRMonitor XPCLock

Definition at line 255 of file xpcprivate.h.


Function Documentation

DEFINE_AUTO_MARKING_ARRAY_PTR_TYPE ( AutoMarkingNativeInterfacePtrArrayPtr  ,
XPCNativeInterface   
)
char* xpc_CheckAccessList ( const PRUnichar wideName,
const char *  list[] 
)

Definition at line 86 of file xpccomponents.cpp.

{
    nsCAutoString asciiName;
    CopyUTF16toUTF8(nsDependentString(wideName), asciiName);

    for(const char** p = list; *p; p++)
        if(!strcmp(*p, asciiName.get()))
            return xpc_CloneAllAccess();

    return nsnull;
}

Here is the call graph for this function:

JSObject* xpc_CloneJSFunction ( XPCCallContext ccx,
JSObject funobj,
JSObject parent 
)

Definition at line 54 of file xpcwrappednativeinfo.cpp.

{
    JSObject *clone = JS_CloneFunctionObject(ccx, funobj, parent);
    if(!clone)
        return nsnull;

    AUTO_MARK_JSVAL(ccx, OBJECT_TO_JSVAL(clone));

    XPCWrappedNativeScope *scope = 
        XPCWrappedNativeScope::FindInJSObjectScope(ccx, parent);

    if (!scope) {
        return nsnull;
    }

    // Make sure to break the prototype chain to the function object
    // we cloned to prevent its scope from leaking into the clones
    // scope.
    JS_SetPrototype(ccx, clone, scope->GetPrototypeJSFunction());

    // Copy the reserved slots to the clone.
    jsval ifaceVal, memberVal;
    if(!JS_GetReservedSlot(ccx, funobj, 0, &ifaceVal) ||
       !JS_GetReservedSlot(ccx, funobj, 1, &memberVal))
        return nsnull;

    if(!JS_SetReservedSlot(ccx, clone, 0, ifaceVal) ||
       !JS_SetReservedSlot(ccx, clone, 1, memberVal))
        return nsnull;

    return clone;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult xpc_CreateSandboxObject ( JSContext cx,
jsval vp,
nsISupports *  prinOrSop 
)

Definition at line 2288 of file xpccomponents.cpp.

{
    // Create the sandbox global object
    nsresult rv;
    nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
    if(NS_FAILED(rv))
        return NS_ERROR_XPC_UNEXPECTED;

    XPCAutoJSContext tempcx(JS_NewContext(JS_GetRuntime(cx), 1024), PR_FALSE);
    if (!tempcx)
        return NS_ERROR_OUT_OF_MEMORY;

    AutoJSRequestWithNoCallContext req(tempcx);
    JSObject *sandbox = JS_NewObject(tempcx, &SandboxClass, nsnull, nsnull);
    if (!sandbox)
        return NS_ERROR_XPC_UNEXPECTED;

    JS_SetGlobalObject(tempcx, sandbox);

    nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(prinOrSop));

    if (!sop) {
        nsCOMPtr<nsIPrincipal> principal(do_QueryInterface(prinOrSop));

        if (!principal) {
            // Create a mostly unique URI that has access to
            // nothing other itself.
            static PRBool doneSeed = PR_FALSE;

            if (!doneSeed) {
                srand((int)(PR_Now() & 0xffffffff));

                doneSeed = PR_TRUE;
            }

            char buf[128];
            sprintf(buf, "about:noaccess-%ul", rand());

            nsCOMPtr<nsIURI> uri;
            rv = NS_NewURI(getter_AddRefs(uri), buf);
            NS_ENSURE_SUCCESS(rv, rv);

            nsCOMPtr<nsIScriptSecurityManager> secman =
                do_GetService(kScriptSecurityManagerContractID);
            NS_ENSURE_TRUE(secman, NS_ERROR_UNEXPECTED);

            rv = secman->GetCodebasePrincipal(uri, getter_AddRefs(principal));

            if (!principal || NS_FAILED(rv)) {
                if (NS_SUCCEEDED(rv))
                    rv = NS_ERROR_FAILURE;
                
                return rv;
            }
        }

        sop = new PrincipalHolder(principal);
        if (!sop)
            return NS_ERROR_OUT_OF_MEMORY;
    }

    // Pass on ownership of sop to |sandbox|.

    {
        nsIScriptObjectPrincipal *tmp = sop;

        if (!JS_SetPrivate(cx, sandbox, tmp)) {
            return NS_ERROR_XPC_UNEXPECTED;
        }

        NS_ADDREF(tmp);
    }

    rv = xpc->InitClasses(cx, sandbox);
    if (NS_SUCCEEDED(rv) &&
        !JS_DefineFunctions(cx, sandbox, SandboxFunctions)) {
        rv = NS_ERROR_FAILURE;
    }
    if (NS_FAILED(rv))
        return NS_ERROR_XPC_UNEXPECTED;

    if (vp)
        *vp = OBJECT_TO_JSVAL(sandbox);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool xpc_DumpEvalInJSStackFrame ( JSContext cx,
JSUint32  frameno,
const char *  text 
)
JSBool xpc_DumpJSStack ( JSContext cx,
JSBool  showArgs,
JSBool  showLocals,
JSBool  showThisProps 
)
nsresult xpc_EvalInSandbox ( JSContext cx,
JSObject sandbox,
const nsAString &  source,
const char *  filename,
PRInt32  lineNo,
PRBool  returnStringOnly,
jsval rval 
)

Definition at line 2656 of file xpccomponents.cpp.

{
    if (JS_GetClass(cx, sandbox) != &SandboxClass)
        return NS_ERROR_INVALID_ARG;

    nsIScriptObjectPrincipal *sop =
        (nsIScriptObjectPrincipal*)JS_GetPrivate(cx, sandbox);
    NS_ASSERTION(sop, "Invalid sandbox passed");
    nsCOMPtr<nsIPrincipal> prin = sop->GetPrincipal();

    JSPrincipals *jsPrincipals;

    if (!prin ||
        NS_FAILED(prin->GetJSPrincipals(cx, &jsPrincipals)) ||
        !jsPrincipals) {
        return NS_ERROR_FAILURE;
    }

    nsRefPtr<ContextHolder> sandcx = new ContextHolder(cx, sandbox);
    if(!sandcx || !sandcx->GetJSContext()) {
        JS_ReportError(cx, "Can't prepare context for evalInSandbox");
        JSPRINCIPALS_DROP(cx, jsPrincipals);
        return NS_ERROR_OUT_OF_MEMORY;
    }

    XPCPerThreadData *data = XPCPerThreadData::GetData();
    XPCJSContextStack *stack = nsnull;
    if (data && (stack = data->GetJSContextStack())) {
        if (NS_FAILED(stack->Push(sandcx->GetJSContext()))) {
            JS_ReportError(cx,
                    "Unable to initialize XPConnect with the sandbox context");
            JSPRINCIPALS_DROP(cx, jsPrincipals);
            return NS_ERROR_FAILURE;
        }
    }


    // Push a fake frame onto sandcx so that we can properly propagate uncaught
    // exceptions.
    JSStackFrame frame;
    memset(&frame, 0, sizeof frame);

    sandcx->GetJSContext()->fp = &frame;

    if (!filename) {
        // Default the filename to the codebase.
        filename = jsPrincipals->codebase;
        lineNo = 1;
    }

    nsresult rv = NS_OK;

    JSString *str = nsnull;
    if (!JS_EvaluateUCScriptForPrincipals(sandcx->GetJSContext(), sandbox,
                                          jsPrincipals,
                                          NS_REINTERPRET_CAST(const jschar *,
                                              PromiseFlatString(source).get()),
                                          source.Length(), filename, lineNo,
                                          rval) ||
        (returnStringOnly &&
         !JSVAL_IS_VOID(*rval) &&
         !(str = JS_ValueToString(sandcx->GetJSContext(), *rval)))) {
        jsval exn;
        if (JS_GetPendingException(sandcx->GetJSContext(), &exn)) {
            // Stash the exception in |cx| so we can execute code on
            // sandcx without a pending exception.
            JS_SetPendingException(cx, exn);
            JS_ClearPendingException(sandcx->GetJSContext());
            if (returnStringOnly) {
                // The caller asked for strings only, convert the
                // exception into a string.
                str = JS_ValueToString(sandcx->GetJSContext(), exn);

                if (str) {
                    // We converted the exception to a string. Use that
                    // as the value exception.
                    JS_SetPendingException(cx, STRING_TO_JSVAL(str));
                } else {
                    JS_ClearPendingException(cx);
                    rv = NS_ERROR_FAILURE;
                }
            }

            // Clear str so we don't confuse callers.
            str = nsnull;
        } else {
            rv = NS_ERROR_OUT_OF_MEMORY;
        }
    }

    if (str) {
        *rval = STRING_TO_JSVAL(str);
    }

    if (stack) {
        stack->Pop(nsnull);
    }

    NS_ASSERTION(sandcx->GetJSContext()->fp == &frame, "Dangling frame");
    sandcx->GetJSContext()->fp = NULL;

    sandcx->DidEval();

    JSPRINCIPALS_DROP(cx, jsPrincipals);

    return rv;
}

Here is the call graph for this function:

JSBool xpc_ForcePropertyResolve ( JSContext cx,
JSObject obj,
jsval  idval 
) [inline]

Definition at line 697 of file xpcinlines.h.

{
    JSProperty* prop;
    JSObject* obj2;
    jsid id;    

    if(!JS_ValueToId(cx, idval, &id) ||
       !OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop))
        return JS_FALSE;
    if(prop)
        OBJ_DROP_PROPERTY(cx, obj2, prop);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file xpcwrappedjsclass.cpp.

{
    if(NS_SUCCEEDED(code))
        return JS_FALSE;

    switch(code)
    {
        // Error codes that we don't want to report as errors...
        // These generally indicate bad interface design AFAIC. 
        case NS_ERROR_FACTORY_REGISTER_AGAIN:
        case NS_BASE_STREAM_WOULD_BLOCK:
            return JS_FALSE;
    }
    return JS_TRUE;
}

Here is the caller graph for this function:

JSBool JS_DLL_CALLBACK XPC_JSArgumentFormatter ( JSContext cx,
const char *  format,
JSBool  fromJS,
jsval **  vpp,
va_list *  app 
)

Definition at line 1566 of file xpcconvert.cpp.

{
    XPCCallContext ccx(NATIVE_CALLER, cx);
    if(!ccx.IsValid())
        return JS_FALSE;

    jsval *vp;
    va_list ap;

    vp = *vpp;
    VARARGS_ASSIGN(ap, *app);

    nsXPTType type;
    const nsIID* iid;
    void* p;

    NS_ASSERTION(format[0] == '%' && format[1] == 'i', "bad format!");
    char which = format[2];

    if(fromJS)
    {
        switch(which)
        {
            case 'p':
                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
                iid = &NS_GET_IID(nsISupports);
                break;
            case 'v':
                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
                iid = &NS_GET_IID(nsIVariant);
                break;
            case 's':
                type = nsXPTType((uint8)(TD_DOMSTRING | XPT_TDP_POINTER));                
                iid = nsnull;
                p = va_arg(ap, void *);
                break;
            default:
                NS_ERROR("bad format!");
                return JS_FALSE;
        }

        if(!XPCConvert::JSData2Native(ccx, &p, vp[0], type, JS_FALSE,
                                      iid, nsnull))
            return JS_FALSE;
        
        if(which != 's')
            *va_arg(ap, void **) = p;
    }
    else
    {
        switch(which)
        {
            case 'p':
                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
                iid  = va_arg(ap, const nsIID*);
                break;
            case 'v':
                type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));                
                iid = &NS_GET_IID(nsIVariant);
                break;
            case 's':
                type = nsXPTType((uint8)(TD_DOMSTRING | XPT_TDP_POINTER));                
                iid = nsnull;
                break;
            default:
                NS_ERROR("bad format!");
                return JS_FALSE;
        }

        // NOTE: MUST be retrieved *after* the iid in the 'p' case above.
        p = va_arg(ap, void *);

        if(!XPCConvert::NativeData2JS(ccx, &vp[0], &p, type, iid,
                                      JS_GetGlobalObject(cx), nsnull))
            return JS_FALSE;
    }
    *vpp = vp + 1;
    VARARGS_ASSIGN(*app, ap);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool xpc_JSObjectIsID ( JSContext cx,
JSObject obj 
)

Definition at line 1024 of file xpcjsid.cpp.

{
    NS_ASSERTION(cx && obj, "bad param");
    // NOTE: this call does NOT addref
    XPCWrappedNative* wrapper =
        XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj);
    return wrapper &&
           (wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSID))  ||
            wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSIID)) ||
            wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSCID)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsID* xpc_JSObjectToID ( JSContext cx,
JSObject obj 
)

Definition at line 1004 of file xpcjsid.cpp.

{
    nsID* id = nsnull;
    if(!cx || !obj)
        return nsnull;

    // NOTE: this call does NOT addref
    XPCWrappedNative* wrapper =
        XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj);
    if(wrapper &&
       (wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSID))  ||
        wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSIID)) ||
        wrapper->HasInterfaceNoQI(NS_GET_IID(nsIJSCID))))
    {
        ((nsIJSID*)wrapper->GetIdentityObject())->GetId(&id);
    }
    return id;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xpc_MarkForValidWrapper ( JSContext cx,
XPCWrappedNative wrapper,
void arg 
)

Definition at line 678 of file xpcwrappednativejsops.cpp.

{
    // NOTE: It might be nice to also do the wrapper->Mark() call here too.
    // That call marks the wrapper's and wrapper's proto's interface sets.
    // We currently do that in the GC callback code. The reason we don't do that
    // here is because the bits used in that marking do unpleasant things to the
    // member counts in the interface and interface set objects. Those counts
    // are used in the DealWithDyingGCThings calls that are part of this JS GC
    // marking phase. By doing these calls later during our GC callback we 
    // avoid that problem. Arguably this could be changed. But it ain't broke.

    // However, we do need to call the wrapper's MarkBeforeJSFinalize so that
    // it can be sure that its (potentially shared) JSClass gets marked. The
    // danger is that a live wrapper might not be in a wrapper map and thus
    // won't be fully marked in the GC callback. This can happen if there is
    // a security exception during wrapper creation or if during wrapper
    // creation it is determined that the wrapper is not needed. In those cases
    // the wrapper can never actually be used from JS code - so resources like
    // the interface set will never be accessed. But the JS engine will still
    // need to use the JSClass. So, some marking is required for protection.

    wrapper->MarkBeforeJSFinalize(cx);
     
    if(wrapper->HasProto())
    {
        JSObject* obj = wrapper->GetProto()->GetJSProtoObject();
        NS_ASSERTION(obj, "bad proto");
        JS_MarkGCThing(cx, obj, "XPCWrappedNativeProto::mJSProtoObject", arg);
    }
    MarkScopeJSObjects(cx, wrapper->GetScope(), arg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSObject* xpc_NewIDObject ( JSContext cx,
JSObject jsobj,
const nsID aID 
)

Definition at line 973 of file xpcjsid.cpp.

{
    JSObject *obj = nsnull;

    char* idString = aID.ToString();
    if(idString)
    {
        nsCOMPtr<nsIJSID> iid =
            dont_AddRef(NS_STATIC_CAST(nsIJSID*, nsJSID::NewID(idString)));
        PR_Free(idString);
        if(iid)
        {
            nsXPConnect* xpc = nsXPConnect::GetXPConnect();
            if(xpc)
            {
                nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
                nsresult rv = xpc->WrapNative(cx, jsobj,
                                              NS_STATIC_CAST(nsISupports*,iid),
                                              NS_GET_IID(nsIJSID),
                                              getter_AddRefs(holder));
                if(NS_SUCCEEDED(rv) && holder)
                {
                    holder->GetJSObject(&obj);
                }
            }
        }
    }
    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void xpc_NotifyAll ( XPCLock lock) [inline, static]

Definition at line 267 of file xpcprivate.h.

    {
        NS_ASSERTION(lock, "xpc_NotifyAll called with null lock!");
#ifdef DEBUG
        PRStatus result = 
#endif    
        PR_NotifyAll(lock);
        NS_ASSERTION(PR_SUCCESS == result, "bad result from PR_NotifyAll!");
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static void xpc_Wait ( XPCLock lock) [inline, static]

Definition at line 257 of file xpcprivate.h.

    {
        NS_ASSERTION(lock, "xpc_Wait called with null lock!");
#ifdef DEBUG
        PRStatus result = 
#endif
        PR_Wait(lock, PR_INTERVAL_NO_TIMEOUT);
        NS_ASSERTION(PR_SUCCESS == result, "bad result from PR_Wait!");
    }

Here is the call graph for this function:

JSBool JS_DLL_CALLBACK XPC_WN_CallMethod ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval vp 
)

Definition at line 1440 of file xpcwrappednativejsops.cpp.

{
    NS_ASSERTION(JS_TypeOfValue(cx, argv[-2]) == JSTYPE_FUNCTION, "bad function");
    JSObject* funobj = JSVAL_TO_OBJECT(argv[-2]);
    XPCCallContext ccx(JS_CALLER, cx, obj, funobj, 0, argc, argv, vp);
    XPCWrappedNative* wrapper = ccx.GetWrapper();
    THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);

    XPCNativeInterface* iface;
    XPCNativeMember*    member;

    if(!XPCNativeMember::GetCallInfo(ccx, funobj, &iface, &member))
        return Throw(NS_ERROR_XPC_CANT_GET_METHOD_INFO, cx);
    ccx.SetCallInfo(iface, member, JS_FALSE);
    return XPCWrappedNative::CallMethod(ccx);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1260 of file xpcwrappednativejsops.cpp.

{
    return &XPC_WN_NoCall_JSOps;
}

Here is the caller graph for this function:

Definition at line 1266 of file xpcwrappednativejsops.cpp.

{
    return &XPC_WN_WithCall_JSOps;
}

Here is the caller graph for this function:

JSBool JS_DLL_CALLBACK XPC_WN_GetterSetter ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval vp 
)

Definition at line 1459 of file xpcwrappednativejsops.cpp.

{
    NS_ASSERTION(JS_TypeOfValue(cx, argv[-2]) == JSTYPE_FUNCTION, "bad function");
    JSObject* funobj = JSVAL_TO_OBJECT(argv[-2]);

    XPCCallContext ccx(JS_CALLER, cx, obj, funobj);
    XPCWrappedNative* wrapper = ccx.GetWrapper();
    THROW_AND_RETURN_IF_BAD_WRAPPER(cx, wrapper);

    XPCNativeInterface* iface;
    XPCNativeMember*    member;

    if(!XPCNativeMember::GetCallInfo(ccx, funobj, &iface, &member))
        return Throw(NS_ERROR_XPC_CANT_GET_METHOD_INFO, cx);

    ccx.SetArgsAndResultPtr(argc, argv, vp);
    if(argc)
    {
        ccx.SetCallInfo(iface, member, JS_TRUE);
        JSBool retval = XPCWrappedNative::SetAttribute(ccx);
        if(retval && vp)
            *vp = argv[0];
        return retval;
    }
    // else...

    ccx.SetCallInfo(iface, member, JS_FALSE);
    return XPCWrappedNative::GetAttribute(ccx);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 422 of file xpcprivate.h.

Definition at line 423 of file xpcprivate.h.

Definition at line 1563 of file xpcconvert.cpp.

Definition at line 62 of file nsXPConnect.cpp.

Definition at line 59 of file nsXPConnect.cpp.

Definition at line 61 of file nsXPConnect.cpp.

Definition at line 64 of file nsXPConnect.cpp.

Definition at line 60 of file nsXPConnect.cpp.

Definition at line 63 of file nsXPConnect.cpp.

Definition at line 1589 of file xpcwrappednativejsops.cpp.

Definition at line 869 of file xpcwrappednativejsops.cpp.

Definition at line 1670 of file xpcwrappednativejsops.cpp.

Definition at line 1753 of file xpcwrappednativejsops.cpp.

Definition at line 65 of file nsXPConnect.cpp.