It took a few milliseconds for the results to be shown. Now, let's look for something else. Let's look for bottom, for example. And we get even more results at the same exact speed.
Now, clicking on the results, we're immediately redirected to the corresponding page the result citation comes from. Let's now inspect what's happening under the hood in this example. Is this a JavaScript client side functionality bootstrapped to the static pages running against the database somewhere?
If we go to the sources right now with the inspector, let me bring it and focus the search bar, we will immediately see something happening here. Here. We see this wasm source and the contents of the module. We have demonstrated that we can seamlessly run and operate between JavaScript programs and WebAssembly modules. There are platform APIs that make it easier to transfer memory, to trigger events or update state between code running in the window object and that running on a worker.
And you may say, okay, that's very nice, Natalia, but that's not JavaScript. I know it's Rust. And you're right. So what if we want to use JavaScript end to end, including in non-browser scenarios where just in time flows may not be the best option or may be unsupported. Do we have the tools to do so? Can we make JavaScript portable from the browser to non-browser environments and back and forth for real? Can we do this?
Let's start by answering this question. If WebAssembly needs a JavaScript engine and those are usually part of a browser, can we run WebAssembly in non-browser scenarios? We can, as long as we provide additional interfaces. For example, those of WASI or the WebAssembly system interface. WebAssembly system interface is just another standard. It's a modular system interface built for WebAssembly outside of the browser. And it's fully compatible with POSIX systems. Just as WebAssembly uses the JavaScript virtual machine to run in the browser, WebAssembly with enabled WASI runs in a special runtime that can even run on bare metal.
Remember that WebAssembly has no access to any APIs and that we don't explicitly import. That is, they are entirely secure environments from that point of view. They are sandboxed. We'll talk more about these security features in a bit. Let's now see a demo of JavaScript code that was written once and runs in the browser and on WASM time using a tool chain called Javi. Welcome to my binary translator. Now, for this demo, I need some dependencies. I need Javi, a JavaScript WebAssembly tool chain, and since I'm not going to be running this only on the browser, I will need a standalone runtime for WASM, in this case, WASM time.
Comments