WebAssembly.compileStreaming()

WebAssembly.compileStreaming() 方法用来从一个流式源中直接编译一个 WebAssembly.instantiateStreaming() 方法。

语法

Promise<WebAssembly.Module> WebAssembly.compileStreaming(source);

参数

source
一个 Response 对象或一个会履行(fulfill)它的 promise,用来表示你想编译的 .wasm 模块的流式源。

返回值

一个会被解决(resolve)为编译后的 WebAssembly.Module 对象的 Promise

异常

例子

下面的例子(在 GitHub 上查看我们的 compile-streaming.html 示例或者直接在线预览)直接从流式源传输一个 .wasm 模块然后将其编译为一个 WindowOrWorkerGlobalScope.fetch() 的调用结果来调用该方法。

var importObject = { imports: { imported_func: arg => console.log(arg) } };

WebAssembly.compileStreaming(fetch('simple.wasm'))
.then(module => WebAssembly.instantiate(module, importObject))
.then(instance => instance.exports.exported_func());

得到的 module 实例接下来通过 WebAssembly.instantiate() 方法被实例化了,然后调用模块导出的函数。

Specifications

Specification Status Comment
WebAssembly features for web embedding
compileStreaming()
Draft Initial draft definition.

Browser compatibility

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
compileStreaming Chrome Full support 61 Edge Full support 16 Firefox Full support 58 IE No support No Opera Full support 47 Safari No support No WebView Android Full support 61 Chrome Android Full support 61 Firefox Android Full support 58 Opera Android ? Safari iOS No support No Samsung Internet Android Full support 8.0 nodejs No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also