You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! While I've gotten used to storing everything in ducc.globals(), I still get a bit annoyed at the whole retrieve everything from globals every time. For instance, for many calls crossing the Rust<->JS boundary I'll have to do something like ducc.globals().get("namespace").get("library").get("_refs").get(index).
However, I got an idea for a potential way to kind of store references to Duktape for faster and nicer retrieval, without sacrificing any safety guarantees. Basically, it'd be a handle type looking something like this:
and API for retrieving an ObjectHandle from an Object somewhere.
Some practical concerns would be making sure that GC doesn't remove our object when we hold a handle (but is able to if we don't), which depends on Duktape's support for it. One scary bit is Drop for ObjectHandle; how can we inform Duktape that it's okay to GC the referenced object without access to &Ducc? Maybe a drop_object_reference(&Ducc) that must be called before Drop or it will panic.
The benefits of this approach would be the ability to keep a reference certain objects without caring about what is happening in the JS world, and I think the ergonomics of using it are better than the global referencing as well. If this works, it could be extended to FunctionHandle etc as well.
Does this sound like a viable/safe idea? If it turns out well, maybe the same approach would work with Mini-V8 as well.
The text was updated successfully, but these errors were encountered:
Hi! While I've gotten used to storing everything in
ducc.globals()
, I still get a bit annoyed at the whole retrieve everything from globals every time. For instance, for many calls crossing the Rust<->JS boundary I'll have to do something likeducc.globals().get("namespace").get("library").get("_refs").get(index)
.However, I got an idea for a potential way to kind of store references to Duktape for faster and nicer retrieval, without sacrificing any safety guarantees. Basically, it'd be a handle type looking something like this:
and API for retrieving an ObjectHandle from an Object somewhere.
Some practical concerns would be making sure that GC doesn't remove our object when we hold a handle (but is able to if we don't), which depends on Duktape's support for it. One scary bit is Drop for ObjectHandle; how can we inform Duktape that it's okay to GC the referenced object without access to &Ducc? Maybe a
drop_object_reference(&Ducc)
that must be called before Drop or it will panic.The benefits of this approach would be the ability to keep a reference certain objects without caring about what is happening in the JS world, and I think the ergonomics of using it are better than the global referencing as well. If this works, it could be extended to FunctionHandle etc as well.
Does this sound like a viable/safe idea? If it turns out well, maybe the same approach would work with Mini-V8 as well.
The text was updated successfully, but these errors were encountered: