Our volunteers haven't translated this article into Bahasa Indonesia yet. Join us and help get the job done!
You can also read the article in English (US).

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.


The primary uses for the WebAssembly object are:


The primary API for compiling and instantiating WebAssembly code, returning both a Module and its first Instance.
Compiles and instantiates a WebAssembly module directly from a streamed underlying source, returning both a Module and its first Instance.
Compiles a WebAssembly.Module from WebAssembly binary code, leaving instantiation as a separate step.
compiles a WebAssembly.Module directly from a streamed underlying source, leaving instantiation as a separate step.
Validates a given typed array of WebAssembly binary code, returning whether the bytes are valid WebAssembly code (true) or not (false).


Creates a new WebAssembly Module object.
Creates a new WebAssembly Instance object.
Creates a new WebAssembly Memory object.
Creates a new WebAssembly Table object.
Creates a new WebAssembly CompileError object.
Creates a new WebAssembly LinkError object.
Creates a new WebAssembly RuntimeError object.


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.


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

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support5716522 No4411
CompileError5716522 No4411
Instance5716522 No4411
LinkError5716522 No4411
Memory5716522 No4411
Module5716522 No4411
RuntimeError5716522 No4411
Table5716522 No4411
compile5716522 No4411
compileStreaming61 No58 No47 ?
instantiate5716522 No4411
instantiateStreaming61 No58 No47 ?
validate5716522 No4411
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5757 Yes1522 ?11 ?
CompileError5757 Yes1522 ?11 ?
Instance5757 Yes1522 ?11 ?
LinkError5757 Yes1522 ?11 ?
Memory5757 Yes1522 ?11 ?
Module5757 Yes1522 ?11 ?
RuntimeError5757 Yes1522 ?11 ?
Table5757 Yes1522 ?11 ?
compile5757 Yes1522 ?11 ?
compileStreaming6161 No58 ? ? ?
instantiate5757 Yes1522 ?11 ?
instantiateStreaming6161 No58 ? ? ?
validate5757 Yes1522 ?11 ?

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

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

See also

Tag Dokumen dan Kontributor

 Kontributor untuk laman ini: chrisdavidmills, fscholz, emilbayes, apurv-pandey, lukewagner
 Terakhir diperbarui oleh: chrisdavidmills,