blob: 21e6b071af1cf8ffd6a3c0d7b2fb0d669abd6233 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
---
title: WebAssembly
slug: Web/JavaScript/Reference/Global_Objects/WebAssembly
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly
---
<div>{{JSRef}}</div>
<p><strong><code>WebAssembly</code></strong> 자바스크립트 객체는 모든 <a href="/ko/docs/WebAssembly">WebAssembly</a>에 관계된 기능의 네임스페이스로서 역할합니다.</p>
<p>대부분의 전역객체와 다르게, <code>WebAssembly</code>는 생성자가 아닙니다 (함수 객체가 아닙니다). 비슷한 예로 수학적인 상수나 함수들을 담고있는 {{jsxref("Math")}} 객체나, 국제화 관련 생성자나 언어에 민감한 다른 함수들을 담고있는 {{jsxref("Intl")}} 등이 있습니다.</p>
<h2 id="설명">설명</h2>
<p><code>WebAssembly</code> 객체의 기본적인 사용례는 다음과 같습니다:</p>
<ul>
<li>{{jsxref("WebAssembly.instantiate()")}} 함수를 사용해서 웹어셈블리 코드 불러오기.</li>
<li>{{jsxref("WebAssembly.Memory()")}}/{{jsxref("WebAssembly.Table()")}} 생성자로 새 메모리와 테이블 인스턴스 생성하기.</li>
<li>{{jsxref("WebAssembly.CompileError()")}}/{{jsxref("WebAssembly.LinkError()")}}/{{jsxref("WebAssembly.RuntimeError()")}} 생성자로 웹어셈블리에서 발생하는 에러에 대한 처리장치 만들기.</li>
</ul>
<h2 id="메서드">메서드</h2>
<dl>
<dt>{{jsxref("WebAssembly.instantiate()")}}</dt>
<dd>WebAssembly 코드를 컴파일하고 인스턴스화하여 <code>Module</code>과 첫 번째 <code>Instance</code>를 반환하는 기본 API입니다.</dd>
<dt>{{jsxref("WebAssembly.instantiateStreaming()")}}</dt>
<dd>스트리밍 된 원본 소스에서 직접 WebAssembly 모듈을 컴파일하고 인스턴스화하여 <code>Module</code>과 첫 번째 <code>Instance</code>를 반환합니다.</dd>
<dt>{{jsxref("WebAssembly.compile()")}}</dt>
<dd>WebAssembly 바이너리 코드에서 {{jsxref("WebAssembly.Module")}}을 컴파일하여 인스턴스화를 별도의 단계로 남겨 둡니다.</dd>
<dt>{{jsxref("WebAssembly.compileStreaming()")}}</dt>
<dd>{{jsxref("WebAssembly.Module")}}을 스트림 된 원본 소스에서 직접 컴파일하여 인스턴스화를 별도의 단계로 남겨 둡니다.</dd>
<dt>{{jsxref("WebAssembly.validate()")}}</dt>
<dd>바이트가 유효한 WebAssembly 코드 (<code>true</code>)인지 아닌지 (<code>false</code>)를 반환하여 WebAssembly 바이너리 코드의 지정된 입력 된 배열을 확인합니다.</dd>
</dl>
<h2 id="생성자">생성자</h2>
<dl>
<dt>{{jsxref("WebAssembly.Global()")}}</dt>
<dd>Creates a new WebAssembly <code>Global</code> object.</dd>
<dt>{{jsxref("WebAssembly.Module()")}}</dt>
<dd>Creates a new WebAssembly <code>Module</code> object.</dd>
<dt>{{jsxref("WebAssembly.Instance()")}}</dt>
<dd>Creates a new WebAssembly <code>Instance</code> object.</dd>
<dt>{{jsxref("WebAssembly.Memory()")}}</dt>
<dd>Creates a new WebAssembly <code>Memory</code> object.</dd>
<dt>{{jsxref("WebAssembly.Table()")}}</dt>
<dd>Creates a new WebAssembly <code>Table</code> object.</dd>
<dt>{{jsxref("WebAssembly.CompileError()")}}</dt>
<dd>Creates a new WebAssembly <code>CompileError</code> object.</dd>
<dt>{{jsxref("WebAssembly.LinkError()")}}</dt>
<dd>Creates a new WebAssembly <code>LinkError</code> object.</dd>
<dt>{{jsxref("WebAssembly.RuntimeError()")}}</dt>
<dd>Creates a new WebAssembly <code>RuntimeError</code> object.</dd>
</dl>
<h2 id="예제">예제</h2>
<p>다음 예제 (GitHub의 <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/instantiate-streaming.html">instantiate-streaming.html</a> 데모보기 및 <a href="https://mdn.github.io/webassembly-examples/js-api-examples/instantiate-streaming.html">라이브보기</a>)에서는 기본 소스에서 .wasm 모듈을 직접 스트리밍 한 다음 컴파일하고 인스턴스화합니다. 프로미스는 <code>ResultObject</code>로 충족됩니다. <code>instantiateStreaming()</code> 함수는 {{domxref ( "Response")}} 객체에 대한 promise를 받아들이므로 직접 {{domxref ( "WindowOrWorkerGlobalScope.fetch()")}} 호출에 전달할 수 있습니다.</p>
<pre><code>var importObject = { imports: { imported_func: arg => console.log(arg) } };
WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject)
.then(obj => obj.instance.exports.exported_func());</code></pre>
<p>그런 다음 ResultObject의 인스턴스 구성에 액세스하고 그 안에 있는 <code>exported_func</code>을 호출합니다.</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', '#the-webassembly-object', 'WebAssembly')}}</td>
<td>{{Spec2('WebAssembly JS')}}</td>
<td>초안 정의</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">브라우저 호환성</h2>
<div>{{Compat("javascript.builtins.WebAssembly")}}</div>
<h2 id="바깥_고리">바깥 고리</h2>
<ul>
<li><a href="/ko/docs/WebAssembly">웹어셈블리</a> 개요 페이지</li>
<li><a href="/ko/docs/WebAssembly/Concepts">웹어셈블리의 컨셉</a></li>
<li><a href="/en-US/docs/WebAssembly/Using_the_JavaScript_API">Using the WebAssembly JavaScript API</a></li>
</ul>
|