A
WebAssembly.Module()
constructor creates a new Module object containing stateless WebAssembly code that has already been compiled by the browser and can be efficiently
shared with Workers
, and instantiated multiple times.
WebAssembly.Module()
constructor function can be called to synchronously compile given WebAssembly binary code. However, the primary way to get a
Module
is through an asynchronous compilation function like
WebAssembly.compile()
.
Important
: Since compilation for large modules can be expensive, developers should only use the
Module()
constructor when synchronous compilation is absolutely required; the asynchronous
WebAssembly.compileStreaming()
method should be used at all other times.
new WebAssembly.Module(bufferSource);
var importObject = {
imports: {
imported_func: function(arg) {
console.log(arg);
}
}
};
function createWasmModule(bytes) {
return new WebAssembly.Module(bytes);
}
fetch('simple.wasm').then(response =>
response.arrayBuffer()
).then(bytes => {
let mod = createWasmModule(bytes);
WebAssembly.instantiate(mod, importObject)
.then(result =>
result.exports.exported_func()
);
})
| 规范 |
|---|
|
WebAssembly JavaScript 接口
The definition of 'WebAssembly.Module()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
见实现注意事项。
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()