Subj : Re: cloning context/runtime To : Brendan Eich , mozilla-jseng@mozilla.org From : matthias@atip.de (Matthias Thiel) Date : Thu Aug 07 2003 01:01 pm On Wed, 06 Aug 2003 18:41:50 -0700 Brendan Eich wrote: > Matthias Thiel wrote: > > >Hi, > > > >is there a simple possibility for creating a copy of a context or runtime ? > >The idea is to create a copy of the whole ecmascript environment which may be changed by some scripts. After execution of these scripts, it should be possible to "rollback" all changes in the context for working with the original context. A rollback function would be too complex, so I want to create a copy of the whole context that I may use for retrieving the old state. > >Would it be a good idea to implement a function for deep copying the context struct ? > > > > Side effects of scripts running are not limited to context, which has > mostly hidden state. Any object in the runtime's heap that can be > reached from an object available to the script could be affected. > Native data structures hidden from the engine too. Without transaction > support in the API, you can hope only to snapshot and rollback object > property changes (adds/deletes/value-changes/attribute-changes). That's > not easy or efficient, though. > > Why do you want this, btw? I'm working on a VoiceXML Interpreter and I want to integrate the spidermonkey library. According to our interpretation of the VXML specification it is necessary to copy a context for executing the so called subdialogs. The specification says that the subdialogs should not influence the original context, but they should have access to the original context. For being sure, that they do not modify the original context, the best solution should be to create a new context that will be filled with the needed inf ormation from the original one. Maybe it will be enough for now to copy only the objects and its properties to the new context without keeping all internal changes of scripts. The functionality I didn't found in the API is to get a list of all properties belonging to a JSObject for reading them out and setting them in the new context/object. Is there already a function for that ? What would be the easiest way to implement it on my own ? best regards, Matthias Thiel -- Matthias Thiel ATIP GmbH Software Developer Daimlerstr. 32 D-60314 Frankfurt/Main phone: +49 69 941963 220 fax: +49 69 941963 188 web: www.atip.de .