From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/webassembly/validate/index.html | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/webassembly/validate') diff --git a/files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html b/files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html new file mode 100644 index 0000000000..7d44cc216b --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html @@ -0,0 +1,75 @@ +--- +title: WebAssembly.validate() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate +--- +
{{JSRef}}
+ +

WebAssembly.validate() 方法用于验证包含 WebAssembly 二进制码的一个 typed array 是否合法,返回 true 如果这些字节能构成一个合法的 wasm 模块,否则返回 false

+ +

语法

+ +
WebAssembly.validate(bufferSource);
+ +

参数

+ +
+
bufferSource
+
一个包含 WebAssembly 二进制码的 typed array 或 ArrayBuffer
+
+ +

返回值

+ +

一个布尔值,用来表示给定的 bufferSource 是合法 wasm 代码(true)或者不是(false)。

+ +

异常

+ +

如果给定的 bufferSource 不是 typed array 或 ArrayBuffer 类型,将会抛出 {{jsxref("TypeError")}} 异常。

+ +

例子

+ +

下面的例子(查看 validate.html 源代码,或者在线预览)通过 fetch 获取了一个 .wasm 模块并将其转换为一个 typed array。接下来用 validate() 方法来验证这个模块是否合法。

+ +
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

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('WebAssembly JS', '#webassemblyvalidate', 'validate()')}}{{Spec2('WebAssembly JS')}}Initial draft definition.
+ +

Browser compatibility

+ +
+ + +

{{Compat("javascript.builtins.WebAssembly.validate")}}

+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf