-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple Duktape contexts with a shared heap #4
Comments
First, I want to say that I love Ducc! It's the Duktape library I didn't know I was waiting for, and it was really easy for me to pick up and use Anyway, for motivation on this issue: I'm trying to implement a CommonJS/NodeJS-style module system in Duktape. Duktape has an official answer on modules, but I feel like the recommended approach is flawed (their official implementation literally wraps the module code in I'd be willing to take a stab at implementing this in a PR, but I think there's multiple different ways to tackle this from an API perspective (all of which have trade-offs). A few possible solutions I've thought about:
I also don't know much about the safety implications of |
I pushed up a WIP/proof-of-concept branch with a basic implementation for this issue: wip/duktape-threading. Unfortunately it segfaults in one of the tests I added so there's still some work to do before it's actually useable! I based it on the |
Thanks for giving this thought. It's one of those things that never came up in my usage but I knew it'd be important in many other cases. I'll help give this some careful study over the next few days (sorry, just a bit busy here) but please feel free to keep iterating and to continue updating this issue! |
Minor update: I fixed the segfault (it happened because I hadn't set |
Currently,
Ducc::new()
always creates a new Duktape heap for the context. However, this means values cannot be shared across contexts except through serialization.The Duktape guide has a section on contexts and heaps that describes how to create a context using a shared heap with
duk_push_thread
orduk_push_thread_new_globalenv
.For prior art, the
v8-rs
crate exposes a similar concept with theContext
andIsolate
types. So, library users would first callIsolate::new()
to create a new isolated v8 instance (analogous to a Duktape heap), thenContext::new(&isolate)
to create the context (analogous to a Duktape context).The text was updated successfully, but these errors were encountered: