语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -2,7 +2,7 @@
<div></div>
<p><strong><code>WebAssembly.compileStreaming()</code></strong> 方法用来从一个流式源中直接编译一个 <a href="Reference/Global_Objects/WebAssembly/Module" title="所有 Module 实例继承自 Module() 构造函数的原型对象 —— 修改它会影响所有 Module 实例。"><code>WebAssembly.Module</code></a>。当模块需要在被实例化前被编译时,这个方法会很有用。如果要从流式源实例化一个模块应采用 <a href="Reference/Global_Objects/WebAssembly/instantiateStreaming" title="WebAssembly.instantiateStreaming() 方法直接从流式底层源编译和实例化WebAssembly模块。这是加载wasm代码一种非常有效的优化方式。"><code>WebAssembly.instantiateStreaming()</code></a> 方法。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">Promise&lt;WebAssembly.Module&gt; WebAssembly.compileStreaming(<em>source</em>);</pre>
<pre><code class="language-javascript">Promise&lt;WebAssembly.Module&gt; WebAssembly.compileStreaming(<em>source</em>);</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><em>source</em></dt>
@@ -17,11 +17,11 @@
</ul>
<h2 id="例子">例子</h2>
<p>下面的例子(在 GitHub 上查看我们的 <a class="external" href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/compile-streaming.html" rel="noopener">compile-streaming.html</a> 示例或者直接<a class="external" href="https://mdn.github.io/webassembly-examples/js-api-examples/compile-streaming.html" rel="noopener">在线预览</a>)直接从流式源传输一个 .wasm 模块然后将其编译为一个 <a href="Reference/Global_Objects/WebAssembly/Module" title="所有 Module 实例继承自 Module() 构造函数的原型对象 —— 修改它会影响所有 Module 实例。"><code>WebAssembly.Module</code></a> 对象。因为 <code>compileStreaming()</code> 方法可以接受一个结果为  <a href="/zh-CN/docs/Web/API/Response" title="Fetch API 的Response接口呈现了对一次请求的响应数据"><code>Response</code></a> 对象的 promise因此你可以直接用 <a href="/zh-CN/docs/Web/API/WindowOrWorkerGlobalScope/fetch" title="位于 WorkerOrGlobalScope 这一个 mixin 中的 fetch() 方法用于发起获取资源的请求。它返回一个 promise这个 promise 会在请求响应后被 resolve并传回 Response 对象。"><code>WindowOrWorkerGlobalScope.fetch()</code></a> 的调用结果来调用该方法。</p>
<pre class="brush: js">var importObject = { imports: { imported_func: arg =&gt; console.log(arg) } };
<pre><code class="language-javascript">var importObject = { imports: { imported_func: arg =&gt; console.log(arg) } };
WebAssembly.compileStreaming(fetch('simple.wasm'))
.then(module =&gt; WebAssembly.instantiate(module, importObject))
.then(instance =&gt; instance.exports.exported_func());</pre>
.then(instance =&gt; instance.exports.exported_func());</code></pre>
<p>得到的 module 实例接下来通过 <a href="Reference/Global_Objects/WebAssembly/instantiate" title="WebAssembly.instantiate() 是编译和实例化 WebAssembly 代码的主要方法.  这个方法有两个重载方式:"><code>WebAssembly.instantiate()</code></a> 方法被实例化了,然后调用模块导出的函数。</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">