quickjs-rs
quickjs-rs copied to clipboard
Track JavaScript data lifetimes
I'm embedding this in a rendering application where rendered objects can be scripted in the frontend. The problem is that the rendered objects are managed in Rust but created in JavaScript. When the JS objects are garbage collected, they remain in the Rust backend. Ideally this should be automated so when the JS objects are deleted there is some automated way of having the Rust data associated be deleted too. Is there a way of achieving this currently or a implementation that could enable this?
As @pavlukivan pointed out, this is possible.
It would require exposing the JS_NewClass
, SetOpaque
and then provide a finalizer that can call a Rust callback.
Currently the exposed QuickJS API surface is very minimal on purpose.
I probably won't have time to implement this anytime soon, but I'd happily accept a PR.