Hi,

I have this simple use case:

hello-worker.html -----------------------8<---------------------
<!doctype html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Emscripten Test</title>
    <script type="text/javascript">
      var w = new Worker("hello-worker.js");
    </script>
  </body>
</html>
hello-worker.html -----------------------8<---------------------


hello.c: -----------------------------8<------------------------
#include <stdio.h>

void foo(void)
{
    printf("foo\n");
}

int main() {
    return 0;
}
hello.c: -----------------------------8<------------------------


hello-worker.js ---------------------8<-------------------------
importScripts("hello.js");

if (Module) {
    console.log("Module is defined");
}
hello-worker.js ---------------------8<-------------------------

I compile hello.js with:
EMCC hello.c -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1 -s 
EXPORTED_FUNCTIONS="['_foo']" --closure 1 -O2 -o hello.js

For some reasons when the hello.js code is loaded from the worker,
Module is not defined and I get:

ReferenceError: Module is not defined hello-worker.js:3
"run() called, but dependencies remain, so not running" hello.js:4

This only happens with -O2 --closure 1, it will work with -O2
--closure 0 or with -O1 --closure 1.

The equivalent non-worker code is working fine (that is Module is
correctly referenced):
hello.html -----------------------8<---------------------
<!doctype html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Emscripten Test</title>
    <script type="text/javascript" src="hello.js"></script>
    <script type="text/javascript">
    if (Module) {
        console.log("Module is defined");
    }
    </script>
  </body>
</html>
hello.html -----------------------8<---------------------

BTW this is probably affecting Broadway, see
https://github.com/mbebenita/Broadway/issues/45

Can someone explain why this is happening? Should I file an issue?

TIA

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to