Subj : Re: using js_HashString in a getter callback To : netscape.public.mozilla.jseng From : Brann Joly Date : Fri May 21 2004 05:37 pm Hi:) I think I understand correctly how generic callbacks can be implemented , but i have still two small questions (and want to be sure i'm not totally wrong) First, here is what I'm trying to achieve : I have various c++ objects, and I want them to be available to JS scripts. Since my objects types are created at runtime, i need to use generic wrappers, getters and setters I need to store some private data somewhere to achieve this, and to call/get the good method/property of the c++ object. For methods, i'm storing the private data this way : JSFunction* func = JS_DefineFunction(cx, i->second.first, _decl.name, jslangage::generic_wrapper, n, 0); JS_SetPrivate(cx, JS_GetFunctionObject(func), &_decl); and getting it back this way jsval a; JS_GetReservedSlot(cx,(JSObject*) JSVAL_TO_OBJECT(argv[-2]),0,&a); foo * m = (foo*) JSVAL_TO_PRIVATE(a); For properties, i'm in trouble. I would like to be able to store a private pointer somewhere, and to get it back in my generic getter method, but it seems I can't. The only thing I get is an id, and I can turn this id into the string that I passed while declaring the property: That means I declare a property this way : JS_DefineProperty(cx, obj, "foo", null, jslangage::generic_getter, jslangage::generic_setter, NULL); and get back the name of the property beeing accessed this way (thx Sterling ) JS_GetStringChars(JS_ValueToString(cx, id)) I have two problems here : first, a string is not something very speedy to test, so i'd rather do it only once and stock later the id (not the string) and the corresponding private pointer in a map. this raises the following question: Is Id something stable over time, or should I always use JS_ValueToString ? second, i may have different objects with the same property name. in this case, are both id (i mean the id parameter getting passed to the getter callback) equals, or are them different, but still returning the same string when you call JS_ValueToString(id). Brann .