WebAssembly.validate() - JavaScript 编辑
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
Using validate
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 |
---|
WebAssembly JavaScript Interface The definition of 'validate()' in that specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论