Reputation: 33
I guess that some problems would be on this process.
Do you think that it is safe and stable?
Upvotes: 2
Views: 910
Reputation: 6623
TLDR; It might be possible, but not as full-featured and high-performance as Spidermonkey/V8 (...yet)
Guys from Mozilla already compiled Python to WebAssembly, so why not JavaScript? However, there are some limitations of WebAssembly that has big performance impacts.
Although JS environment is single-threaded, JS runtimes themselves are not. Modern JS engines take advantage of parallelism for parsing, compiling, GC, and etc. WebAssembly 1.0 (aka MVP) does not support threading. There is WebAssembly Threads proposal and currently Chrome and Firefox Nightly support it as an experimental feature and disabled by default. Furthermore, this proposal might take more time to be stable than expected in response to Spectre/Meltdown vulnerability.
WebAssembly has the linear memory model for user space memory (heap). JIT emits optimized machine codes dynamically in order to make it faster. However, for security reasons, WebAssembly does not allow writing and executing instructions from the memory.
Same things happens to iOS. Apple prevents native code execution from memory so custom JS engines cannot have JIT on iOS.
If you are thinking to compile and run a JS engine on WebAssembly,I would suggest trying lightweight JS engines such as JerryScript and Espruino. These aim running JS on embedded systems which are single-core and memory constrainted. They might have less building problems than Spidermonkey/V8.
Anyway, don't expect anything stable as of 2018.
Upvotes: 2