Subj : Re: Serializing JavaScript in spidermonkey To : netscape.public.mozilla.jseng From : Marcello Bastea-Forte Date : Thu Jan 01 2004 01:47 pm Martin Honnen wrote: > Is there any reason you need new Array()? I think if you do > var state = new Object(); > and > state['array'] = new Object(); > the uneval works just fine. Sweetness, thanks a bunch. :-) Works now. Now I have to figure out how to do this in C++... *runs off* .... *wanders back* So here's what I ended up with (and it works!), but I'm still slightly confused about when I let spidermonkey free memory, and when I have to: void JavaScript::serialize(JSObject *obj, ostream &os) { jsval ret; if (JS_TRUE == JS_CallFunctionName(cx, obj, "toSource", 0, NULL, &ret) && JSVAL_IS_STRING(ret)) { os << JS_GetStringBytes(JSVAL_TO_STRING(ret)); /* Do I need to free the string (ret) somehow, here? Or does the gc deal with it automatically? (my guess is the latter, but better to know if I'm doing something wrong at this point than later. */ } } Marcello .