Passing an object from JS to ocaml

I understand that in Rust/wasm_bindgen, we can define a JS class bar, its static functions, and its methods. See Importing a class from JS - The `wasm-bindgen` Guide

Here is what I do not understand:

  1. How do we pass a Bar from JS to Rust ?

  2. how does Rust, when holding on to the Bar, inform JS land: "yo, don't GC this"

  3. How does Rust, after it drops type Bar, inform JS land "no longer holding ref to Bar"


If I remember correctly, the glue code wasm-bindgen generates keeps a list of the objects that it passes to the Rust side. When the object is dropped Rust calls back into the glue code to remove the object from the list.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.