WebAssembly
JavaScript 对象充当名称空间为所有
WebAssembly
相关功能。在该规范中的 load 定义。
不像大多数其它全局对象,
WebAssembly
不是构造函数 (它不是函数对象)。可以比较它与
Math
, which is also a namespace object for mathematical constants and functions, or to
Intl
which is the namespace object for internationalization constructors and other language-sensitive functions.
The primary uses for the
WebAssembly
object are:
WebAssembly.instantiate()
函数。
WebAssembly.Memory()
/
WebAssembly.Table()
构造函数。
WebAssembly.CompileError()
/
WebAssembly.LinkError()
/
WebAssembly.RuntimeError()
构造函数。
WebAssembly.CompileError()
Indicates an error during WebAssembly decoding or validation.
WebAssembly.Global()
WebAssembly.Module
instances. This allows dynamic linking of multiple modules.
WebAssembly.Instance()
WebAssembly.LinkError()
WebAssembly.Memory()
buffer
property is a resizable
ArrayBuffer
that holds the raw bytes of memory accessed by a WebAssembly
Instance
.
WebAssembly.Module()
WebAssembly.RuntimeError()
WebAssembly.Table()
An array-like structure representing a WebAssembly Table, which stores function references.
WebAssembly.instantiate()
Module
and its first
Instance
.
WebAssembly.instantiateStreaming()
Module
and its first
Instance
.
WebAssembly.compile()
WebAssembly.Module
from WebAssembly binary code, leaving instantiation as a separate step.
WebAssembly.compileStreaming()
WebAssembly.Module
directly from a streamed underlying source, leaving instantiation as a separate step.
WebAssembly.validate()
true
) or not (
false
).
The following example (see our
instantiate-streaming.html
demo on GitHub, and
view it live
also) directly streams a .wasm module from an underlying source then compiles and instantiates it, the promise fulfilling with a
ResultObject
. Because the
instantiateStreaming()
function accepts a promise for a
Response
object, you can directly pass it a
WindowOrWorkerGlobalScope.fetch()
call, and it will pass the response into the function when it fulfills.
var importObject = { imports: { imported_func: arg => console.log(arg) } };
WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject)
.then(obj => obj.instance.exports.exported_func());
ResultObject
's instance member is then accessed, and the contained exported function invoked.
| 规范 |
|---|
|
WebAssembly JavaScript 接口
在该规范中的 WebAssembly 定义。 |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WebAssembly
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
CompileError
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
Global
|
Chrome 69 | Edge No | Firefox 62 | IE No | Opera No | Safari No | WebView Android 69 | Chrome Android 69 | Firefox Android 62 | Opera Android No | Safari iOS No | Samsung Internet Android 10.0 | nodejs No |
Instance
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
LinkError
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
Memory
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
Module
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
RuntimeError
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
Table
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
compile
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
compileStreaming
|
Chrome 61 | Edge 16 | Firefox 58 | IE No | Opera 47 | Safari No | WebView Android 61 | Chrome Android 61 | Firefox Android 58 | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 | nodejs No |
instantiate
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
instantiateStreaming
|
Chrome 61 | Edge 16 | Firefox 58 | IE No | Opera 47 | Safari No | WebView Android 61 | Chrome Android 61 | Firefox Android 58 | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 | nodejs No |
validate
|
Chrome 57 | Edge 16 |
Firefox
52
|
IE No | Opera 44 | Safari 11 | WebView Android 57 | Chrome Android 57 |
Firefox Android
52
|
Opera Android 43 | Safari iOS 11 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
完整支持
不支持
见实现注意事项。
WebAssembly
WebAssembly.Module
WebAssembly.Global
WebAssembly.Instance
WebAssembly.Memory
WebAssembly.Table
WebAssembly.CompileError
WebAssembly.LinkError
WebAssembly.RuntimeError
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()