WebAssembly

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WebAssembly
Web Assembly Logo.svg
Paradigm Imperative, structured, expression-oriented
Developer W3C
First appeared March 2017; 1 year ago (2017-03)
Typing discipline Static
OS Web
License Apache 2.0 License
Filename extensions .wat, .wasm
Website webassembly.org
Influenced by
asm.js, PNaCl

WebAssembly (wasm, WA) is a web standard that defines a binary format and a corresponding assembly-like text format for executable code in Web pages. It is meant to enable executing code nearly as fast as running native machine code. It was envisioned to complement JavaScript to speed up performance-critical parts of web applications and later on to enable web development in other languages than JavaScript.[1][2][3] It is developed at the World Wide Web Consortium (W3C) with engineers from Mozilla, Microsoft, Google and Apple.[4]

It is executed in a sandbox in the web browser after a formal verification step. Programs can be compiled from high-level languages into wasm modules and loaded as libraries from within JavaScript applets.

Design[edit]

WebAssembly is a portable structured stack machine[5] which is designed to be faster to parse than JavaScript, as well as faster to execute,[6] and to enable very compact code representation.

History[edit]

Vendor-specific precursor technologies are Google Native Client (NaCl) and asm.js.[1][7] The initial implementation of WebAssembly support in browsers was based on the feature set of asm.js.[8] It was first announced on 17 June 2015[9] and on 15 March 2016 was demonstrated executing Unity's Angry Bots in Firefox,[10] Chromium, Google Chrome,[11] and Microsoft Edge.[12] In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended.[13] In late September 2017, Safari 11 was released with support. As of March 2018, the website Can I use tracks 72.75% global web browser support for WebAssembly (and indirectly, through polyfill, others are supported).[14] In February 2018 the WebAssembly Working Group published three public working drafts for the Core Specification, Javascript Interface, and Web API.[15][16][17][18]

Support[edit]

Mozilla declared support "in all major browsers",[19] e.g. it's also been enabled by default in Edge 16.[20] For backward compatibility, wasm can be compiled into asm.js by a JavaScript applet (a so-called polyfill) and executed on incompatible browsers this way.[21]

Emscripten can compile to wasm[13] using LLVM in the backend.

Its initial aim is to support compilation from C and C++,[6] though support for other source languages such as Rust is also emerging.[22] After the minimum viable product (MVP) release, there are plans to support garbage collection[23] which would make WebAssembly a compilation target for garbage collected programming languages like Java and C#.

Representation[edit]

In March 2017, the WebAssembly Community Group reached consensus on the initial (MVP) binary format, JavaScript API, and reference interpreter.[24] 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 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:[25]

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 (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.[26] An example is shown below:

(module
  (import "math" "exp" (func $exp (param f64) (result f64)))
  (func (export "doubleExp") (param $0 f64) (result f64)
    (f64.mul
      (call $exp
        (get_local $0))
      (f64.const 2))))

See also[edit]

Literature[edit]

References[edit]

  1. ^ a b Lardinois, Frederic (2015-06-17). "Google, Microsoft, Mozilla And Others Team Up To Launch WebAssembly, A New Binary Format For The Web". TechCrunch. Retrieved 2017-12-24. 
  2. ^ Cimpanu, Catalin (2015-06-18). "Mozilla, Microsoft, Google, and Apple Join Efforts to Create a Binary File Format for the Web". softpedia. Retrieved 2017-12-23. 
  3. ^ Hoffmann, Moritz (2015-06-23). "Turbo-Boost für JavaScript: Eric Elliott über WebAssembly". JAXenter (in German). Retrieved 2017-12-23. 
  4. ^ Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast. 
  5. ^ "Design Rationale". GitHub / WebAssembly / design. 1 October 2016. 
  6. ^ a b "WebAssembly High-Level Goals". GitHub / WebAssembly / design. 11 December 2015. 
  7. ^ Avram, Abel (2017-05-31). "Google Is to Remove Support for PNaCl". InfoQ. Retrieved 2017-12-22. 
  8. ^ "WebAssembly: a binary format for the web". ②ality – JavaScript and more. 18 June 2015. 
  9. ^ "Launch bug". GitHub / WebAssembly / design. 11 June 2015. 
  10. ^ Wagner, Luke (14 March 2016). "A WebAssembly Milestone: Experimental Support in Multiple Browsers". Mozilla Hacks. 
  11. ^ Thompson, Seth (15 March 2016). "Experimental support for WebAssembly in V8". V8 Blog. 
  12. ^ Zhu, Limin (15 March 2016). "Previewing WebAssembly experiments in Microsoft Edge". Microsoft Edge dev blog. 
  13. ^ a b Krill, Paul (2017-03-06). "WebAssembly is now ready for browsers to use". InfoWorld. Retrieved 2017-12-23. 
  14. ^ "WebAssembly". Can I use. Retrieved 2018-03-07. 
  15. ^ "WebAssembly First Public Working Drafts". W3C. February 15, 2018. Retrieved April 20, 2018. 
  16. ^ "WebAssembly Core Specification". W3C. February 15, 2018. Retrieved April 20, 2018. 
  17. ^ "WebAssembly JavaScript Interface". W3C. February 15, 2018. Retrieved April 20, 2018. 
  18. ^ "WebAssembly Web API". W3C. February 15, 2018. Retrieved April 20, 2018. 
  19. ^ "WebAssembly support now shipping in all major browsers". The Mozilla Blog. Retrieved 2017-11-21. 
  20. ^ "Introducing new JavaScript optimizations, WebAssembly, SharedArrayBuffer, and Atomics in EdgeHTML 16". Microsoft Edge Dev Blog. Retrieved 2017-11-21. 
  21. ^ Bright, Peter (2015-06-18). "The Web is getting its bytecode: WebAssembly". Ars Technica. Retrieved 2017-12-23. 
  22. ^ Krill, Paul (2017-11-29). "Direct WebAssembly compilation comes to Rust language". InfoWorld. Retrieved 2017-12-24. 
  23. ^ Krill, Paul (2017-10-26). "What's next for WebAssembly: GC, threads, debugging". TechWorld. Retrieved 2017-12-24. 
  24. ^ "Roadmap". WebAssembly. March 2017. 
  25. ^ jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh (9 March 2017). "Text Format". WebAssembly/design. GitHub. 
  26. ^ "Folded instructions". GitHub.  / WebAssembly / spec

Definition of Free Cultural Works logo notext.svg This article incorporates text from a free content work. Licensed under Apache License 2.0 License statement: Text Format, jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh, GitHub. WebAssembly/design. To learn how to add open license text to Wikipedia articles, please see Wikipedia:Adding open license text to Wikipedia. For information on reusing text from Wikipedia, please see the terms of use.

External links[edit]