wasm-bindgen
wasm-bindgen copied to clipboard
Convert `JsValue` to `js_sys::Object`
Summary
Hi!
I want to implement something like deep equal on Rust to speed up comparing AST nodes in 🐊Putout code transformer.
Right now I have such code:
let value_to = js_sys::Reflect::get(current_to, &key)?;
value_to is JsValue, but I need to get keys of an object and using Object::keys:
let keys_from: Array = Object::keys(&value_to);
But that's not work because Object::keys expects to receive js_sys::Object.
How can I convert JsValue to js_sys::Object and vice versa?
Additional Details
I tried to use serde_wasm_bindgen, but I have an error:

Object::try_from doesn't works here:

You can do this using dyn_into. Instead of Object::try_from(&value_to).unwrap(), use value_to.dyn_into().unwrap(). (You'll also need to import JsCast to use it).