quickjs-rs icon indicating copy to clipboard operation
quickjs-rs copied to clipboard

Track JavaScript data lifetimes

Open semirix opened this issue 4 years ago • 2 comments

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?

semirix avatar Sep 13 '20 11:09 semirix

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.

theduke avatar Feb 04 '21 20:02 theduke