WebAssembly

What is WebAssembly?

WebAssembly is a dedicated binary file format that can be loaded into a web browser and run. Yes, it is possible to run binary files with all four major web browsers. Moreover, it is almost certain that you can compile programs written in your favorite programming language into a binary format that can be loaded and run with a normal browser.

In general WebAssembly is not a programming language. It is designed as a compilation target for traditional programming languages such as C++, Java and Python, allowing "ordinary" programs to run in a regular web browser, as well as developing software for the Web using traditional tools. WebAssembly is also designed to run programs at near-native speeds, making it possible to perform intensive tasks such as rendering 3D graphics or processing audio or video files in a web browser.

WebAssembly like other internet standards is open. So using it is not a method to hide proprietary source code from its users as WebAssembly binaries can easily be converted to high-level source code, like for instance C.

WebAssembly modules are loaded into the browser with Javascript now, but in the future they will be loaded directly by browsers like Javascript modules are loaded today.

WebAssembly is now supported and can be run in all major browsers: Chrome, Firefox, Safari nad Edge.

WebAssembly is developed by various organizations like WebAssembly Forum, W3.org WebAssembly Working Group, Bytecode Aliance and various companies like Google, Intel, Microsoft, Amazon or Mozilla.

How does it work?

The result of compilation of high-level source code is a set of low-level instructions for a Virtual Stack Machine running in the browser. WebAssembly is a bytecode meaning that every single byte (except data bytes) is a specific instruction. For instance 0x7F (0111 1111 in binary) is a declaration of a 32-bit integer data type, 0x6A (0110 1010 in binary) is an addition instruction, while 0x0B (0000 1011 in binary) is a declaration of a conditional statement (if).

WebAssembly binary format (wasm) has its textual representation WebAssembly Text Format (wat). This format allow to write WebAssembly files by hand. Moreover since binary files can easily be converted to text files and vice versa they can also be used to debug compiled files from high-level languages. In fact Chrome Development Tools already suports it.

The smallest structural component of WebAssembly that can be loaded into a web browser and run is a module. So every single WebAssembly file represents a single module. Conceptually, each WebAssembly module is a tree consisting of connected nodes. One of them is the parent node, the others are child nodes. These child nodes can be one of many types.

Modules are represented in WebAssembly Text format using S-expressions, which simply represent a tree structure with its nodes, dependencies, and values. In this representation, each node is written using a pair of parentheses, inside which there is a text label specifying the type of node, and a space-separated list of elements defining its properties, each of which can be a set of consecutive nodes.

..