The WebAssembly
JavaScript object acts as the namespace for all WebAssembly-related functionality.
Unlike most other global objects, WebAssembly
is not a constructor (it is not a function object). You can compare it to Math
, which is also a namespace object for mathematical constants and functions, or to Intl
which is the namespace object for internationalization constructors and other language sensitive functions.
Description
The primary uses for the WebAssembly
object are:
Methods
WebAssembly.instantiate()
- The primary API for compiling and instantiating WebAssembly code, returning both a
Module
and its first Instance
.
WebAssembly.instantiateStreaming()
- Compiles and instantiates a WebAssembly module directly from a streamed underlying source, returning both a
Module
and its first Instance
.
WebAssembly.compile()
- Compiles a
WebAssembly.Module
from WebAssembly binary code, leaving instantiation as a separate step.
WebAssembly.compileStreaming()
- compiles a
WebAssembly.Module
directly from a streamed underlying source, leaving instantiation as a separate step.
WebAssembly.validate()
- Validates a given typed array of WebAssembly binary code, returning whether the bytes are valid WebAssembly code (
true
) or not (false
).
Constructors
WebAssembly.Module()
- Creates a new WebAssembly
Module
object.
WebAssembly.Instance()
- Creates a new WebAssembly
Instance
object.
WebAssembly.Memory()
- Creates a new WebAssembly
Memory
object.
WebAssembly.Table()
- Creates a new WebAssembly
Table
object.
WebAssembly.CompileError()
- Creates a new WebAssembly
CompileError
object.
WebAssembly.LinkError()
- Creates a new WebAssembly
LinkError
object.
WebAssembly.RuntimeError()
- Creates a new WebAssembly
RuntimeError
object.
Examples
The following example (see our instantiate-streaming.html demo on GitHub, and view it live also) directly streams a .wasm module from an underlying source then compiles and instantiates it, the promise fulfilling with a ResultObject
. Because the instantiateStreaming()
function accepts a promise for a Response
object, you can directly pass it a WindowOrWorkerGlobalScope.fetch()
call, and it will pass the response into the function when it fulfills.
var importObject = { imports: { imported_func: arg => console.log(arg) } };
WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject)
.then(obj => obj.instance.exports.exported_func());
The ResultObject
's instance member is then accessed, and the contained exported function invoked.
Specifications
Browser compatibility
1. This feature is behind the Experimental JavaScript Features
preference.
2. Disabled in the Firefox 52 Extended Support Release (ESR).
| Desktop | Mobile | Server |
---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | Node.js |
---|
Basic support |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
CompileError |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
Instance |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
LinkError |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
Memory |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
Module |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
RuntimeError |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
Table |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
compile |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
compileStreaming |
Full support
61 |
Full support
16 |
Full support
58 |
No support
No |
Full support
47 |
No support
No |
Full support
61 |
Full support
61 |
No support
No |
Full support
58 |
?
|
No support
No |
No support
No |
No support
No |
---|
instantiate |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
instantiateStreaming |
Full support
61 |
Full support
16 |
Full support
58 |
No support
No |
Full support
47 |
No support
No |
Full support
61 |
Full support
61 |
No support
No |
Full support
58 |
?
|
No support
No |
No support
No |
No support
No |
---|
validate |
Full support
57 |
Full support
16 |
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
No support
No |
Full support
44 |
Full support
11 |
Full support
57 |
Full support
57 |
Full support
Yes-
Full support
Yes
- Disabled This feature is behind the
Experimental JavaScript Features preference.
|
Full support
52-
Full support
52
- Notes Disabled in the Firefox 52 Extended Support Release (ESR).
|
?
|
Full support
11 |
Full support
7.0 |
Full support
8 |
---|
Legend
-
Full support
- Full support
-
No support
- No support
-
Compatibility unknown
- Compatibility unknown
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.
See also
Document Tags and Contributors