A WebAssembly.Instance object is a stateful, executable instance of a WebAssembly.Module. Instance 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.instantiateStreaming() 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.instantiateStreaming() method should be used at all other times.
var myInstance = new WebAssembly.Instance(module, importObject);
Parameters
- module
- The
WebAssembly.Moduleobject to be instantiated. - importObject Optional
- An object containing the values to be imported into the newly-created
Instance, such as functions orWebAssembly.Memoryobjects. There must be one matching property for each declared import ofmoduleor 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.exportsRead 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 Interface The definition of 'Instance' in that specification. |
Working Draft | Initial draft definition. |
Browser compatibility
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Instance | Chrome Full support 57 | Edge Full support 16 | Firefox
Full support
52
| IE No support No | Opera Full support 44 | Safari Full support 11 | WebView Android Full support 57 | Chrome Android Full support 57 | Firefox Android
Full support
52
| Opera Android ? | Safari iOS Full support 11 | Samsung Internet Android Full support 7.0 | nodejs Full support 8.0.0 |
exports | Chrome Full support 57 | Edge Full support 16 | Firefox
Full support
52
| IE No support No | Opera Full support 44 | Safari Full support 11 | WebView Android Full support 57 | Chrome Android Full support 57 | Firefox Android
Full support
52
| Opera Android ? | Safari iOS Full support 11 | Samsung Internet Android Full support 7.0 | nodejs Full support 8.0.0 |
prototype | Chrome Full support 57 | Edge Full support 16 | Firefox
Full support
52
| IE No support No | Opera Full support 44 | Safari Full support 11 | WebView Android Full support 57 | Chrome Android Full support 57 | Firefox Android
Full support
52
| Opera Android ? | Safari iOS Full support 11 | Samsung Internet Android Full support 7.0 | nodejs Full support 8.0.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.
- See implementation notes.