Wasm-bindgen: Allow Serialize/Deserialize into a `JsValue`

Created on 29 Mar 2018  路  3Comments  路  Source: rustwasm/wasm-bindgen

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!

help wanted

Most helpful comment

I've posted an initial pass of this API at https://github.com/rustwasm/wasm-bindgen/pull/171

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

expobrain picture expobrain  路  4Comments

MarcAntoine-Arnaud picture MarcAntoine-Arnaud  路  3Comments

arilotter picture arilotter  路  3Comments

bantic picture bantic  路  4Comments

fitzgen picture fitzgen  路  3Comments