Everipedia Logo
Everipedia is now IQ.wiki - Join the IQ Brainlist and our Discord for early access to editing on the new platform and to participate in the beta testing.
WebAssembly

WebAssembly

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.[2][3][4][5] 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.[6][7]

Wasm does not replace JavaScript; in order to use Wasm in browsers, users may use Emscripten SDK to compile C++ (or any other LLVM-supported language such as D or Rust) source code into a binary file which runs in the same sandbox as regular JavaScript code;[1] Emscripten provides bindings for several commonly used environment interfaces like WebGL; it has access only to an expandable memory and a small number of scalar values. There is no direct Document Object Model (DOM) access; however, it is possible to create proxy functions for this, for example through stdweb,[12] web_sys,[13] and js_sys.[14]

The World Wide Web Consortium (W3C) maintains the standard with contributions from Mozilla, Microsoft, Google, and Apple.[15]

WebAssembly
ParadigmImperative, structured, expression-oriented
Designed byW3C
Developer
  • W3C
  • Mozilla
  • Microsoft
  • Google
  • Apple
First appearedMarch 2017 (2017-03)
Typing disciplineStatic
LicenseApache License 2.0
Filename extensions
  • .wat
  • .wasm
Websitewebassembly.org [70]
Influenced by
  • asm.js
  • PNaCl
img

History

WebAssembly was first announced in 2015,[16] and the first demonstration was executing Unity's Angry Bots in Firefox,[17] Google Chrome,[18] and Microsoft Edge.[19] The precursor technologies were asm.js from Mozilla and Google Native Client,[20][21] and the initial implementation was based on the feature set of asm.js.[22]

In March 2017, the design of the minimum viable product (MVP) was declared to be finished and the preview phase ended.[23] In late September 2017, 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.[24][25][26][27]

Support

In November 2017, Mozilla declared support "in all major browsers"[28] (by now all major on mobile and desktop), after WebAssembly was enabled by default in Edge 16.[29] The support includes mobile web browsers for iOS and Android. As of September 2019, 87.42% of installed browsers (89.39% of desktop browsers and 87.4% of mobile browser) support WebAssembly.[30] But for older browsers, Wasm can be compiled into asm.js by a JavaScript polyfill.[31]

Because WebAssembly executables are precompiled, it is possible to use a variety of programming languages to make them.[32] 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.[33]

Emscripten can compile C and C++ to Wasm[23] using LLVM in the backend.

Its initial aim is to support compilation from C and C++,[34] though support for other source languages such as Rust and .NET languages is also emerging.[35][36][33] After the MVP release, there are plans to support multithreading and garbage collection[37][38] which would make WebAssembly a compilation target for garbage-collected programming languages like C# (supported via Blazor) and F# (supported via Bolero[39] with help of Blazor); Java, Julia,[40][41][42] Ruby,[43] as well as Go.

Security considerations

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.[44][45][46] Thread support was eventually added in October 2018.[47]

Embedding

The general standards provide core specifications for JavaScript and Web embedding.[4]

While WebAssembly was initially designed to enable near-native code execution speed in the web browser, it has been considered valuable outside of such, in more generalized contexts.[48][49]

WebAssembly System Interface (WASI) is an ABI designed by Mozilla intended to define a simpler ABI for WebAssembly that can be used in any platform.[50] There are also a few other proposed ABI APIs.[51][52]

Features

Stack machine

Wasm code is intended to be run on a portable abstract structured virtual stack machine (VM).[53] The VM is designed to be faster to parse than JavaScript, as well as faster to execute and to enable very compact code representation.[34]

Instruction set

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.[54]

Representation

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

C input sourceLinear assembly bytecode
(intermediate representation)
Wasm binary encoding
(hexadecimal bytes)
intfactorial(intn){if(n==0)return1;elsereturnn
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.[57] An example is shown below:

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" [71] . Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation. Association for Computing Machinery: 185–200. doi:10.1145/3062341.3062363 [72] .

  • Watt, Conrad (2018). "Mechanising and Verifying the WebAssembly Specification" [73] (PDF). ACM SIGPLAN International Conference on Certified Programs and Proofs. ACM. 7. doi:10.1145/3167082 [74] .

References

[1]
Citation Linkopenlibrary.orgAccording to official documentation the Emscripten SDK may be used to create .wasm files which then may be executed in web browser. "Developer's Guide - WebAssembly". webassembly.org. Retrieved 10 June 2019. "Compiling a New C/C++ Module to WebAssembly". MDN Web Docs. Retrieved 10 June 2019. "Building to WebAssembly — Emscripten 1.38.33 documentation". emscripten.org. Retrieved 10 June 2019. Even though Emscripten can consume various languages when using Clang some problems may arise. "Emscripting a C library to Wasm | Web". Google Developers. Retrieved 10 June 2019.
Sep 27, 2019, 8:28 PM
[2]
Citation Linkwebassembly.github.io"Introduction — WebAssembly 1.0". webassembly.github.io. Retrieved 18 June 2019. WebAssembly is an open standard...
Sep 27, 2019, 8:28 PM
[3]
Citation Linkwebassembly.github.io"Introduction — WebAssembly 1.0". webassembly.github.io. Retrieved 18 June 2019. WebAssembly is a ... code format
Sep 27, 2019, 8:28 PM
[4]
Citation Linkwebassembly.github.io"Conventions — WebAssembly 1.0". webassembly.github.io. Retrieved 17 May 2019. WebAssembly is a programming language that has multiple concrete representations (its binary format and the text format). Both map to a common structure.
Sep 27, 2019, 8:28 PM
[5]
Citation Linkwebassembly.github.io"Introduction — WebAssembly 1.0". webassembly.github.io. Retrieved 18 June 2019. ... this specification is complemented by additional documents defining interfaces to specific embedding environments such as the Web. These will each define a WebAssembly application programming interface (API) suitable for a given environment.
Sep 27, 2019, 8:28 PM
[6]
Citation Linkwebassembly.github.io"WebAssembly Specification Release 1.0 (Draft, last updated Apr 16, 2019): Introduction". webassembly.org. Retrieved 6 May 2019. Its main goal is to enable high performance applications on the Web, but it does not make any Web-specific assumptions or provide Web-specific features, so it can be employed in other environments as well.
Sep 27, 2019, 8:28 PM
[7]
Citation Linkportal.issn.orgHaas, Andreas; Rossberg, Andreas; Schuff, Derek L.; Titzer, Ben L.; Holman, Michael; Gohman, Dan; Wagner, Luke; Zakai, Alon; Bastien, JF (14 June 2017). "Bringing the Web Up to Speed with WebAssembly". SIGPLAN Not. 52 (6): 185–200. doi:10.1145/3140587.3062363. ISSN 0362-1340. While the Web is the primary motivation for WebAssembly, nothing in its design depends on the Web or a JavaScript environment. It is an open standard specifically designed for embedding in multiple contexts, and we expect that stand-alone implementations will become available in the future.
Sep 27, 2019, 8:28 PM
[8]
Citation Linkopenlibrary.org
Sep 27, 2019, 8:28 PM
[9]
Citation Linkopenlibrary.org
Sep 27, 2019, 8:28 PM
[10]
Citation Linkopenlibrary.org
Sep 27, 2019, 8:28 PM
[11]
Citation Linkopenlibrary.org
Sep 27, 2019, 8:28 PM
[12]
Citation Linkdocs.rs"stdweb - Rust". docs.rs. Retrieved 5 June 2019. The goal of this crate is to provide Rust bindings to the Web APIs and to allow a high degree of interoperability between Rust and JavaScript.
Sep 27, 2019, 8:28 PM
[13]
Citation Linkdocs.rs"web_sys - Rust". docs.rs. Retrieved 5 June 2019. Raw API bindings for Web APIs. This is a procedurally generated crate from browser WebIDL which provides a binding to all APIs that browser provide on the web.
Sep 27, 2019, 8:28 PM
[14]
Citation Linkdocs.rs"js_sys - Rust". docs.rs. Retrieved 5 June 2019. Bindings to JavaScript's standard, built-in objects, including their methods and properties.
Sep 27, 2019, 8:28 PM
[15]
Citation Linkarstechnica.comBright, Peter (18 June 2015). "The Web is getting its bytecode: WebAssembly". Ars Technica. Condé Nast.
Sep 27, 2019, 8:28 PM
[16]
Citation Linkgithub.com"Launch bug". GitHub / WebAssembly / design. 11 June 2015.
Sep 27, 2019, 8:28 PM
[17]
Citation Linkhacks.mozilla.orgWagner, Luke (14 March 2016). "A WebAssembly Milestone: Experimental Support in Multiple Browsers". Mozilla Hacks.
Sep 27, 2019, 8:28 PM
[18]
Citation Linkv8project.blogspot.comThompson, Seth (15 March 2016). "Experimental support for WebAssembly in V8". V8 Blog.
Sep 27, 2019, 8:28 PM
[19]
Citation Linkblogs.windows.comZhu, Limin (15 March 2016). "Previewing WebAssembly experiments in Microsoft Edge". Microsoft Edge dev blog.
Sep 27, 2019, 8:28 PM
[20]
Citation Linktechcrunch.comLardinois, Frederic (17 June 2015). "Google, Microsoft, Mozilla And Others Team Up To Launch WebAssembly, A New Binary Format For The Web". TechCrunch. Retrieved 24 December 2017.
Sep 27, 2019, 8:28 PM