The WebAssembly.validate() function validates a given typed array of WebAssembly binary code, returning whether the bytes form a valid wasm module (true) or not (false).

Syntax

WebAssembly.validate(bufferSource);

Parameters

bufferSource
A typed array or ArrayBuffer containing WebAssembly binary code to be validated.

Return value

A boolean that specifies whether bufferSource is valid wasm code (true) or not (false).

Exceptions

If bufferSource is not a typed array or ArrayBuffer, a TypeError is thrown.

Examples

The following example (see the validate.html source code, and see it live too) fetches a .wasm module and converts it into a typed array. The validate() method is then used to check whether the module is valid.

fetch('simple.wasm').then(response =>
  response.arrayBuffer()
).then(function(bytes) {
  var valid = WebAssembly.validate(bytes);
  console.log("The given bytes are "
    + (valid ? "" : "not ") + "a valid wasm module");
});

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Edge Mobile Full support Yes
Disabled
Full support Yes
Disabled
Disabled This feature is behind the Experimental JavaScript Features preference.
Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android ? Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0

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

Contributors to this page: chrisdavidmills, fscholz, lukewagner
Last updated by: chrisdavidmills,