Subj : Re: Missing the getProperty/setProperty mark with strings To : netscape.public.mozilla.jseng From : "Sterling Bates" Date : Sat Oct 25 2003 12:43 pm Here's some more info: It looks like the jsval has no JSVAL_* markers. The error is actually occuring when converting the jsval to an object (in the js_ValueToString function, line 2640-2646). If I call JS_ValueToObject from my code then I get the same error. I've tried both of these lines to create the JSString: Result := jsval(JS_NewString(FContext,PChar(str),Length(str))); Result := jsval(StringToJSString(str)); (The |str| variable is a direct reference to the Delphi object's private field FValue.) -> function StringToJSString: function StringToJSString(const str: String): PJSString; begin New(Result); Result^.length := MultiByteToWideChar(0,0,PChar(str),Length(str),Result^.chars,0); GetMem(Result^.chars,Result^.length); MultiByteToWideChar(0,0,PChar(str),Length(str),Result^.chars,Result^.length) ; end; (MultiByteToWideChar is a Windows API.) Let me know if you need anything else. Sterling "Sterling Bates" wrote in message news:bne1m2$bf11@ripley.netscape.com... > I have a Delphi object that I want to be interactive with JS and other > Delphi code simultaneously. Basically, a property set through JS should be > immediately available through Delphi & vice versa. > > I've been able to have JS set the string property just fine, but returning a > Delphi string property to javascript crashes the engine. I'm pretty sure > this can be done, so I'm just wondering where my error lies. > > 1. Creating the object. I immediately assign a property to the associated > JSObject called __addr which is the memory address of the Delphi class > instance. This works fine, the JSClass property setter & getter use this, > and then interact with the Delphi object. > > 2. Setting a property. My class setter gets the name & value of the > variable to be set, then passes those on to the Delphi object. This works > great using RTTI (reflection). > > 3. Getting a property. My class getter retrieves the name of the property > to get, then passes that to the Delphi object. I create a new JSString (on > the heap) containing the existing Delphi object's property value, and return > that as a jsval to the class getter. > > If I GC and shut down the context & runtime before hitting step 3, > everything is great. After step 3, the GC throws an access violation at > address 6102BE7A. I know it's my allocation of the JSString, but I don't > know how else to handle the get operation. I've tried looking at the > spidermonkey code, but I can only glean a trace of what's going on there. > > Thanks for any help, > > Sterling > > .