WebAssembly.Instance

翻译不完整。 请帮助我们翻译这篇文章!

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

  WebAssembly.Instance 对象本身是有状态的,是 WebAssembly.Module 的一个可执行实例。  实例包含所有的 WebAssembly 导出函数 ,允许从JavaScript 调用 WebAssembly 代码。

WebAssembly.Instance() 构造函数以同步方式实例化一个WebAssembly.Module 对象。 然而, 通常获取实例的方法是通过异步函数WebAssembly.instantiate() .

构造函数

重要: 由于大型模块的实例化代价极高, 开发人员应只在必须同步实例化的时候,才使用Instance();绝大多数情况应该使用异步方法WebAssembly.instantiate() .

var myInstance = new WebAssembly.Instance(module, importObject);

参数

module
要被实例化的 WebAssembly.Module 对象.
importObject 可选
一个包含值的对象,导入到新创建的 实例, 比如函数或 WebAssembly.Memory 对象. There must be one matching property for each declared import of module 否则抛出 WebAssembly.LinkError 异常.

实例化

所有的 Instance 实例继承自Instance() 属性对象— 修改它会影响所有的Instance 实例.

实例属性

Instance.prototype.exports
返回一个包含此 WebAssembly 模块实例所导出的全部成员的 JS 对象,以便 JavaScript 访问和使用这些成员,这个对象是只读的。

规格

规格 状态 描述
WebAssembly JavaScript Interface
Instance
Working Draft Initial draft definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
InstanceChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
Instance() constructorChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
exportsChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

参考