WebAssembly (often shortened to Wasm) is an open standard that defines a portable binary code format for executable programs, and a corresponding textual assembly language, as well as interfaces for facilitating interactions between such programs and their host environment. The main goal of WebAssembly is to enable high performance applications on web pages, but the format is designed to be executed and integrated in other environments as well.
WebAssembly was first announced in 2015, and the first demonstration was executing Unity's Angry Bots in Firefox, Google Chrome, and Microsoft Edge. The precursor technologies were asm.js from Mozilla and Google Native Client, and the initial implementation was based on the feature set of asm.js.
Because WebAssembly executables are precompiled, it is possible to use a variety of programming languages to make them. This is achieved either through direct compilation to Wasm, or through implementation of the corresponding virtual machines in Wasm. There have been around 40 programming languages reported to support Wasm as a compilation target.
Its initial aim is to support compilation from C and C++, though support for other source languages such as Rust and .NET languages is also emerging. After the MVP release, there are plans to support multithreading and garbage collection which would make WebAssembly a compilation target for garbage-collected programming languages like C# (supported via Blazor) and F# (supported via Bolero with help of Blazor); Java, Julia, Ruby, as well as Go.
In June 2018, a security researcher presented the possibility of using WebAssembly to circumvent browser mitigations for Spectre and Meltdown security vulnerabilities once support for threads with shared memory is added. Due to this concern, WebAssembly developers put the feature on hold. Thread support was eventually added in October 2018.
The core standard defines a unique Instruction Set Architecture consisting of specific binary encoding and which is intended to be executed by VM. However it doesn't specify how exactly they must be invoked by it.
The table below represents three different views of the same source code input from the left, as it is converted to a Wasm intermediate representation, then to Wasm binary instructions:
|C input source||Linear assembly bytecode|
|Wasm binary encoding|
get_local 0 i64.eqz if (result i64) i64.const 1 else get_local 0 get_local 0 i64.const 1 i64.sub call 0 i64.mul end
20 00 50 04 7E 42 01 05 20 00 20 00 42 01 7D 10 00 7E 0B
The WebAssembly text format can also be written in a folded format using s-expressions. This format is purely syntactic sugar and has no behavioral differences with the linear format. An example is shown below:
Haas, Andreas; Rossberg, Andreas; Schuff, Derek L.; Titzer, Ben L.; Gohman, Dan; Wagner, Luke; Zakai, Alon; Bastien, JF; Holman, Michael (June 2017). "Bringing the web up to speed with WebAssembly"  . Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation. Association for Computing Machinery: 185–200. doi:10.1145/3062341.3062363  .