my2iu / TADS2-html5

Port of the TADS 2 interpreter for HTML5
Other
5 stars 1 forks source link

Only works in Chrome, due to SharedArrayBuffer requirement #4

Open agwells opened 6 years ago

agwells commented 6 years ago

As noted in issue #1, all web browsers are disabling the JS SharedArrayBuffer api as a mitigation against the Meltdown and Specter security issues. That prevents this project from working, because it relies on SharedArrayBuffer to synchronously pass data between the TADS process (running in a web worker) and the user interface (in the browser window).

The core of the problem is that JS's main way to pass data back and forth to a web worker, is via the JS event system. In the browser, you do postMessage(), which sends a message event to the web worker, and that tells JS to invoke the onmessage eventhandler method in the web worker (if it's registered).

Where it breaks down for us, is that JS is asynchronous but single-threaded. Even if an onmessage handler is registered in the web worker, it won't actually be executed until any currently-executing methods in the web worker exit. And the tadsr program, as transpiled by emscripten, doesn't exit until the program quits.

We're not the first to encounter this problem. See:

The apparent solutions available are:

None of these are easy to do, however. As noted in the readme, Emterpreter and ASYNCIFY have already been tried. And the emscripten async functions would require a major rewrite of the plygo() method in tads2/ply.c and related I/O functions.

agwells commented 6 years ago

Update: Chrome re-enabled SharedArrayBuffer in version 68, which came out in May 2018. So, this project works fine now in Chrome (and Chromium).