Subj : Re: Retrieving property name in getter and setter functions To : JZ From : Brendan Eich Date : Fri Feb 21 2003 02:54 pm JZ wrote: >I'm using JS_DefineProperty to add some properties to an object. This works >fine: > > JS_DefineProperty(g_cx, aw_obj, title, init_val, AW_JS_Get, 0, 0); > > >Now, how in my AW_JS_Get function can I retrieve the name of the property >that has been executed in the users JavaScript? > >static JSBool AW_JS_Get(JSContext *cx, JSObject *obj, jsval id, jsval *rval) >{ > // need to get the name of the property here >} > > if (JSVAL_IS_INT(id)) then the property identifier is JSVAL_TO_INT(id) -- an integer index. Otherwise, you can asset that JSVAL_IS_STRING(id), and JSVAL_TO_STRING(id) can be passed to JS_GetStringChars and JS_GetStringLength to look at the string's characters. >Alternatively, how would I pass a unique ID number for the property if I'm >using JS_DefineProperty instead of JS_DefineProperties and a JSPropertySpec? > If you want to define a property with a tinyid, use JS_DefinePropertyWithTinyId. Hmm, that seems to obvious ;-). /be > >I'll need to do the same for my setter function. > >JZ > > > > > .