WebAssembly.Instance.prototype.exports

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

Examples

After fetching some WebAssembly bytecode using fetch, we compile and instantiate the module using the WebAssembly.instantiate() 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);
    }
  }
};

fetch('simple.wasm').then(response =>
  response.arrayBuffer()
).then(bytes =>
  WebAssembly.instantiate(bytes, importObject)
).then(result =>
  result.instance.exports.exported_func()
);

Note: See index.html on GitHub (view it live also) for a similar example that makes use of our fetchAndInstantiate() library function.

Specifications

Specification Status Comment
WebAssembly JavaScript API
The definition of 'WebAssembly.Instance objects' in that specification.
Draft Initial draft definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support5716522 No4411
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic support5757 Yes1522 No ?11

1. This feature is behind the Experimental JavaScript Features preference.

2. Disabled in the Firefox 52 Extended Support Release (ESR).

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, fscholz
 Last updated by: chrisdavidmills,