Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Private Types | Static Private Attributes
XPCArrayHomogenizer Class Reference
Collaboration diagram for XPCArrayHomogenizer:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static JSBool GetTypeForArray (XPCCallContext &ccx, JSObject *array, jsuint length, nsXPTType *resultType, nsID *resultID)

Private Types

enum  Type {
  tNull = 0, tInt, tDbl, tBool,
  tStr, tID, tArr, tISup,
  tUnk, tTypeCount, tVar, tErr
}

Static Private Attributes

static Type StateTable [tTypeCount][tTypeCount-1]

Detailed Description

Definition at line 96 of file xpcvariant.cpp.


Member Enumeration Documentation

enum XPCArrayHomogenizer::Type [private]
Enumerator:
tNull 
tInt 
tDbl 
tBool 
tStr 
tID 
tArr 
tISup 
tUnk 
tTypeCount 
tVar 
tErr 

Definition at line 99 of file xpcvariant.cpp.

    {
        tNull  = 0 ,  // null value
        tInt       ,  // Integer
        tDbl       ,  // Double
        tBool      ,  // Boolean
        tStr       ,  // String
        tID        ,  // ID
        tArr       ,  // Array
        tISup      ,  // nsISupports (really just a plain JSObject)
        tUnk       ,  // Unknown. Used only for initial state.

        tTypeCount ,  // Just a count for table dimensioning.

        tVar       ,  // nsVariant - last ditch if no other common type found.
        tErr          // No valid state or type has this value. 
    };

Member Function Documentation

JSBool XPCArrayHomogenizer::GetTypeForArray ( XPCCallContext ccx,
JSObject array,
jsuint  length,
nsXPTType resultType,
nsID resultID 
) [static]

Definition at line 146 of file xpcvariant.cpp.

{
    Type state = tUnk;
    Type type;
       
    for(jsuint i = 0; i < length; i++)
    {
        jsval val;
        if(!JS_GetElement(ccx, array, i, &val))
            return JS_FALSE;
           
        if(JSVAL_IS_INT(val))
            type = tInt;
        else if(JSVAL_IS_DOUBLE(val))
            type = tDbl;
        else if(JSVAL_IS_BOOLEAN(val))
            type = tBool;
        else if(JSVAL_IS_VOID(val))
        {
            state = tVar;
            break;
        }
        else if(JSVAL_IS_NULL(val))
            type = tNull;
        else if(JSVAL_IS_STRING(val))
            type = tStr;
        else
        {
            NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
            JSObject* jsobj = JSVAL_TO_OBJECT(val);
            if(JS_IsArrayObject(ccx, jsobj))
                type = tArr;
            else if(xpc_JSObjectIsID(ccx, jsobj))
                type = tID;
            else
                type = tISup;
        }

        NS_ASSERTION(state != tErr, "bad state table!");
        NS_ASSERTION(type  != tErr, "bad type!");
        NS_ASSERTION(type  != tVar, "bad type!");
        NS_ASSERTION(type  != tUnk, "bad type!");

        state = StateTable[state][type];
        
        NS_ASSERTION(state != tErr, "bad state table!");
        NS_ASSERTION(state != tUnk, "bad state table!");
        
        if(state == tVar)
            break;
    }

    switch(state)
    {
        case tInt : 
            *resultType = nsXPTType((uint8)TD_INT32);
            break;
        case tDbl : 
            *resultType = nsXPTType((uint8)TD_DOUBLE);
            break;
        case tBool:
            *resultType = nsXPTType((uint8)TD_BOOL);
            break;
        case tStr : 
            *resultType = nsXPTType((uint8)(TD_PWSTRING | XPT_TDP_POINTER));
            break;
        case tID  : 
            *resultType = nsXPTType((uint8)(TD_PNSIID | XPT_TDP_POINTER));
            break;
        case tISup: 
            *resultType = nsXPTType((uint8)(TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER));
            *resultID = NS_GET_IID(nsISupports);
            break;
        case tNull: 
            // FALL THROUGH
        case tVar :
            *resultType = nsXPTType((uint8)(TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER));
            *resultID = NS_GET_IID(nsIVariant);
            break;
        case tArr : 
            // FALL THROUGH
        case tUnk : 
            // FALL THROUGH
        case tErr : 
            // FALL THROUGH
        default:
            NS_ERROR("bad state");
            return JS_FALSE;
    }
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Initial value:
 {

{tNull,tVar ,tVar ,tVar ,tStr ,tID  ,tVar ,tISup },
{tVar ,tInt ,tDbl ,tVar ,tVar ,tVar ,tVar ,tVar  },
{tVar ,tDbl ,tDbl ,tVar ,tVar ,tVar ,tVar ,tVar  },
{tVar ,tVar ,tVar ,tBool,tVar ,tVar ,tVar ,tVar  },
{tStr ,tVar ,tVar ,tVar ,tStr ,tVar ,tVar ,tVar  },
{tID  ,tVar ,tVar ,tVar ,tVar ,tID  ,tVar ,tVar  },
{tErr ,tErr ,tErr ,tErr ,tErr ,tErr ,tErr ,tErr  },
{tISup,tVar ,tVar ,tVar ,tVar ,tVar ,tVar ,tISup },
{tNull,tInt ,tDbl ,tBool,tStr ,tID  ,tVar ,tISup }}

Definition at line 118 of file xpcvariant.cpp.


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