Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
XPCDispConvert.cpp File Reference

Contains the implementation of the XPCDispConvert class. More...

#include "xpcprivate.h"

Go to the source code of this file.

Defines

#define XPC_ASSIGN(src, dest, data)   *dest.p##data = src.data
#define VALUE(val)   (isPtr ? *src.p##val : src.val)

Functions

JSBool xpc_CopyVariantByRef (VARIANT &src, VARIANT &dest)
 Copies a variant to a by ref variant NOTE: This does not perform any reference counting.
jsval StringToJSVal (JSContext *cx, const PRUnichar *str, PRUint32 len)
 Converts a string to a jsval.

Detailed Description

Contains the implementation of the XPCDispConvert class.

Definition in file XPCDispConvert.cpp.


Define Documentation

#define VALUE (   val)    (isPtr ? *src.p##val : src.val)

Definition at line 445 of file XPCDispConvert.cpp.

#define XPC_ASSIGN (   src,
  dest,
  data 
)    *dest.p##data = src.data

Definition at line 140 of file XPCDispConvert.cpp.


Function Documentation

jsval StringToJSVal ( JSContext cx,
const PRUnichar str,
PRUint32  len 
) [inline]

Converts a string to a jsval.

Parameters:
cxthe JSContext
strthe unicode string to be converted
lenthe length of the string being converted
Returns:
the jsval representing the string

Definition at line 433 of file XPCDispConvert.cpp.

{
    JSString * s = JS_NewUCStringCopyN(cx,
                                       NS_REINTERPRET_CAST(const jschar *, str),
                                       len);
    if(s)
        return STRING_TO_JSVAL(s);
    else
        return JSVAL_NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool xpc_CopyVariantByRef ( VARIANT &  src,
VARIANT &  dest 
) [inline]

Copies a variant to a by ref variant NOTE: This does not perform any reference counting.

It simply does a copy of the values, it's up to the caller to manage any ownership issues

Parameters:
srcthe variant to be copied
destthe destination for the copy
Returns:
JS_TRUE if the copy was performed JS_FALSE if it failed

Definition at line 151 of file XPCDispConvert.cpp.

{
    VARIANT temp;
    VARTYPE vt = dest.vt & ~(VT_BYREF);
    if(vt != src.vt)
    {
        // TODO: This fails more than I had hoped, we may want to
        // add some logic to handle more conversions
        if(FAILED(VariantChangeType(&temp, &src, VARIANT_ALPHABOOL, vt)))
        {
            return JS_FALSE;
        }
    }
    else
        temp = src;
    switch (vt)
    {
        case VT_I2:
        {
            XPC_ASSIGN(temp, dest, iVal);
        }
        break;
           case VT_I4:
        {
            XPC_ASSIGN(temp, dest, lVal);
        }
        break;
           case VT_R4:
        {
            XPC_ASSIGN(temp, dest, fltVal);
        }
        break;
           case VT_R8:
        {
            XPC_ASSIGN(temp, dest, dblVal);
        }
        break;
           case VT_CY:
        {
            XPC_ASSIGN(temp, dest, cyVal);
        }
        break;
           case VT_DATE:
        {
            XPC_ASSIGN(temp, dest, date);
        }
        break;
           case VT_BSTR:
        {
            XPC_ASSIGN(temp, dest, bstrVal);
        }
        break;
           case VT_DISPATCH:
        {
            XPC_ASSIGN(temp, dest, pdispVal);
        }
        break;
           case VT_ERROR:
        {
            XPC_ASSIGN(temp, dest, scode);
        }
        break;
           case VT_BOOL:
        {
            XPC_ASSIGN(temp, dest, boolVal);
        }
        break;
           case VT_VARIANT:
        {
            // Not Supported right now
            return JS_FALSE;
        }
        break;
           case VT_I1:
        {
            XPC_ASSIGN(temp, dest, cVal);
        }
        break;
           case VT_UI1:
        {
            XPC_ASSIGN(temp, dest, bVal);
        }
        break;
           case VT_UI2:
        {
            XPC_ASSIGN(temp, dest, iVal);
        }
        break;
           case VT_UI4:
        {
            XPC_ASSIGN(temp, dest, uiVal);
        }
        break;
           case VT_INT:
        {
            XPC_ASSIGN(temp, dest, intVal);
        }
        break;
           case VT_UINT:
        {
            XPC_ASSIGN(temp, dest, uintVal);
        }
        break;
        default:
        {
            return JS_FALSE;
        }
    }
    return JS_TRUE;
}

Here is the caller graph for this function: