Subj : Re: Missing the getProperty/setProperty mark with strings To : Sterling Bates From : Brendan Eich Date : Sat Oct 25 2003 06:56 pm Sterling Bates wrote: > 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)); Casting to a jsval is wrong (if that's what jsval(...) does). You need to set the right tag in the low order 3 bits, as STRING_TO_JSVAL does. > (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; > You can't New(Result), the GC must allocate all JSString structs. /be .