Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
xpcconvert.cpp File Reference
#include "xpcprivate.h"
#include "nsString.h"
#include "XPCNativeWrapper.h"

Go to the source code of this file.

Defines

#define ILLEGAL_RANGE(c)   (0!=((c) & 0xFF00))
#define ILLEGAL_CHAR_RANGE(c)   (0!=((c) & 0x80))
#define XPC_MK_BIT(p, o)   (1 << (((p)?1:0)+((o)?2:0)))
#define XPC_IS_REFLECTABLE(f, p, o)   ((f) & XPC_MK_BIT((p),(o)))
#define XPC_MK_FLAG(np_no, p_no, np_o, p_o)   ((uint8)((np_no) | ((p_no) << 1) | ((np_o) << 2) | ((p_o) << 3)))
#define XPC_FLAG_COUNT   (1 << 5)
#define JAM_DOUBLE_U64(cx, v, d)   JAM_DOUBLE(cx,v,d)
#define FIT_32(cx, i, d)
#define FIT_U32(cx, i, d)
#define XPC_DO_DOUBLE_WRAP   1
#define VARARGS_ASSIGN(foo, bar)   (foo) = (bar)
#define POPULATE(_t)
#define POPULATE(_mode, _t)

Functions

static JSBool GetISupportsFromJSObject (JSContext *cx, JSObject *obj, nsISupports **iface)
jsval JAM_DOUBLE (JSContext *cx, const int64 &v, jsdouble *dbl)
jsval JAM_DOUBLE (JSContext *cx, double v, jsdouble *dbl)
 FinalizeXPCOMUCString (JSContext *cx, JSString *str)
static JSBool AddXPCOMUCStringFinalizer ()
JSBool JS_DLL_CALLBACK XPC_JSArgumentFormatter (JSContext *cx, const char *format, JSBool fromJS, jsval **vpp, va_list *app)

Variables

static uint8 xpc_reflectable_flags [XPC_FLAG_COUNT]
static intN sXPCOMUCStringFinalizerIndex = -1
const char * XPC_ARG_FORMATTER_FORMAT_STRINGS [] = {"%ip", "%iv", "%is", nsnull}

Define Documentation

#define FIT_32 (   cx,
  i,
  d 
)
Value:
(INT_FITS_IN_JSVAL(i) ? \
                        INT_TO_JSVAL(i) : JAM_DOUBLE(cx,i,d))

Definition at line 204 of file xpcconvert.cpp.

#define FIT_U32 (   cx,
  i,
  d 
)
Value:

Definition at line 208 of file xpcconvert.cpp.

#define ILLEGAL_CHAR_RANGE (   c)    (0!=((c) & 0x80))

Definition at line 56 of file xpcconvert.cpp.

#define ILLEGAL_RANGE (   c)    (0!=((c) & 0xFF00))

Definition at line 53 of file xpcconvert.cpp.

#define JAM_DOUBLE_U64 (   cx,
  v,
  d 
)    JAM_DOUBLE(cx,v,d)

Definition at line 200 of file xpcconvert.cpp.

#define POPULATE (   _t)
Value:
PR_BEGIN_MACRO                                                           \
        for(i = 0; i < count; i++)                                           \
        {                                                                    \
            if(!NativeData2JS(ccx, &current, ((_t*)*s)+i, type, iid,         \
                              scope, pErr) ||                                \
               !JS_SetElement(cx, array, i, &current))                       \
                goto failure;                                                \
        }                                                                    \
    PR_END_MACRO
#define POPULATE (   _mode,
  _t 
)
Value:
PR_BEGIN_MACRO                                                           \
        cleanupMode = _mode;                                                 \
        if (capacity > ~(size_t)0 / sizeof(_t) ||                            \
            nsnull == (array = nsMemory::Alloc(capacity * sizeof(_t))))      \
        {                                                                    \
            if(pErr)                                                         \
                *pErr = NS_ERROR_OUT_OF_MEMORY;                              \
            goto failure;                                                    \
        }                                                                    \
        for(initedCount = 0; initedCount < count; initedCount++)             \
        {                                                                    \
            if(!JS_GetElement(cx, jsarray, initedCount, &current) ||         \
               !JSData2Native(ccx, ((_t*)array)+initedCount, current, type,  \
                              useAllocator, iid, pErr))                      \
                goto failure;                                                \
        }                                                                    \
    PR_END_MACRO
#define VARARGS_ASSIGN (   foo,
  bar 
)    (foo) = (bar)

Definition at line 1559 of file xpcconvert.cpp.

#define XPC_FLAG_COUNT   (1 << 5)

Definition at line 80 of file xpcconvert.cpp.

#define XPC_IS_REFLECTABLE (   f,
  p,
  o 
)    ((f) & XPC_MK_BIT((p),(o)))

Definition at line 72 of file xpcconvert.cpp.

#define XPC_MK_BIT (   p,
  o 
)    (1 << (((p)?1:0)+((o)?2:0)))

Definition at line 71 of file xpcconvert.cpp.

#define XPC_MK_FLAG (   np_no,
  p_no,
  np_o,
  p_o 
)    ((uint8)((np_no) | ((p_no) << 1) | ((np_o) << 2) | ((p_o) << 3)))

Definition at line 73 of file xpcconvert.cpp.


Function Documentation

static JSBool AddXPCOMUCStringFinalizer ( ) [static]

Definition at line 223 of file xpcconvert.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

FinalizeXPCOMUCString ( JSContext cx,
JSString str 
)

Definition at line 212 of file xpcconvert.cpp.

{
    NS_ASSERTION(sXPCOMUCStringFinalizerIndex != -1,
                 "XPCConvert: XPCOM Unicode string finalizer called uninitialized!");

    jschar* buffer = JS_GetStringChars(str);
    nsMemory::Free(buffer);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool GetISupportsFromJSObject ( JSContext cx,
JSObject obj,
nsISupports **  iface 
) [static]

Definition at line 149 of file xpcconvert.cpp.

{
    JSClass* jsclass = JS_GET_CLASS(cx, obj);
    NS_ASSERTION(jsclass, "obj has no class");
    if(jsclass &&
       (jsclass->flags & JSCLASS_HAS_PRIVATE) &&
       (jsclass->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS))
    {
        *iface = (nsISupports*) JS_GetPrivate(cx, obj);
        return JS_TRUE;
    }
    return JS_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

jsval JAM_DOUBLE ( JSContext cx,
const int64 v,
jsdouble dbl 
) [inline]

Definition at line 180 of file xpcconvert.cpp.

{
    jsdouble d;
    LL_L2D(d, v);
    dbl = JS_NewDouble(cx, d);
    if(!dbl)
        return JSVAL_ZERO;
    return DOUBLE_TO_JSVAL(dbl);
}

Here is the call graph for this function:

Here is the caller graph for this function:

jsval JAM_DOUBLE ( JSContext cx,
double  v,
jsdouble dbl 
) [inline]

Definition at line 191 of file xpcconvert.cpp.

{
    dbl = JS_NewDouble(cx, (jsdouble)v);
    if(!dbl)
        return JSVAL_ZERO;
    return DOUBLE_TO_JSVAL(dbl);
}

Here is the call 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:


Variable Documentation

Definition at line 120 of file xpcconvert.cpp.

const char* XPC_ARG_FORMATTER_FORMAT_STRINGS[] = {"%ip", "%iv", "%is", nsnull}

Definition at line 1563 of file xpcconvert.cpp.

Definition at line 83 of file xpcconvert.cpp.