WebAssembly.compileStreaming() function compiles a WebAssembly.Module directly from a streamed underlying source.  This function is useful if it is necessary to a compile a module before it can be instantiated (otherwise, the WebAssembly.instantiateStreaming() function should be used).

句法

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

参数

source
A Response object or a promise that will fulfill with one, representing the underlying source of a .wasm module you want to stream and compile.

返回值

A Promise 解析为 WebAssembly.Module object representing the compiled module.

异常

范例

Compile streaming

The following example (see our compile-streaming.html demo on GitHub, and view it live also) directly streams a .wasm module from an underlying source then compiles it to a WebAssembly.Module object. Because the compileStreaming() 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.compileStreaming(fetch('simple.wasm'))
.then(module => WebAssembly.instantiate(module, importObject))
.then(instance => instance.exports.exported_func());
					

The resulting module instance is then instantiated using WebAssembly.instantiate() , and the exported function invoked.

规范

规范
WebAssembly features for web embedding
The definition of 'compileStreaming()' in that specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 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 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

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: