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
).
WebAssembly.validate(bufferSource);
bufferSource
A boolean that specifies whether bufferSource
is valid wasm code (true
) or not (false
).
If bufferSource
is not a typed array or ArrayBuffer, a TypeError
is thrown.
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"); });
Specification | Status | Comment |
---|---|---|
WebAssembly JavaScript Interface The definition of 'validate()' in that specification. | Working Draft | Initial draft definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 57 | 16 | 52
|
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
|
52
|
? | 11 | 7.0 |
Server | |
---|---|
Node.js | |
Basic support | 8.0.0 |
© 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/validate