WebAssembly or wasm is a low-level bytecode format for in-browser client-side scripting, evolved from JavaScript. Its initial aim is to support compilation from C and C++,[1] though other source languages such as Rust are also supported.[2]

Design

WebAssembly is a portable stack machine[3] which is designed to be faster to parse than JavaScript, as well as faster to execute.[1]

History

WebAssembly was first announced on 17 June 2015[4] and on 15 March 2016 was demonstrated executing Unity‘s Angry Bots in Firefox,[5] Chromium, Google Chrome,[6] and Microsoft Edge.[7] In late September 2017, Safari 11 was released with support. As of October 2017, the website, Can I use, tracks 61.34% global web browser support for WebAssembly, led by Chrome and Firefox.[8] Mozilla declared support “in all major browsers”,[9] e.g. it’s also been enabled by default in Microsoft Edge 41.[10]

Development

The initial implementation of WebAssembly support in browsers will be based on the featureset of asm.js.[11] After the minimum viable product (MVP) release, there are plans to support garbage collection[12][13] which would make WebAssembly a compilation target for garbage collected programming languages like Java and C#. The team working on WebAssembly includes employees of Mozilla, Microsoft, Google and Apple.[14]

Representation

In March 2017, the WebAssembly Community Group reached consensus on the initial (MVP) binary format, JavaScript API, and reference interpreter.[15] It defines a WebAssembly binary format, which is not designed to be used by humans, as well as a human-readable linear assembly bytecode format that resembles traditional assembly languages.

The table below represents 3 different views of the same source code input from the left, as it is converted to a wasm intermediate representation, then to wasm binary:[16]

C (Input Source) text “linear assembly bytecode” (intermediate representation) WASM binary encoding (Binary shown below in hexadecimal)
int factorial(int n) {
  if (n == 0)
    return 1;
  else
    return n * factorial(n-1);
}
get_local 0
i64.eqz
if 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

At the moment, the tooling of the wasm compiler system internally uses s-expressions (for parsing simplicity as well as extra information that “linear assembly bytecode” representation does not contain) to handle intermediate code. An example is shown below (updated to the current format):[17]

(module
  (type $FUNCSIG$dd (func (param f64) (result f64)))
  (import "global.Math" "exp" (func $exp (param f64) (result f64)))
  (memory 256 256)
  (export "memory" (memory 0))
  (func $doubleExp (param $0 f64) (result f64)
    (f64.mul
      (call $exp
        (get_local $0)
      )
      (f64.const 2)
    )
  )
  (export "doubleExp" (func $doubleExp))
)

See also

References

  1. ^ a b “WebAssembly High-Level Goals”. GitHub / WebAssembly / design. 11 December 2015. 
  2. ^ “Announcing Rust 1.14”. The Rust Programming Language Blog. 22 December 2016. 
  3. ^ “Design Rationale”. GitHub / WebAssembly / design. 1 October 2016. 
  4. ^ “Launch bug”. GitHub / WebAssembly / design. 11 June 2015. 
  5. ^ Wagner, Luke (14 March 2016). “A WebAssembly Milestone: Experimental Support in Multiple Browsers”. Mozilla Hacks. 
  6. ^ Thompson, Seth (15 March 2016). “Experimental support for WebAssembly in V8”. V8 Blog. 
  7. ^ Zhu, Limin (15 March 2016). “Previewing WebAssembly experiments in Microsoft Edge”. Microsoft Edge dev blog. 
  8. ^ “WebAssembly”. Can I use. Retrieved 2017-10-29. 
  9. ^ “WebAssembly support now shipping in all major browsers – The Mozilla Blog”. The Mozilla Blog. Retrieved 2017-11-21. 
  10. ^ “Introducing new JavaScript optimizations, WebAssembly, SharedArrayBuffer, and Atomics in EdgeHTML 16 – Microsoft Edge Dev BlogMicrosoft Edge Dev Blog”. blogs.windows.com. Retrieved 2017-11-21. 
  11. ^ “WebAssembly: a binary format for the web”. ②ality – JavaScript and more. 18 June 2015. 
  12. ^ “WebAssembly/design”. GitHub. Retrieved 15 November 2017. 
  13. ^ “WebAssembly/gc”. Github. 
  14. ^ Bright, Peter (18 June 2015). “The Web is getting its bytecode: WebAssembly”. Ars Technica. Condé Nast. 
  15. ^ “Roadmap”. WebAssembly. March 2017. 
  16. ^ jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh (9 March 2017). “Text Format”. WebAssembly/design. GitHub. 
  17. ^ Larsen, Nick (24 June 2016). “Build Your First Thing With WebAssembly”. Culture of Development: The Pit of Success. 

This article incorporates text from a free content work. Licensed under Apache License 2.0 Licence statement: Text Format, jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh, GitHub. WebAssembly/design.

To learn how to add freely licensed text to Wikipedia articles, please see the terms of use.

External links