-
Notifications
You must be signed in to change notification settings - Fork 72
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
destruction of context causes unbinds all the native modules from JsRuntime #364
Comments
Modules are loaded within a Context not within a Runtime. The runtime only stores the method by which modules are loaded it doesn't store the context themselves. So when a context is dropped all the modules within it are also unloaded. The runtime stores the GC, allocator and other stuff which is specific to the javascript engine functionality. The context stores all the javascript state. If you want to reuse the modules you would need to reuse the context. |
thank you for explaining, now that is a littie bit clear to me. if modules are loaded within JsContext rather than JsRuntime why we don't register modules on JsContext? (e.g. here is my JsRuntime initialization code:
this so should I always re-register modules by calling |
Modules aren't registered in the runtime just the loading function. I see that the provided loaders have a slightly strange behavior where they remove a module once it is loaded preventing it from being loaded again once a new context is created. This should probably be changed. In the mean time you can implement your own loader by implementing the |
Thank you sir, thnaks for your reply :) |
what I want is create a single JsRuntime for my entire application, bind all the necessary native modules, and reuse this runtime on each JsContext, but the problem is that destruction of first JsContext will causes unbind all the native modules registered to JsRuntime so if I create a second JsContext with that JsRuntime I cannot access my native module binding unless rebind all the native modules to JsRuntime again before creating second JsContext.
is this correct behavior or I have misunderstanding to use JsRuntime, JsContext?
if yes what is the correct way to use native modules on single JsRuntime with multiple JsContext?
your native module example works fine because it only create only one JsContext and program will end after simple javascript execution, but if you create multiple JsContext in your example I assume it will not work in second JsContext unless you rebind all the native modules.
and I cannot access my class in javascript registered by rust side, it is can't be work at all, there is no example, nor documentation.
I mean is thank you for making this crate for us but you may face less github issue if you would spend few hours of time to make documentation and more example, I believe a lot of developers struggling the same issue as me.
thank you and have a nice day :)
The text was updated successfully, but these errors were encountered: