felixhao28/JSCPP

WebWorker compatibility (for browser multi-threading)

BruceKnowsHow opened this issue · 1 comments

The JSCPP distribution has exactly one error when being loaded into a WebWorker via importScripts(). That error has to do with the way window.JSCPP is assigned in index.js. WebWorkers don't have access to the window object. I was able to fix it in the context of my project by doing the following replacement.

Before:
window.JSCPP = require('./launcher').default;
After:
var JSCPP = require('./launcher').default;

This completely fixes the issue and I'm able to run C++ via a worker. However, I am not familiar enough with NodeJS to determine whether this is a reasonable solution. Just wanted to bring this to your attention.

Thank you for this project, it has been extremely helpful so far.

Thanks for pointing it out. I just added two helper classes to make running JSCPP in WebWorkers easier:

https://github.com/felixhao28/JSCPP/tree/master#running-in-webworker

It should be helpful for you. Debugging in WebWorker is supported too. You can find example code in https://github.com/felixhao28/JSCPP/blob/master/dist/index.html.