diff options
author | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2021-09-07 00:43:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-07 00:43:07 +0900 |
commit | c01e8779a5fed876331e3933e8e19e1daecab11c (patch) | |
tree | be0fe33e2fd3a86e6b4d77197a0954e9b88456ab /files/ja/web/javascript/reference/global_objects/webassembly/table/index.html | |
parent | f07b200c812378523739b7e1e75b7e6cf72fe673 (diff) | |
download | translated-content-c01e8779a5fed876331e3933e8e19e1daecab11c.tar.gz translated-content-c01e8779a5fed876331e3933e8e19e1daecab11c.tar.bz2 translated-content-c01e8779a5fed876331e3933e8e19e1daecab11c.zip |
Global_Objects/WebAssembly/Table 以下の文書を更新 (#2265)
- Markdownに変換
- 2021/08/28 時点の英語版に同期
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/webassembly/table/index.html')
-rw-r--r-- | files/ja/web/javascript/reference/global_objects/webassembly/table/index.html | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/table/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/table/index.html deleted file mode 100644 index 963a942b65..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/table/index.html +++ /dev/null @@ -1,126 +0,0 @@ ---- -title: WebAssembly.Table() -slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table -translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table ---- -<div>{{JSRef}}</div> - -<p><code><strong>WebAssembly.Table()</strong></code> コンストラクタは与えられたサイズと要素の型から <code>Table</code> オブジェクトを生成します。</p> - -<p>これは、配列ライクな構造で表現された WebAssembly テーブルの JavaScript ラッパーオブジェクトです。JavaScript か WebAssembly コード上で生成されたテーブルは JavaScript、WebAssembly の両方からアクセス、変更可能です。</p> - -<div class="note"> -<p><strong>注</strong>: 現在、テーブルには関数の参照のみ格納できます。しかし、将来的に拡張される予定です。</p> -</div> - -<h2 id="構文">構文</h2> - -<pre class="syntaxbox">var myTable = new WebAssembly.Table(tableDescriptor);</pre> - -<h3 id="パラメータ">パラメータ</h3> - -<dl> - <dt><em>tableDescriptor</em></dt> - <dd>以下のメンバーを含むことができるオブジェクト: - <dl> - <dt><em>element</em></dt> - <dd>テーブルに格納する値の型の文字列表現。現在は、<code>"anyfunc"</code> (関数) のみ設定できます。</dd> - <dt><em>initial</em></dt> - <dd>WebAssembly テーブルの初期要素数。</dd> - <dt><em>maximum {{optional_inline}}</em></dt> - <dd>WebAssembly テーブルが拡張できる要素の最大数。</dd> - </dl> - </dd> -</dl> - -<h3 id="例外">例外</h3> - -<ul> - <li>もし <code>tableDescriptor</code> がオブジェクト型でない場合、{{jsxref("TypeError")}} がスローされます。</li> - <li>もし <code>maximum</code> 定義されていて <code>initial</code> よりも小さい場合、{{jsxref("RangeError")}} がスローされます。</li> -</ul> - -<h2 id="Table_インスタンス"><code>Table</code> インスタンス</h2> - -<p>全ての <code>Table</code> インスタンスは <code>Table()</code>コンストラクタの <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/prototype">プロトタイプオブジェクト</a> を継承します。これは全ての <code>Table</code> インスタンスに影響するように変更可能です。</p> - -<h3 id="インスタンスプロパティ">インスタンスプロパティ</h3> - -<dl> - <dt><code>Table.prototype.constructor</code></dt> - <dd>このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは {{jsxref("WebAssembly.Table()")}} コンストラクタです。</dd> - <dt>{{jsxref("Global_Objects/WebAssembly/Table/length","Table.prototype.length")}}</dt> - <dd>テーブルの長さを返します。すなわち、要素数です。</dd> -</dl> - -<h3 id="インスタンスメソッド">インスタンスメソッド</h3> - -<dl> - <dt>{{jsxref("Global_Objects/WebAssembly/Table/get","Table.prototype.get()")}}</dt> - <dd>アクセサ関数。インデックスから格納された要素を取得します。</dd> - <dt>{{jsxref("Global_Objects/WebAssembly/Table/grow","Table.prototype.grow()")}}</dt> - <dd>指定した要素数で Table インスタンスを拡張します。</dd> - <dt>{{jsxref("Global_Objects/WebAssembly/Table/set","Table.prototype.set()")}}</dt> - <dd>指定したインデックスに要素を格納します。</dd> -</dl> - -<h2 id="例">例</h2> - -<p>以下の例 (table2.htmlの <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/table2.html">ソースコード</a> と <a href="https://mdn.github.io/webassembly-examples/js-api-examples/table2.html">動作例</a> を参照) では初期サイズが2の WebAssembly Table インスタンスを生成しています。次に、テーブルの長さと2つのインデックスの内容を表示しています (長さが2で両方の要素が {{jsxref("null")}} であることを確認するために、{{jsxref("WebAssembly/Table/get", "Table.prototype.get()")}} を使って読み込んでいます) 。</p> - -<pre class="brush: js">var tbl = new WebAssembly.Table({initial:2, element:"anyfunc"}); -console.log(tbl.length); // "2" -console.log(tbl.get(0)); // "null" -console.log(tbl.get(1)); // "null"</pre> - -<p>次に、テーブルを含むインポートオブジェクトを作ります:</p> - -<pre class="brush: js">var importObj = { - js: { - tbl:tbl - } -};</pre> - -<p>最後に {{jsxref("WebAssembly.instantiateStreaming()")}} を使用して wasm モジュール (table2.wasm) をロード し、インスタンス化します。table2.wasm モジュールは2の関数を持っていて (1つは42を、もう1つは83を返す) 、インポートされたテーブルの0、1番目に両方の要素が格納されます (<a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/table2.wat">text representation</a>を参照) 。そして、インスタンス化された後、テーブルの長さは2のままです。しかし、今はJSから呼び出し可能な <a href="/en-US/docs/WebAssembly/Exported_functions">エクスポートされたWebAssembly関数</a> が含まれています。</p> - -<pre class="brush: js">WebAssembly.instantiateStreaming(fetch('table2.wasm'), importObject) -.then(function(obj) { - console.log(tbl.length); - console.log(tbl.get(0)()); - console.log(tbl.get(1)()); -});</pre> - -<p>内部の値を表示するためには、参照された関数のアクセサの呼び出しの後に、2つ目の関数呼び出しを含める必要があることに注意して下さい (<code>get(0)</code> ではなく <code>get(0)()</code>)。</p> - -<p>この例では、JavaScript からテーブルを作成してアクセスしていますが、wasm インスタンス内で同じテーブルを参照して呼び出すこともできます。</p> - -<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', '#webassemblytable-objects', 'Table')}}</td> - <td>{{Spec2('WebAssembly JS')}}</td> - <td>初回ドラフト定義。</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> - -<div>{{Compat("javascript.builtins.WebAssembly.Table")}}</div> - -<h2 id="関連情報">関連情報</h2> - -<ul> - <li><a href="/ja/docs/WebAssembly">WebAssembly</a> overview page</li> - <li><a href="https://developer.mozilla.org/ja/docs/WebAssembly/Concepts">WebAssembly のコンセプト</a></li> - <li><a href="https://developer.mozilla.org/ja/docs/WebAssembly/Using_the_JavaScript_API">WebAssembly JavaScript API を使用する</a></li> -</ul> |