Subj : Re: _setProperty function get id=1? To : netscape.public.mozilla.jseng From : Weiyang Zhou Date : Sun Aug 14 2005 11:49 am I found out why, seems if that property has been declared using static JSPropertySpec menuItem_props, then the id is the tinyid. If it is a dynamically added property, the JSVAL_IS_STRING(id) returns true. So can I use JSVAL_IS_INT(id) to test it? "Weiyang Zhou" wrote in message news:ddmtve$csj1@ripley.netscape.com... >I have a strange problem. With the following code: > > static JSBool menuItem_setProperty(JSContext *cx, JSObject *obj, jsval id, > jsval *vp) > { > if( JSVAL_IS_STRING(id) ) > { > ..... > } > return JS_TRUE; > } > > static JSClass menuItem_class = > { > "_Gui_MenuItem", > JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE, > JS_PropertyStub, > JS_PropertyStub, > menuItem_getProperty, > menuItem_setProperty, > JS_EnumerateStub, > JS_ResolveStub, > JS_ConvertStub, > menuItem_finalize, > JSCLASS_NO_OPTIONAL_MEMBERS > }; > > enum menuItem_tinyid > { > menuItem_text, > }; > > static JSPropertySpec menuItem_props[] = > { > {"text", menuItem_text, JSPROP_ENUMERATE}, > {0} > }; > > > JS_InitClass( > cx, > obj, > NULL, > &menuItem_class, > _Gui_MenuItem, > menuItem_class_ctor_nargs, > menuItem_props, > menuItem_methods, > NULL, > NULL > ); > > > But whenever I tried to access the "text" property from JavaScript like; > > menuItem.text = "something"; > > menuItem_setProperty() will be called, but the 3rd parameter id always has > value 1 and it fails the JSVAL_IS_STRING(id) test. So I can not set the > value. > I have traced into line 2967 of jsobj.c, the code that calls > menuItem_setProperty(); > > if (!SPROP_SET(cx, sprop, obj, obj, vp)) > return JS_FALSE; > > cx, sprop, obj, and vp seem to be fine there. > > Does anyone know why? Desperately need some help. > > Thanks a lot > Weiyang > .