Cannot start TeaVM-compiled JavaScript code from Web Worker using eval() #731
-
|
Hello there, I'm attempting to create a self-contained JavaScript file that spawns workers of itself. My approach fetches the JavaScript file, fetch('%s').then(response=>response.text().then(script=>{globalThis.eval(script);main();}))I've tried different dynamic code execution methods, but none of them worked. Is there something I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Instead of eval, did you try using importScript? As for your code, |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your response! Your suggestion worked, but I was able to alternatively get it working by converting the JavaScript file into a Function, appending |
Beta Was this translation helpful? Give feedback.
Instead of eval, did you try using importScript? As for your code,
evalcreates a separate scope, andmainis defined there, not in the scope that actually callsmain. Witheval-based approach it would look something like that: