How can I export/import the Module object ?

31 views
Skip to first unread message

Mehdi Sabwat

unread,
Jan 27, 2020, 6:49:59 AM1/27/20
to emscripten-discuss
Hi,

I want to be able to import the Module object from another file (a worklet-processor in my case).
The problem is that if I have a worker, it will evaluate the "export default Module", I guess it's because of a "eval(...)" in importScript().
I tried appending :
if (ENVIRONMENT_IS_WEB == 1)
{
   
export default Module;
}

but I am getting this error :
Uncaught SyntaxError: Unexpected token 'export'

Here is the context :
<script async type="module" src="./experimental.js"></script>
<script type="module">
import Module from "./experimental.js";

console
.log(Module.wasmMemory.buffer.byteLength);
</script>

I tried a lot of things, including using -s MODULARIZE=1, which does not help because (in my case) it slows down the application a lot. And even with that, I couldn't use the same Module object instance in the worklet.

There is an example here that works setting aside the fact that the audio context won't start because it's not initialized after a user gesture, but it won't work in my case with:
+#include <emscripten.h>
 
#include "emscripten/bind.h"
 
 
using namespace emscripten;
@@ -53,6 +53,11 @@ class VariableBufferKernel {
   
unsigned bytes_per_channel_ = 0;
 
};
 
+int main(){
+  EM_ASM(Module["noExitRuntime"] = true;);
+  return 0;
+}

I put the logs in a file.

Anyone has an idea on what I should do to try to solve this issue?
Thanks

Regards
Mehdi
logs.out

Mehdi Sabwat

unread,
Feb 8, 2020, 1:19:12 PM2/8/20
to emscripten-discuss
Answering my self, the solution was provided by Paul Adenot which seems to work for my usecase.

The idea is to createObjectURL from the workletprocessor and the file where you define the objects you need access to.

I guess it's understandable that we cannot have "real time" access to the Module object because we provide the worklet with a Class definition, which explains why what I was trying to do wouldn't work, and didn't make much sense.
Reply all
Reply to author
Forward
0 new messages