We should have an option to convert an arbitrary object to a JsValue via Serialize an Deserialize. It may not be quick but it's often quite useful!
I want to take a stab at this and have a couple of questions.
Would you be in favor changing JsValue into an enum to make it easier to match based on its type during serialization?
It's not apparent how we deal with objects and arrays right now (if at all). Would you mind providing some instructions for how that would work?
Nah for now I'd like to leave JsValue opaque as it represents a foreign JS object which we don't know the value of. I think it'd be fine though to add a decode method which could return an enum, however, storing the various values internally.
I think that implementing this may actually be easiest to just convert straight to JSON, send that to JS, and then parse the object and return an index. Alternatively we could add accessors/creators to JsValue for objects and arrays (e.g. the ability to set keys), but that would involve crossing the wasm/JS boundary which may not be as efficient
I've posted an initial pass of this API at https://github.com/rustwasm/wasm-bindgen/pull/171
Most helpful comment
I've posted an initial pass of this API at https://github.com/rustwasm/wasm-bindgen/pull/171