W3cubDocs

/JavaScript

WebAssembly.module

A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser and can be efficiently shared with Workers, and instantiated multiple times. To instantiate the module, call the secondary overload of WebAssembly.instantiate(). The WebAssembly.Module() constructor function can be called to synchronously compile given WebAssembly binary code. However, the primary way to get a Module is through an asynchronous compilation function like WebAssembly.compile().

Constructor Syntax

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

var myModule = new WebAssembly.Module(bufferSource);

Parameters

bufferSource
A typed array or ArrayBuffer containing the binary code of the .wasm module you want to compile.

Function Properties of the Module Constructor

WebAssembly.Module.customSections()
Given a Module and string, returns a copy of the contents of all custom sections in the module with the given string name.
WebAssembly.Module.exports()
Given a Module, returns an array containing descriptions of all the declared exports.
WebAssembly.Module.imports()
Given a Module, returns an array containing descriptions of all the declared imports.

Module instances

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

Instance properties

Module.prototype.constructor
Returns the function that created this object's instance. By default this is the WebAssembly.Module() constructor.
Module.prototype[@@toStringTag]
The initial value of the @@toStringTag property is the String value "WebAssembly.Module".

Instance methods

Module instances have no default methods of their own.

Specifications

Specification Status Comment
WebAssembly JavaScript Interface
The definition of 'WebAssembly.Module()' in that specification.
Working Draft Initial draft definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 57 16 52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
No 44 11
customSections 57 16 52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
No 44 11
exports 57 16 52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
No 44 11
imports 57 16 52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
No 44 11
prototype 57 16 52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
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
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
? 11 7.0
customSections 57 57 Yes
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
? 11 7.0
exports 57 57 Yes
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
? 11 7.0
imports 57 57 Yes
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
? 11 7.0
prototype 57 57 Yes
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
52
52
Disabled in the Firefox 52 Extended Support Release (ESR).
? 11 7.0
Server
Node.js
Basic support 8.0.0
customSections 8.0.0
exports 8.0.0
imports 8.0.0
prototype 8.0.0

See also

© 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/Module