WebAssembly.compile()
function compiles WebAssembly binary code into a
WebAssembly.Module
object. This function is useful if it is necessary to a compile a module before it can be instantiated (otherwise, the
WebAssembly.instantiate()
function should be used).
Promise<WebAssembly.Module> WebAssembly.compile(bufferSource);
A
Promise
解析为
WebAssembly.Module
object representing the compiled module.
bufferSource
is not a
typed array
,
TypeError
is thrown.
WebAssembly.CompileError
.
The following example compiles the loaded simple.wasm byte code using the
compile()
function and then sends it to a
worker
使用
postMessage()
.
var worker = new Worker("wasm_worker.js");
fetch('simple.wasm').then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.compile(bytes)
).then(mod =>
worker.postMessage(mod)
);
注意
: You'll probably want to use
WebAssembly.compileStreaming()
in most cases, as it is more efficient than
compile()
.
| 规范 |
|---|
|
WebAssembly JavaScript 接口
The definition of 'compile()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
见实现注意事项。
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()