WebAssembly
Paradigm | Imperative, structured, expression-oriented |
---|---|
Designed by | W3C |
Developer |
|
First appeared | March 2017 (2017-03) |
Typing discipline | Static |
License | Apache 2.0 |
Filename extensions |
|
Website | webassembly.org |
Influenced by | |
|
WebAssembly (often shortened to Wasm) is a standard that defines a binary format and a corresponding assembly-like text format for executables used by web pages.
The purpose of Wasm is to enable the JavaScript engine of a web browser to execute page scripts nearly as fast as native machine code. But this is not a full replacement for JavaScript; rather, Wasm is only intended for performance-critical portions of page scripts.[1][2][3] Wasm code runs in the same sandbox as regular script code, but only regular scripts have direct access to the DOM tree.
The World Wide Web Consortium (W3C) maintains the standard with contributions from Mozilla, Microsoft, Google, and Apple.[1]
Contents
1 History
2 Support
3 Representation
4 Literature
5 References
6 External links
History
WebAssembly was first announced in 2015,[4] and the first demonstration was executing Unity's Angry Bots in Firefox,[5]Google Chrome,[6] and Microsoft Edge.[7] The precursor technologies were asm.js from Mozilla and Google Native Client,[8][9] and the initial implementation was based on the feature set of asm.js.[10]
In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended.[11] In late September 2017[update], Safari 11 was released with support. In February 2018, the WebAssembly Working Group published three public working drafts for the Core Specification, JavaScript Interface, and Web API.[12][13][14][15]
Support
In November 2017, Mozilla declared support "in all major browsers",[16] after WebAssembly was enabled by default in Edge 16.[17] The support includes mobile web browsers for iOS and Android. As of March 2018[update], 81.41% of installed browsers support WebAssembly.[18]
But for older browsers, Wasm can be compiled into asm.js by a JavaScript polyfill.[19]
Because WebAssembly executables are pre-compiled, it is possible to use a variety of programming languages to make them.[2] 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 compilation target.[20]
Emscripten can compile to Wasm[11] using LLVM in the backend.
Its initial aim is to support compilation from C and C++,[21] though support for other source languages such as Rust and .NET languages is also emerging.[22][23][20] After the minimum viable product (MVP) release, there are plans to support multithreading and garbage collection[24] which would make WebAssembly a compilation target for garbage-collected programming languages like Java, C# (supported via Blazor), and Go.
Representation
WebAssembly code is intended to be run on a portable abstract structured stack machine,[25] which is designed to be faster to parse than JavaScript, as well as faster to execute,[21] and to enable very compact code representation.
In March 2017, the WebAssembly Community Group reached consensus on the initial (MVP) binary format, JavaScript API, and reference interpreter.[26] 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:[27]
C input source | Linear assembly bytecode (intermediate representation) | Wasm binary encoding (hexadecimal bytes) |
---|---|---|
int factorial(int n) | get_local 0 | 20 00 |
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.[28] 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)
)
)
)
Literature
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..mw-parser-output cite.citationfont-style:inherit.mw-parser-output .citation qquotes:"""""""'""'".mw-parser-output .citation .cs1-lock-free abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/6/65/Lock-green.svg/9px-Lock-green.svg.png")no-repeat;background-position:right .1em center.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/d/d6/Lock-gray-alt-2.svg/9px-Lock-gray-alt-2.svg.png")no-repeat;background-position:right .1em center.mw-parser-output .citation .cs1-lock-subscription abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Lock-red-alt-2.svg/9px-Lock-red-alt-2.svg.png")no-repeat;background-position:right .1em center.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registrationcolor:#555.mw-parser-output .cs1-subscription span,.mw-parser-output .cs1-registration spanborder-bottom:1px dotted;cursor:help.mw-parser-output .cs1-ws-icon abackground:url("//upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Wikisource-logo.svg/12px-Wikisource-logo.svg.png")no-repeat;background-position:right .1em center.mw-parser-output code.cs1-codecolor:inherit;background:inherit;border:inherit;padding:inherit.mw-parser-output .cs1-hidden-errordisplay:none;font-size:100%.mw-parser-output .cs1-visible-errorfont-size:100%.mw-parser-output .cs1-maintdisplay:none;color:#33aa33;margin-left:0.3em.mw-parser-output .cs1-subscription,.mw-parser-output .cs1-registration,.mw-parser-output .cs1-formatfont-size:95%.mw-parser-output .cs1-kern-left,.mw-parser-output .cs1-kern-wl-leftpadding-left:0.2em.mw-parser-output .cs1-kern-right,.mw-parser-output .cs1-kern-wl-rightpadding-right:0.2em
Watt, Conrad (2018). "Mechanising and Verifying the WebAssembly Specification" (PDF). ACM SIGPLAN International Conference on Certified Programs and Proofs. ACM. 7. doi:10.1145/3167082.
References
^ ab Bright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast.
^ ab Ball, Kevin (June 26, 2018). "How WebAssembly is Accelerating the Future of Web Development". Archived from the original (HTML) on 2019-02-12. Retrieved 2018-10-22.
^ "Is WebAssembly trying to replace JavaScript?".
^ "Launch bug". GitHub / WebAssembly / design. 11 June 2015.
^ Wagner, Luke (14 March 2016). "A WebAssembly Milestone: Experimental Support in Multiple Browsers". Mozilla Hacks.
^ Thompson, Seth (15 March 2016). "Experimental support for WebAssembly in V8". V8 Blog.
^ Zhu, Limin (15 March 2016). "Previewing WebAssembly experiments in Microsoft Edge". Microsoft Edge dev blog.
^ 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.
^ Avram, Abel (2017-05-31). "Google Is to Remove Support for PNaCl". InfoQ. Retrieved 2017-12-22.
^ "WebAssembly: a binary format for the web". ②ality – JavaScript and more. 18 June 2015.
^ ab Krill, Paul (2017-03-06). "WebAssembly is now ready for browsers to use". InfoWorld. Retrieved 2017-12-23.
^ "WebAssembly First Public Working Drafts". W3C. February 15, 2018. Retrieved April 20, 2018.
^ "WebAssembly Core Specification". W3C. February 15, 2018. Retrieved April 20, 2018.
^ "WebAssembly JavaScript Interface". W3C. February 15, 2018. Retrieved April 20, 2018.
^ "WebAssembly Web API". W3C. February 15, 2018. Retrieved April 20, 2018.
^ "WebAssembly support now shipping in all major browsers". The Mozilla Blog. Retrieved 2017-11-21.
^ "Introducing new JavaScript optimizations, WebAssembly, SharedArrayBuffer, and Atomics in EdgeHTML 16". Microsoft Edge Dev Blog. Retrieved 2017-11-21.
^ "WebAssembly". Can I use. Retrieved 2018-12-04.
^ Bright, Peter (2015-06-18). "The Web is getting its bytecode: WebAssembly". Ars Technica. Retrieved 2017-12-23.
^ ab "Awesome WebAssembly Languages". June 26, 2018. Archived from the original (HTML) on 2019-02-12. Retrieved 2019-02-12.
^ ab "WebAssembly High-Level Goals". GitHub / WebAssembly / design. 11 December 2015.
^ Krill, Paul (2017-11-29). "Direct WebAssembly compilation comes to Rust language". InfoWorld. Retrieved 2017-12-24.
^ "Frequently asked questions (FAQ) about Blazor". blazor.net. Retrieved 2018-06-18.
^ Krill, Paul (2017-10-26). "What's next for WebAssembly: GC, threads, debugging". TechWorld. Retrieved 2017-12-24.
^ "Design Rationale". GitHub / WebAssembly / design. 1 October 2016.
^ "Roadmap". WebAssembly. March 2017.
^ jfbastien; rossberg-chromium; kripken; titzer; s3ththompson; sunfishcode; lukewagner; flagxor; enricobacis; c3d; binji; andrewosh (9 March 2017). "Text Format". WebAssembly/design. GitHub.
^ "Folded instructions". GitHub. / WebAssembly / spec
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 this how-to page. For information on reusing text from Wikipedia, please see the terms of use.
External links
Official website- W3C Community Group
- WebAssembly Design
"WebAssembly". MDN Web Docs. – with info on browser compatibility and specifications (WebAssembly JavaScript API)- WebAssembly: What and What Next? (youtube)