The exports
readonly property of the WebAssembly.Instance
object prototype returns an object containing as its members all the functions exported from the WebAssembly module instance, to allow them to be accessed and used by JavaScript.
instance.exports
After fetching some WebAssembly bytecode using fetch, we compile and instantiate the module using the WebAssembly.instantiateStreaming()
function, importing a JavaScript function into the WebAssembly Module in the process. We then call an Exported WebAssembly function that is exported by the Instance
.
var importObject = { imports: { imported_func: function(arg) { console.log(arg); } } }; WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject) .then(obj => obj.instance.exports.exported_func());
Note: You can also find this example as instantiate-streaming.html on GitHub (view it live also).
Specification | Status | Comment |
---|---|---|
WebAssembly JavaScript Interface The definition of 'WebAssembly.Instance objects' in that specification. | Working Draft | Initial draft definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 57 | 16 | 52
|
No | 44 | 11 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 57 | 57 | Yes
|
52
|
? | 11 | 7.0 |
Server | |
---|---|
Node.js | |
Basic support | 8.0.0 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports