tonyg/js-nacl

Multithreading support

tanx opened this issue · 5 comments

tanx commented

Sorry for all the github issues, but I've got some time today. I've been checking out the generated emscripten code and I noticed the following functions:

Module.onFullScreen
checks
document.webkitFullScreenElement

and

Module.requestAnimationFrame
checks
window.requestAnimationFrame

I would guess, that those Module functions are hooks for potential GUI use-cases for an emscripten module, but I don't think they are relevant for a crypto library. The problem is that in order for multithreading to work inside the browser (via WebWorker), a script can't reference either 'window' or 'document' as they aren't thread-safe. The details can be read here:
http://www.html5rocks.com/en/tutorials/workers/basics/

Question: is there any way to remove the Module functions by changing emscripten arguments? I could just remove those manually by hand before closure minifies the scripts, but that would not be very automation friendly. Thanks

I don't know the answer to that; I've only just started working with Emscripten. Perhaps ask over there? (Not sure if there's IRC or a mailing-list.) Alternatively sed'ing out the offending pieces might work, but yeah, fragile and icky.

tanx commented

Ok. I couldnt find the anwser in the emscripten wiki. Irc or mailinglist is probably a good idea.

tanx commented

I found a solution for adding Multithreading support by simply changing two lines of code in nacl_cooked_prefix & sufix.js. Would you like me to do a pull request? Thanks

That sounds great! Please do. I'll be interested to see what needs to change.

tanx commented

Ok I sent you a pull request.