Subj : Re: Retrieving property name in getter and setter functions To : Eric Brueggemann From : Brendan Eich Date : Fri May 09 2003 04:28 pm >>> 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 assert 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. False -- search for ATOM_NOCOPY, notice that that flag is *not* used in the js_InflateStringToBuffer case in js_Atomize. I wonder why you thought there was a problem, though. Were you seeing crashes or other symptoms of some bug, or were you just reading code? > The above assertion would be extremely helpful if it were reliable, > but it isn't always the case. Any way of fixing this? The assertion that the jsval id passed to class or per-property getters and setters satisfies either JSVAL_IS_INT(id) or JSVAL_IS_STRING(id) is reliable. If you have a bug to report, please show a testcase or give some skidmarks. /be > > > Cheers, > > Eric > .