mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-27 09:32:01 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
</div></div>
|
||||
<p><strong><code>WebAssembly.compile()</code></strong> 方法编译WebAssembly二进制代码到一个<a href="Reference/Global_Objects/WebAssembly/Module" title="所有 Module 实例继承自 Module() 构造函数的原型对象 —— 修改它会影响所有 Module 实例。"><code>WebAssembly.Module</code></a> 对象。如果在实例化之前有必要去编译一个模块,那么这个方法是有用的(否则,将会使用<a href="Reference/Global_Objects/WebAssembly/instantiate" title="WebAssembly.instantiate() 是编译和实例化 WebAssembly 代码的主要方法. 这个方法有两个重载方式:"><code>WebAssembly.instantiate()</code></a> 方法)</p>
|
||||
<h2 id="语法">语法</h2>
|
||||
<pre class="syntaxbox">Promise<WebAssembly.Module> WebAssembly.compile(bufferSource);</pre>
|
||||
<pre><code class="language-javascript">Promise<WebAssembly.Module> WebAssembly.compile(bufferSource);</code></pre>
|
||||
<h3 id="参数">参数</h3>
|
||||
<dl>
|
||||
<dt><em>bufferSource</em></dt>
|
||||
@@ -19,7 +19,7 @@
|
||||
</ul>
|
||||
<h2 id="例子">例子</h2>
|
||||
<p>下面的例子 (查看GitHub上的 <a class="external" href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/index-compile.html" rel="noopener">index-compile.html</a> 例子, 并且也能 <a class="external" href="https://mdn.github.io/webassembly-examples/js-api-examples/index-compile.html" rel="noopener">查看运行效果</a>) 使用 <code>compile()</code> 方法编译加载进来的 simple.wasm 二进制代码并且使用 <a href="/en-US/docs/Web/API/Worker/postMessage">postMessage()</a> 发送给一个 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API">worker</a>。</p>
|
||||
<pre class="brush: js">var worker = new Worker("wasm_worker.js");
|
||||
<pre><code class="language-javascript">var worker = new Worker("wasm_worker.js");
|
||||
|
||||
fetch('simple.wasm').then(response =>
|
||||
response.arrayBuffer()
|
||||
@@ -27,9 +27,9 @@ fetch('simple.wasm').then(response =>
|
||||
WebAssembly.compile(bytes)
|
||||
).then(mod =>
|
||||
worker.postMessage(mod)
|
||||
);</pre>
|
||||
);</code></pre>
|
||||
<p>在线程中 (查看 <code><a class="external" href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/wasm_worker.js" rel="noopener">wasm_worker.js</a></code>) 我们定义了一个导入对象共模块使用,然后设置了一个事件处理函数来接收主线程发送过来的模块。当模块被接收之后,我们使用<a href="Reference/Global_Objects/WebAssembly/Instantiate" title="WebAssembly.instantiate() 是编译和实例化 WebAssembly 代码的主要方法. 这个方法有两个重载方式:"><code>WebAssembly.Instantiate()</code></a> 方法创建了一个实例,调用从它里面导出的一个方法,接下来展示了我们可以用 <a class="new" href="Reference/Global_Objects/WebAssembly/Module/exports" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>WebAssembly.Module.exports</code></a> 属性来调用模块上返回的可用信息。</p>
|
||||
<pre class="brush: js">var importObject = {
|
||||
<pre><code class="language-javascript">var importObject = {
|
||||
imports: {
|
||||
imported_func: function(arg) {
|
||||
console.log(arg);
|
||||
@@ -47,7 +47,7 @@ onmessage = function(e) {
|
||||
|
||||
var exports = WebAssembly.Module.exports(mod);
|
||||
console.log(exports[0]);
|
||||
};</pre>
|
||||
};</code></pre>
|
||||
<h2 id="Specifications">Specifications</h2>
|
||||
<table class="standard-table">
|
||||
<thead>
|
||||
|
||||
Reference in New Issue
Block a user