Subj : Re: [SpiderMonkey] Serializing JSObject To : ggadwa@charter.net From : Brendan Eich Date : Wed Jun 23 2004 03:58 pm ggadwa@charter.net wrote: >> This sounds awfully like uneval and eval to me. > > > Wouldn't they have the same problems you noted above? Sure, but as you note, if the objects are all script-created, no problemo. > I'll take a look, > this isn't anything I noticed because it's not in the docs. Care to > explain these a bit further? Are we talking about the eval in > javascript itself? All this happens in my C code, behind the scenes. From the JS API, eval and uneval can be called via JS_CallFunctionName, passing the global object as obj and "eval" or "uneval", but that's actually going through an extra layer in the case of eval. For eval, the API you want is JS_EvaluateScript or one of its kin. There is no JS_UnevaluateValue API, so you'd want to invoke uneval via JS_CallFunctionName. > If there's a simple function I can call on a JSObject that can covert it > back and forth from a string, I'm all for it, even though creating the > code is fun :) Try playing with eval and uneval in the js shell: js> var o = {p:1, q:true, r:'three'}; js> var s = uneval(o); js> s ({p:1, q:true, r:"three"}) js> var o2 = eval(s) js> var s2 = uneval(o2) js> s == s2 true /be .