diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/webassembly/module/customsections | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/webassembly/module/customsections')
-rw-r--r-- | files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html new file mode 100644 index 0000000000..757c3e33e4 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html @@ -0,0 +1,144 @@ +--- +title: WebAssembly.Module.customSections() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections +--- +<div>{{JSRef}}{{SeeCompatTable}}</div> + +<p><strong><code>WebAssembly.customSections()</code></strong> 関数はモジュールと文字列名を指定して、全てのカスタムセクションのコンテンツのコピーを返します。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox">var custSec = WebAssembly.Module.customSections(<em>module</em>, <em>sectionName</em>);</pre> + +<h3 id="パラメータ">パラメータ</h3> + +<dl> + <dt><em>module</em></dt> + <dd>カスタムセクションが考慮されている {{jsxref("WebAssembly.Module")}} オブジェクト。</dd> + <dt><em>sectionName</em></dt> + <dd>目的のカスタムセクションの文字列名。</dd> +</dl> + +<h3 id="戻り値">戻り値</h3> + +<p><code>sectionName</code> にマッチした全てのカスタムセクションの {{domxref("ArrayBuffer")}} コピーの配列 (もしかしたら空の場合もあります) 。</p> + +<h3 id="例外">例外</h3> + +<p>もし <code>module</code> が {{jsxref("WebAssembly.Module")}} オブジェクトインスタンスでない場合、{{jsxref("TypeError")}} がスローされます。</p> + +<h2 id="カスタムセクション">カスタムセクション</h2> + +<p>wasm モジュールは一連の <strong>セクション</strong> で構成されています。これらのセクションのほとんどは wasm の仕様によって完全に指定、バリデーションされますが、バリデーション中に無視されスキップされる <strong>カスタムセクション</strong> をモジュールに含めることができます (通常のセクション("既知のセクション")とカスタムセクションを区別するための情報は <a href="https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#high-level-structure">高レベルの構造</a> を読んでください)。</p> + +<p>これにより開発者は他の目的のために wasm モジュール内にカスタムデータを含めることができます。例えば、開発者がモジュール内の全ての関数とローカル変数に名前を付けられる (ネイティブビルドにおける "シンボル" のようなもの) <a href="https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section">ネームカスタムセクション</a> のようなものがあります 。</p> + +<p>Note that the WebAssembly テキストフォーマットには現在新しいカスタムセクションのための構文の仕様がありません。しかし、テキストフォーマットから .wasm に変換するときに wasm にネームセクションを追加することができます。<a href="https://github.com/webassembly/wabt">wabt tool</a> の一部である wast2wasm コマンドで <code>--debug-names</code> オプションを指定することができます。これを指定することにより、ネームカスタムセクションを持つ .wasm に変換することができます:</p> + +<pre class="brush: bash">wast2wasm simple-name-section.was -o simple-name-section.wasm --debug-names</pre> + +<h2 id="例">例</h2> + +<p>次の例では(custom-section.html の <a href="https://github.com/mdn/webassembly-examples/blob/master/other-examples/custom-section.html">ソース</a> と <a href="https://mdn.github.io/webassembly-examples/other-examples/custom-section.html">動作例</a> をご確認ください) 、ロードした section.wasm バイトコードをコンパイルしています。</p> + +<p>それから、<code>WebAssembly.Module.customSections</code> を使用して <code>length</code> が0より大きいかチェックして、モジュールに "name" カスタムセクションが含まれているかどうかチェックします。この例では "name" カスタムセクションが存在するため、<code>ArrayBuffer</code> オブジェクトが返されます。</p> + +<pre class="brush: js">fetch('simple-name-section.wasm').then(response => + response.arrayBuffer() +).then(bytes => + WebAssembly.compile(bytes) +).then(function(mod) { + var nameSections = WebAssembly.Module.customSections(mod, "name"); + if (nameSections.length != 0) { + console.log("Module contains a name section"); + console.log(nameSections[0]); + }; +});</pre> + +<h2 id="仕様">仕様</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様</th> + <th scope="col">策定状況</th> + <th scope="col">コメント</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('WebAssembly JS', '#webassemblymodulecustomsections', 'customSections()')}}</td> + <td>{{Spec2('WebAssembly JS')}}</td> + <td>初回ドラフト定義。</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>基本サポート</td> + <td>57</td> + <td>15<sup>[2]</sup></td> + <td>{{CompatGeckoDesktop(52)}}<sup>[1]</sup></td> + <td>{{CompatNo}}</td> + <td>44</td> + <td>11</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome for Android</th> + <th>Android Webview</th> + <th>Edge Mobile</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>基本サポート</td> + <td>57</td> + <td>57</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile(52)}}<sup>[1]</sup></td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>11</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] WebAssemblyはFirefox 52+で有効です。<a href="https://www.mozilla.org/en-US/firefox/organizations/">Firefox 52 Extended Support Release</a> (ESR.)では無効化されています。</p> + +<p>[2] 現在、“Experimental JavaScript Features” フラグを付けることでサポートされます。詳細については <a href="https://blogs.windows.com/msedgedev/2017/04/20/improved-javascript-performance-webassembly-shared-memory/">このブログ記事</a> を参照してください。</p> + +<h2 id="関連情報">関連情報</h2> + +<ul> + <li><a href="/ja/docs/WebAssembly">WebAssembly</a> overview page</li> + <li><a href="/ja/docs/WebAssembly/Concepts">WebAssembly のコンセプト</a></li> + <li><a href="/ja/docs/WebAssembly/Using_the_JavaScript_API">WebAssembly JavaScript API を使用する</a></li> +</ul> |