robertkrimen / otto

A JavaScript interpreter in Go (golang)
http://godoc.org/github.com/robertkrimen/otto
MIT License
7.97k stars 584 forks source link

Serializing otto.Value #113

Open michaelbironneau opened 9 years ago

michaelbironneau commented 9 years ago

At the moment I'm using Call to invoke JSON.stringify on an object to serialize it - is that the best way to do it? Ideally I'd like to use something like gob but at the moment that won't work (Value doesn't export any fields). Am I missing something obvious?

Great package by the way, really nice work :).

stevenh commented 9 years ago

Do you have a more specific example of what your trying to do Michael?

michaelbironneau commented 9 years ago

The idea is to persist an object created by user Javascript in Otto to a file or database and then recreate this object later on (possibly under a different context, or even a different machine). We want to do this to save the state of an stream processing application that runs user code (Javascript) inside Otto so that if the application crashes, we can resume processing from an earlier state. Specifically:

It would be even better if we could serialize the whole context, as the user Javascript wouldn't be restricted to using this state object, but that's probably more difficult.

Hope that makes more sense?

dtylman commented 8 years ago

Would be happy to see this functionality also.