About WebAssembly

WebAssembly is an open specification for:

  • a stack-based virtual machine (standalone or embeddable in a host environment like a web browser or any other program)
  • modules, executed as standalone programs or libraries of functions on this VM
  • a binary encoding for modules, usually saved as .wasm files: useful for network transfer, disk storage and actually running wasm code
  • a textual representation of modules, usually saved as .wat files: it is based on S-expressions and is useful for humans to write and debug wasm modules by hand.

This is a generic and flexible middle-level virtual machine:

  • unlike JVM/CLR/v8, it is not tied to a GC and object system. Its basic types are just primitive numbers (i32, i64, f32, f64), function references and opaque references. The computation happens on its internal stack and can only use a strictly isolated linear memory.

  • unlike actual machine instruction sets like x86_64/aarch64/risc-v, it is strongly typed and has structured control flow that makes arbitrary jumps impossible.

  • it provides strong and verifiable isolation and is a hermetic sandbox; imported and exported WASM functions are entirely controlled by the host; no host capabilities (I/O, DOM API, ...) are accessible by default.

  • despite "Web" in its name, it does not require JavaScript or any other web technologies, even though it has a standardized JavaScript API. For example, wasm3 is an implementation that successfully runs on microcontrollers.

  • the stack-based bytecode is simple, compact and easy to (JIT-)compile to native code