aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/webassembly/validate/index.html75
1 files changed, 75 insertions, 0 deletions
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
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>WebAssembly.validate()</code></strong> 方法用于验证包含 WebAssembly 二进制码的一个 <a href="/en-US/docs/Web/JavaScript/Typed_arrays">typed array</a> 是否合法,返回 <code>true</code> 如果这些字节能构成一个合法的 wasm 模块,否则返回 <code>false</code>。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">WebAssembly.validate(bufferSource);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>bufferSource</code></dt>
+ <dd>一个包含 WebAssembly 二进制码的 <a href="/en-US/docs/Web/JavaScript/Typed_arrays">typed array</a> 或 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a>。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一个布尔值,用来表示给定的 <code>bufferSource</code> 是合法 wasm 代码(<code>true</code>)或者不是(<code>false</code>)。</p>
+
+<h3 id="异常">异常</h3>
+
+<p>如果给定的 <code>bufferSource</code> 不是 <a href="/en-US/docs/Web/JavaScript/Typed_arrays">typed array</a> 或 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer">ArrayBuffer</a> 类型,将会抛出 {{jsxref("TypeError")}} 异常。</p>
+
+<h2 id="例子">例子</h2>
+
+<p>下面的例子(查看 validate.html <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/validate.html">源代码</a>,或者<a href="https://mdn.github.io/webassembly-examples/js-api-examples/validate.html">在线预览</a>)通过 <code>fetch</code> 获取了一个 .wasm 模块并将其转换为一个 typed array。接下来用 <code>validate()</code> 方法来验证这个模块是否合法。</p>
+
+<pre class="brush: js">fetch('simple.wasm').then(response =&gt;
+  response.arrayBuffer()
+).then(function(bytes) {
+  var valid = WebAssembly.validate(bytes);
+  console.log("The given bytes are "
+ + (valid ? "" : "not ") + "a valid wasm module");
+});
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('WebAssembly JS', '#webassemblyvalidate', 'validate()')}}</td>
+ <td>{{Spec2('WebAssembly JS')}}</td>
+ <td>Initial draft definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
+
+<div>
+
+
+<p>{{Compat("javascript.builtins.WebAssembly.validate")}}</p>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/WebAssembly">WebAssembly</a> overview page</li>
+ <li><a href="/en-US/docs/WebAssembly/Concepts">WebAssembly concepts</a></li>
+ <li><a href="/en-US/docs/WebAssembly/Using_the_JavaScript_API">Using the WebAssembly JavaScript API</a></li>
+</ul>