WebAssembly是一种运行在现代浏览器里的新型代码 - 它是一种低级的类汇编语言并具有紧凑的二进制格式,这使得它可以以接近原生的性能运行,并且通过提供编译目标来让类似C/C++之类的语言可以编译到WebAssembly从而可以在web端运行。它也被设计成可以和JavaScript共同运行,允许2者一同完成工作。

In a nutshell

WebAssembly has huge implications for the web platform — it will provide a way to run code written in multiple languages on the web at near native speed, with client apps running on the web that previously couldn’t have done so.

WebAssembly is designed to complement and run alongside JavaScript — using the WebAssembly JavaScript APIs, you can load WebAssembly modules into a JavaScript app and share functionality between the two. This allows you to take advantage of WebAssembly's performance and power and JavaScript's expressiveness and flexibility in the same apps, even if you don't know how to write WebAssembly code.

And what's even better is that it is being developed as a web standard via the W3C WebAssembly Community Group with active participation from all major browser vendors.


WebAssembly concepts
Get started by reading the high-level concepts behind WebAssembly — what it is, why it is so useful, how it fits into the web platform (and beyond), and how to use it.
Compiling from C/C++ to WebAssembly
When you’ve written code in C/C++, you can then compile it into .wasm using a tool like Emscripten. Let’s look at how it works.
Loading and running WebAssembly code
After you have a .wasm, this article covers how to fetch, compile and instantiate it, combining the WebAssembly JavaScript API with the Fetch or XHR APIs.
Caching compiled WebAssembly modules
Caching large WebAssembly modules on the client is useful for improving app startup performance. This article explains how to use this using IndexedDB.
Using the WebAssembly JavaScript API
Once you've loaded a .wasm module, you'll want to use it. In this article we show you how to use WebAssembly via the WebAssembly JavaScript API.
Exported WebAssembly functions
Exported WebAssembly functions are the JavaScript reflections of WebAssembly functions and allow calling WebAssembly code from JavaScript. This article describes what they are.
Understanding WebAssembly text format
This article explains the wasm text format. This is the low-level textual representation of a .wasm module shown in browser developer tools when debugging.
Converting WebAssembly text format to wasm
This article provides a guide on how to convert a WebAssembly module written in the text format into a .wasm binary.

API reference

This object acts as the namespace for all WebAssembly related functionality.
A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser and can be efficiently shared with Workers, cached in IndexedDB, and instantiated multiple times.
A WebAssembly.Instance object is a stateful, executable instance of a ModuleInstance objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.
The WebAssembly.instantiate() function is the primary API for compiling and instantiating WebAssembly code, returning both a Module and its first Instance.
A WebAssembly.Memory object is a resizable ArrayBuffer that holds the raw bytes of memory accessed by an Instance.
A WebAssembly.Table object is a resizable typed array of opaque values, like function references, that are accessed by an Instance.
Creates a new WebAssembly CompileError object.
Creates a new WebAssembly LinkError object.
Creates a new WebAssembly RuntimeError object.



Specification Status Comment
Web Assembly JavaScript API Draft Initial draft definition of the JavaScript API.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 57 未实现 52 (52)[1] 未实现 (Yes) 未实现
Feature Chrome for Android Android Webview Edge Mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 57 57 未实现 52.0 (52)[1] 未实现 未实现 未实现

[1] WebAssembly is enabled in Firefox 52+, although disabled in the Firefox 52 Extended Support Release (ESR.)

See also


 此页面的贡献者: disoul
 最后编辑者: disoul,