Subj : Re: String property & DOM synchro To : netscape.public.mozilla.jseng From : Lorenzo Pastrana Date : Tue Jun 29 2004 01:32 pm "Brendan Eich" wrote in message news:cbpnm2$reu1@ripley.netscape.com... > Lorenzo Pastrana wrote: > > >>You really have to show your code for me to help effectively. > > Again, please show more code -- mail me if you want to keep it confidential. .... ok that's not a confidentiality problem, I'm on a 'generic' model, the line I posted is the actual code that handles the strings.. more code would mean spending your precious time on unrelated problems... Any way I'll post a little more, but you'll agree that's pure good will since you won't learn mutch more than I told you in plain english ;-p JSBool jslangage::generic_getter( JSContext *_cx, JSObject *_obj, jsval _id, jsval *_vp) { jslangage* jsl = (jslangage*)JS_GetContextPrivate(_cx); jsobj* pobj = (jsobj*) JS_GetPrivate(_cx,_obj); const sphAttributeDecl* decl = jsl->LookupAttribute(pobj, _id); if(decl == NULL) { return JS_TRUE; } sphMsgData ret(decl->atype); _Kernel.Send_Message(pobj->handle, decl->getMsg, NULL, ret); // applies conversion see below *_vp = jsl->to_jsval(ret,_obj,decl->name,_id); return JS_TRUE; } jsval jslangage::to_jsval( sphMsgData& _data, JSObject * _father, const sphChar* _prop, jsval _id) { switch ((u32) _data.get_type()) { case HOBJ: // Generic object { // Builds the corresponding object if not done yet // (using JS_DefineObject on _father with _prop) // This object has all messages mapping infos as private data, // see the generic_getter for details on mechanism // This function will be called again for pobj props access JSObject* pobj = GetObject(_data,_father,_prop); return OBJECT_TO_JSVAL(pobj); } case VCT: // Special case for 'leaf' types // This object has all id/messages mapping infos // as private data and updates the DOM on access return OBJECT_TO_JSVAL( jsvct::JSNew(jscontext,(vct&)_data,_father,_attr,_id) ); [...SNIP...] case STR: // This works for simple Get/Set but on // obj.strprop.concat(otherstr); it fails to update the DOM return STRING_TO_JSVAL( jsNewString(jscontext, (char*)((str&)_data).Export(), ((str&)_data).GetLength())); case BINT: return BOOLEAN_TO_JSVAL((bint) _data); case U32: return INT_TO_JSVAL((u32) _data); } } > You may be misusing the JS_NewString API. It might be, but anyway this is not a memory management problem really : - I want to rely on SM's JSString 'sandard' implementation in JS space - I dont own JSString code and I'm not inclined to branch - My DOM engine is accessed by messages, so the buffer I provide to JS_NewString is allready a copy. - The string implementation I'm using in the background does not want to 'share' it's buffer (usual encapsulation/ownership problem).. - Since the new JSString works on a copy of the data, it needs to be re-synched into the DOM after modifications - At this point I'm missing some notification mechanism called by JSString or whatever other solution :-/ Actually, since the DOM concept has been introduced, I believe this kind of cases will occur more often, the singularity of JSString is that it has data AND methods /w side effects, I'd be curious how other DOMs handle this but it sounds to me that I'm not in an implementation issue completely, you tell me. > Note that calling that API hands off ownership of the char [] > passed by reference. If you want the JS engine to make its own > copy of that memory, use JS_NewStringCopy[NZ]. > > /be .