Is it possible to mutate JavaScript values with wasm?

For example, can I do something like this?


  let foo = {num: 1};
  console.log(foo) // {num: 2}

I was reading the wasm-bindgen docs, and this looked like what I wanted at first:
But my initial tests to add one failed, even if foo was just an integer. Here was my rust code for that:

    pub fn add_one(num: *mut u8) {
        unsafe {
            *num += 1;

Technically no. The only types you can get across are integers and floats.
What wasm-bindgen would do is to store the variable reference in an array, then call something like set_arg_i32(index_of_value, new_value) which would be implemented in JS.

In your case, just return the new value.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.