Search code examples
javascriptwebassemblyisolationjavascript-injection

Is there a Javascript runtime in WebAssembly


I am trying to isolate user JavaScript code for security. I can do this via Iframe security and message passing.

Is there a JavaScript runtime that can be loaded via webassembly to which i can pass something simple like '5+3' and read the result.

If this was c# etc I could new up and manage a V8 engine and have it execute the javascript and pass back to the host.


Solution

  • JavaScript engines are typically written in C++ making them an ideal candidate for compiling to WebAssembly using Emscripten. And yes, you could use this for the purposes of isolation - see this excellent blog post from Figma that discusses that specifically:

    https://www.figma.com/blog/how-we-built-the-figma-plugin-system/

    It also discusses various other useful options such as Realms.