Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Types | Private Member Functions | Private Attributes
XPCDispJSPropertyInfo Class Reference

Helper class that describes a JS function or property. More...

#include <XPCDispPrivate.h>

Collaboration diagram for XPCDispJSPropertyInfo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XPCDispJSPropertyInfo (JSContext *cx, PRUint32 memid, JSObject *obj, jsval val)
 Inspects a JS Function or property.
PRBool Valid () const
 Returns true if the property information was initialized property.
PRUint32 GetParamCount () const
 Returns the number of parameters If this is a setter, the parameter count is always one.
PRUint32 GetMemID () const
 Returns the generated member ID/dispid This is based on the order of the function/property within the object.
INVOKEKIND GetInvokeKind () const
 Returns the COM's INVOKEKIND for the property/method.
void GetReturnType (XPCCallContext &ccx, ELEMDESC &elemDesc)
 Assigns the return type in elemDesc.
ELEMDESC * GetParamInfo ()
 Returns an element description for the property.
PRBool IsProperty () const
 Tests whether this is a property.
PRBool IsReadOnly () const
 Test whether this is read-only.
PRBool IsSetter () const
 Tests whether this is a setter.
void SetSetter ()
 Denotes this property has a setter (is not read-only)
nsAString constGetName () const
 returns the name of the property/method

Private Types

enum  property_type {
  INVALID, PROPERTY, READONLY_PROPERTY, FUNCTION,
  SETTER_MODE = 0x20
}

Private Member Functions

property_type PropertyType () const
 Accessor for the property type mProperty.

Private Attributes

PRUint32 mPropertyType
PRUint32 mParamCount
PRUint32 mMemID
jsval mProperty
nsString mName

Detailed Description

Helper class that describes a JS function or property.

Definition at line 505 of file XPCDispPrivate.h.


Member Enumeration Documentation

Enumerator:
INVALID 
PROPERTY 
READONLY_PROPERTY 
FUNCTION 
SETTER_MODE 

Definition at line 575 of file XPCDispPrivate.h.


Constructor & Destructor Documentation

Inspects a JS Function or property.

Parameters:
cxA JS Context
memidthe ID of the property or function
objthe JS object the property or function resides on
valID val of the property or function

Definition at line 116 of file XPCDispTypeInfo.cpp.

                                                                       : 
    mPropertyType(INVALID), mMemID(memid)
{
    PRUint32 len;
    jschar * chars = xpc_JSString2String(cx, val, &len);
    if(!chars)
        return;

    mName = nsString(NS_REINTERPRET_CAST(const PRUnichar *, chars), len);
    JSBool found;
    uintN attr;
    // Get the property's attributes, and make sure it's found and enumerable 
    if(!JS_GetUCPropertyAttributes(cx, obj, chars, len, &attr, &found) || 
        !found || (attr & JSPROP_ENUMERATE) == 0)
        return;

    // Retrieve the property 
    if(!chars || !JS_GetUCProperty(cx, obj, chars, len, &mProperty) ||
        JSVAL_IS_NULL(mProperty))
        return;

    // If this is a function
    if(JSVAL_IS_OBJECT(mProperty) && 
        JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(mProperty)))
    {
        mPropertyType = FUNCTION;
        JSObject * funcObj = JSVAL_TO_OBJECT(mProperty);
        JSIdArray * funcObjArray = JS_Enumerate(cx, funcObj);
        if(funcObjArray)
        {
            mParamCount = funcObjArray->length;
        }
    }
    else // It's a property
    {
        mParamCount = 0;
        if((attr & JSPROP_READONLY) != 0)
        {
            mPropertyType = READONLY_PROPERTY;
        }
        else
        {
            mPropertyType = PROPERTY;
        }
    }
}

Here is the call graph for this function:


Member Function Documentation

INVOKEKIND XPCDispJSPropertyInfo::GetInvokeKind ( ) const [inline]

Returns the COM's INVOKEKIND for the property/method.

Returns:
the COM's INVOKEKIND for the property/method

Definition at line 518 of file XPCDispInlines.h.

{
    return IsSetter() ? INVOKE_PROPERTYPUT : 
        (IsProperty() ? INVOKE_PROPERTYGET : INVOKE_FUNC); 
}

Here is the caller graph for this function:

Returns the generated member ID/dispid This is based on the order of the function/property within the object.

Returns:
the memid of the property

Definition at line 512 of file XPCDispInlines.h.

{
    return mMemID;
}

Here is the caller graph for this function:

const nsAString & XPCDispJSPropertyInfo::GetName ( ) const [inline]

returns the name of the property/method

Returns:
the name of the property/method

Definition at line 548 of file XPCDispInlines.h.

{
    return mName; 
}

Here is the caller graph for this function:

Returns the number of parameters If this is a setter, the parameter count is always one.

Returns:
the number of parameters

Definition at line 506 of file XPCDispInlines.h.

{
    return IsSetter() ? 1 : mParamCount;
}

Here is the caller graph for this function:

Returns an element description for the property.

Returns:
the element descriptoin object, ownership is assumed by the caller.

Definition at line 95 of file XPCDispTypeInfo.cpp.

{
    PRUint32 paramCount = GetParamCount();
    ELEMDESC* elemDesc;
    if(paramCount != 0)
    {
        elemDesc = new ELEMDESC[paramCount];
        if(elemDesc)
        {
            for(PRUint32 index = 0; index < paramCount; ++index)
            {
                FillOutElemDesc(VT_VARIANT, PARAMFLAG_FIN, elemDesc[index]);
            }
        }
    }
    else
        elemDesc = 0;
    // Caller becomes owner
    return elemDesc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void XPCDispJSPropertyInfo::GetReturnType ( XPCCallContext ccx,
ELEMDESC &  elemDesc 
)

Assigns the return type in elemDesc.

Parameters:
ccxan xpconnect call context
elemDescthe element description to set the return type

Definition at line 77 of file XPCDispTypeInfo.cpp.

{
    VARTYPE vt;
    if(IsSetter())      // if this is a setter
    {
        vt = VT_EMPTY;
    }
    else if(IsProperty())   // If this is a property
    {
        vt = XPCDispConvert::JSTypeToCOMType(ccx, mProperty);
    }
    else                    // if this is a function
    {
        vt = VT_VARIANT;
    }
    FillOutElemDesc(vt, PARAMFLAG_FRETVAL, elemDesc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tests whether this is a property.

Returns:
true if this is a property

Definition at line 525 of file XPCDispInlines.h.

Here is the caller graph for this function:

Test whether this is read-only.

Returns:
true if this is read-only

Definition at line 531 of file XPCDispInlines.h.

Tests whether this is a setter.

Returns:
true if this is a setter

Definition at line 537 of file XPCDispInlines.h.

{
    return (mPropertyType & SETTER_MODE) != 0;
}

Here is the caller graph for this function:

Accessor for the property type mProperty.

Returns:
property_type for the property

Definition at line 554 of file XPCDispInlines.h.

Denotes this property has a setter (is not read-only)

Definition at line 542 of file XPCDispInlines.h.

Returns true if the property information was initialized property.

Returns:
true if the property information was initialized property

Definition at line 500 of file XPCDispInlines.h.

{
    return mPropertyType != INVALID;
}

Member Data Documentation

Definition at line 586 of file XPCDispPrivate.h.

Definition at line 588 of file XPCDispPrivate.h.

Definition at line 585 of file XPCDispPrivate.h.

Definition at line 587 of file XPCDispPrivate.h.

Definition at line 584 of file XPCDispPrivate.h.


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