-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cloning Context/Value fails w/o ContextGuard #14
Comments
I've spent quite some time this forenoon contemplating just this. I've implemented a fix for the The most prominent alternative I've come up with so far is using a default context, created during the In fact, I'm not quite sure of the list of things not shared between contexts. This would solve these problems, though some issues would persist in a multi-threaded environment, since And I agree that introducing additional lifetime dependencies (i.e |
With a detailed response from a ChakraCore team member I believe I am confident enough to start implementing the default context approach. This would alleviate several of the aforementioned issues, and would allow the API to be simplified. Though the safety risks associated with multi-threading would remain. |
Problem:
The
JsAddRef
andJsRelease
APIs require a current context to be set in order to work. However, they are being exposed through theClone
andDrop
traits that don't require aContextGuard
to be present whenclone
is called, or the value is dropped.This results in the following panics, when a value is cloned and/or dropped w/o a current context:
I'm struggling to think of a way to expose a safe API through clone/drop, tbh. Especially
drop
seems to be problematic, because Rust offers no way to control under which circumstances a value might be dropped.A possible way to fix it could be to tie the lifetime of a Context or Value to the lifetime of the ContextGuard, which would require the value to be dropped before the context guard is dropped, i.e. before the current context is unset, and would require the context guard to be alive in order to clone a value.
The downside is that this complicates storing contexts or values in Rust data structures, but it's the only possible solution I can think of at this point.
The text was updated successfully, but these errors were encountered: