Getting exports from an evaluated module with get_module_namespace always results in null values
Trying to get module exports like the example here
The module is loaded with load_main_module, I call mod_evaluate on the ID returned, then do the below:
But the value returned is always undefined
Js:
Rust:
GitHub
feat(core): Adds a new method get_module_namespace to access the na...
Allows users to access the namespace object of a module.
Example - Extracting the default export binding of a JavaScript module using deno_core
...
let module_namespace = runtime.get_module_namespa...
6 Replies
I'm sorry, but the documentation does not provide a clear answer to your question about why you're getting null values when trying to get exports from an evaluated module with
get_module_namespace
. It might be a good idea to check if the module is correctly loaded and evaluated before trying to access its exports. If the problem persists, you might want to ask for help in a Deno related community or forum, providing them with the complete code you're working with.I know the module is loaded because I can pull values from global. It's just exports that don't work
@mmastrac hate to bug you again, but
TBH I'm not familiar with that particular v8 API. It looks like it should work, but I'm not sure why it isn't. Sorry about that. Someone else may be able to help, however.
Alright!! I figured it out
It was a small error in how I captured the module_id from the async move tokio was blocking on
Can valid ModuleIds ever be 0? Since they are a usize
Because if not, a check for that might be useful
Ah nice. If not, we could make them https://doc.rust-lang.org/stable/std/num/struct.NonZeroUsize.html
NonZeroUsize in std::num - Rust
An integer that is known not to equal zero.
https://github.com/denoland/deno_core/blob/2af63b92b1e26871d44c6cf5db57464a761911f4/core/modules/map.rs#L381
Loader is created with next_load_id of 1
So it should never be 0
I think a NonZeroUsize makes more sense in that context, since usize has a default value which is invalid here
Seems the 0 module_id is actually being used in a few spots to represent the lack of loaded modules, by reading it as
self.handles.len()