Subj : Re: [SpiderMonkey] Saving Global State To : "ggadwa@charter.net" From : Brendan Eich Date : Tue Feb 10 2004 11:14 am ggadwa@charter.net wrote: > OK, I have one last thing to work out with the engine, then I'm done :) > > This might not be possible, or might just be very complex. Complex is > fine. I have a work around for impossible, but it would make anybody > creating a script have to handle tons of extraneous scripting that I > should be handling behind the scenes. This has come up before, but I > don't think I've seen a good answer yet. > > I need to "save" the state of a script ... BUT .. lucky me, my scripts > run by events and all the params passed to the events are generated by > me, and therefore the execution state + function params don't have to > be saved (saving will always happen when no script has an active > call). The SINGLE thing that has to be saved is the global object, > which I can get/set easily. Does "save" really mean "serialize to stable storage"? Why not just set the object aside, in memory, restoring it later via JS_SetGlobalObject? Just checking -- if you do need to serialize to some stable/remote/offline store, then see below. > The question is: How can I convert it into something I can save, then > re-convert back into an object? Doesn't matter what it is; binary > stream, text, large, small, don't care :) Your global object's class could implement the xdrObject hook. See jsxdrapi.h and jspubtd.h. Your class xdrObject hook will be responsible for serializing or deserializing (according as xdr->mode is JSXDR_ENCODE or JSXDR_DECODE) all the properties (global variables, functions, even if not enumerable) and any private data you care about. To discover non-enumerable properties, you will have to use jsdbgapi.h's JS_GetPropertyDescArray. /be .