Subj : Re: Retrieving property name in getter and setter functions To : netscape.public.mozilla.jseng From : Eric Brueggemann Date : Fri May 09 2003 12:04 pm Brendan Eich wrote: > JZ wrote: > <*snip*> > >> 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. > Actually, that's not always safe. Since a call to js_Atomize uses temporary space to inflate bytes into wide chars, JSVAL_TO_STRING(id)->chars may no longer exist when the id makes it into your getter/setter. The above assertion would be extremely helpful if it were reliable, but it isn't always the case. Any way of fixing this? Cheers, Eric .