diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
commit | da78a9e329e272dedb2400b79a3bdeebff387d47 (patch) | |
tree | e6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/ko/web/javascript/reference/global_objects/webassembly/table | |
parent | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff) | |
download | translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2 translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip |
initial commit
Diffstat (limited to 'files/ko/web/javascript/reference/global_objects/webassembly/table')
-rw-r--r-- | files/ko/web/javascript/reference/global_objects/webassembly/table/index.html | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/files/ko/web/javascript/reference/global_objects/webassembly/table/index.html b/files/ko/web/javascript/reference/global_objects/webassembly/table/index.html new file mode 100644 index 0000000000..9d86fe40c7 --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/webassembly/table/index.html @@ -0,0 +1,130 @@ +--- +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 또는 WebAssembly 코드로 작성된 테이블은 JavaScript 및 WebAssembly에서 액세스 및 변경할 수 있습니다.</p> + +<div class="note"> +<p><strong>Note</strong>: 테이블은 현재 function references만 저장할 수 있지만 나중에 확장 될 수 있습니다.</p> +</div> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">var myTable = new WebAssembly.Table(tableDescriptor);</pre> + +<h3 id="Parameters">Parameters</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="Exceptions">Exceptions</h3> + +<ul> + <li><code>tableDescriptor</code>가 object 유형이 아닌 경우 {{jsxref ( "TypeError")}}가 발생합니다.</li> + <li><code>maximum</code>이 지정되고 initial보다 작은 경우 {{jsxref ( "RangeError")}}가 발생합니다.</li> +</ul> + +<h2 id="Table_instances"><code>Table</code> instances</h2> + +<p>모든 <code>Table</code> 인스턴스는 <code>Table()</code>생성자의 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/prototype">prototype object</a>에서 상속받습니다.이 인스턴스는 모든 <code>Table</code> 인스턴스에 적용되도록 수정할 수 있습니다.</p> + +<h3 id="Instance_properties">Instance properties</h3> + +<dl> + <dt><code>Table.prototype.constructor</code></dt> + <dd>이 객체의 인스턴스를 생성 한 함수를 돌려줍니다. 기본적으로 이것은 {{jsxref("WebAssembly.Table()")}} 생성자입니다.</dd> + <dt>{{jsxref("WebAssembly/Table/length","Table.prototype.length")}}</dt> + <dd>테이블의 길이, 즉 요소의 수를 돌려줍니다.</dd> +</dl> + +<h3 id="Instance_methods">Instance methods</h3> + +<dl> + <dt>{{jsxref("WebAssembly/Table/get","Table.prototype.get()")}}</dt> + <dd>접근 자 함수 - 주어진 색인에 저장된 요소를 가져옵니다.</dd> + <dt>{{jsxref("WebAssembly/Table/grow","Table.prototype.grow()")}}</dt> + <dd>지정된 요소 수만큼 Table 인스턴스의 크기를 늘립니다.</dd> + <dt>{{jsxref("WebAssembly/Table/set","Table.prototype.set()")}}</dt> + <dd>지정된 인덱스에 격납되어있는 요소를, 지정된 값으로 설정합니다.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<p>다음 예제 (table2.html <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/table2.html">source code</a> 및 <a href="https://mdn.github.io/webassembly-examples/js-api-examples/table2.html">live version</a> 참조)는 초기 크기가 2인 새 WebAssembly Table 인스턴스를 만듭니다. 그런 다음 두 개의 인덱스 (표 {{jsxref ( "WebAssembly / Table / get", "Table.prototype.get ()")}}를 통해 검색하여 테이블의 길이와 내용을 인쇄합니다. 길이가 2이고 {{jsxref ( "null")}}이 두개라고 출력됩니다.</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>그런 다음 테이블을 포함한 <code>importObj</code>를 만듭니다.</p> + +<pre class="brush: js">var importObj = { + js: { + tbl:tbl + } +};</pre> + +<p>마지막으로 {{jsxref ( "WebAssembly.instantiateStreaming ()")}} 메소드를 사용하여 wasm 모듈 (table2.wasm)을 로드하고 인스턴스화합니다. table2.wasm 모듈에는 두 개의 함수 (하나는 42를 반환하고 다른 하나는 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">Exported WebAssembly Functions</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>액세서의 끝 부분에 두 번째 함수 호출 연산자를 포함시켜 실제로 참조 된 함수를 호출하고 그 안에 저장된 값을 기록해야합니다 (예 : <code>get(0)</code> 대신 <code>get(0)()</code>).</p> + +<p>이 예제는 자바 스크립트에서 테이블을 만들고 액세스하고 있지만 wasm 인스턴스 내부에서도 같은 테이블을 볼 수 있고 호출 할 수 있음을 보여줍니다.</p> + +<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', '#webassemblytable-objects', 'Table')}}</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.Table")}}</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> |