A WebAssembly.Instance object is a stateful, executable instance of a WebAssembly.ModuleInstance objects contain all the Exported WebAssembly functions that allow calling into WebAssembly code from JavaScript.

The WebAssembly.Instance() constructor function can be called to synchronously instantiate a given WebAssembly.Module object. However, the primary way to get an Instance is through the asynchronous WebAssembly.instantiate() function.

Constructor Syntax

Important: Since instantiation for large modules can be expensive, developers should only use the Instance() constructor when synchronous instantiation is absolutely required; the asynchronous WebAssembly.instantiate() method should be used at all other times.

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

Parameters

module
The WebAssembly.Module object to be instantiated.
importObject Optional
An object containing the values to be imported into the newly-created Instance, such as functions or WebAssembly.Memory objects. There must be one matching property for each declared import of module or else a WebAssembly.LinkError is thrown.

Instance instances

All Instance instances inherit from the Instance() constructor's prototype object — this can be modified to affect all Instance instances.

Instance properties

Instance.prototype.constructor
Returns the function that created this object's instance. By default this is the WebAssembly.Instance() constructor.
Instance.prototype.exports Read only
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 methods

None.

Specifications

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

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support5716522 No4411
exports5716522 No4411
prototype5716522 No4411
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic support5757 Yes1522 No ?11
exports5757 Yes1522 No ?11
prototype5757 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

 Last updated by: chrisdavidmills,