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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
---
title: WebAssembly.Global
slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Global
translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Global
---
<div>{{JSRef}}</div>
<div> </div>
<div><strong><code>WebAssembly.Global</code></strong> 객체는 전역 변수 인스턴스를 나타내며 JavaScript 및 하나 이상의 {{jsxref("WebAssembly.Module")}} 인스턴스에서 가져 오거나 내보낼 수 있습니다. 이렇게하면 여러 모듈을 동적으로 연결할 수 있습니다.</div>
<h2 id="Constructor_Syntax">Constructor Syntax</h2>
<pre class="syntaxbox">var myGlobal = new WebAssembly.Global(<em>descriptor</em>, <em>value</em>);</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
<dt><em>descriptor</em></dt>
<dd>A <code>GlobalDescriptor</code> dictionary object, 두 개의 속성이 포함되어 있습니다.
<ul>
<li><code>value</code>: {{domxref("USVString")}}는 전역의 데이터 유형을 나타냅니다. i32, i64, f32 및 f64 중 하나입니다.</li>
<li><code>mutable</code>: 전역 변수를 변경할 수 있는지 여부를 결정하는 부울 값입니다. 기본적으로 <code>false</code>입니다.</li>
</ul>
</dd>
<dt><em>value</em></dt>
<dd>변수에 포함 된 값입니다. 변수의 데이터 타입과 일치하는 한 모든 값을 사용할 수 있습니다.<br>
변수에 포함 된 값입니다. 변수의 데이터 타입과 일치하는 모든 값을 사용할 수 있습니다. 값을 지정하지 않으면 <a href="https://webassembly.github.io/spec/js-api/#defaultvalue"><code>DefaultValue</code> 알고리즘</a>에 지정된대로 입력 된 0 값이 사용됩니다.</dd>
</dl>
<h2 id="Function_properties_of_the_Module_constructor">Function properties of the <code>Module</code> constructor</h2>
<p>None.</p>
<h2 id="Global_instances">Global instances</h2>
<p>모든 <code>Global</code> 인스턴스는 <code>Global()</code> 생성자의 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/prototype">prototype object</a>에서 상속받습니다.이 인스턴스는 모든 <code>Global</code> 인스턴스에 영향을 미치도록 수정할 수 있습니다.</p>
<h3 id="Instance_properties">Instance properties</h3>
<p>{{page('/ko/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/prototype', 'Properties')}}</p>
<h3 id="Instance_methods">Instance methods</h3>
<p>{{page('/ko/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/prototype', 'Methods')}}</p>
<h2 id="Examples">Examples</h2>
<p>다음 예제에서는 <code>WebAssembly.Global()</code> 생성자를 사용하여 만드는 새 전역 인스턴스를 보여줍니다. 값이 0 인 변경 가능한 <code>i32</code> 유형으로 정의됩니다.</p>
<p>The value of the global is then changed, first to <code>42</code> using the <code>Global.value</code> property, and then to 43 using the <code>incGlobal()</code> function exported out of the <code>global.wasm</code> module (this adds 1 to whatever value is given to it and then returns the new value). </p>
<p>그런 다음 <code>global.value</code> 속성을 사용하여 <code>42</code>까지 전역 값을 변경 한 다음 <code>global.wasm</code> 모듈에서 내 보낸 <code>incGlobal()</code> 함수를 사용하여 43으로 변경합니다.(이것은 값이 주어진 값에 1을 더한 다음 새 값을 반환합니다.)</p>
<pre class="brush: js">const output = document.getElementById('output');
function assertEq(msg, got, expected) {
output.innerHTML += `Testing ${msg}: `;
if (got !== expected)
output.innerHTML += `FAIL!<br>Got: ${got}<br>Expected: ${expected}<br>`;
else
output.innerHTML += `SUCCESS! Got: ${got}<br>`;
}
assertEq("WebAssembly.Global exists", typeof WebAssembly.Global, "function");
const global = new WebAssembly.Global({value:'i32', mutable:true}, 0);
WebAssembly.instantiateStreaming(fetch('global.wasm'), { js: { global } })
.then(({instance}) => {
assertEq("getting initial value from wasm", instance.exports.getGlobal(), 0);
global.value = 42;
assertEq("getting JS-updated value from wasm", instance.exports.getGlobal(), 42);
instance.exports.incGlobal();
assertEq("getting wasm-updated value from JS", global.value, 43);
});</pre>
<div class="note">
<p><strong>Note</strong>: GitHub에서 실행중인 예제(<a href="https://mdn.github.io/webassembly-examples/js-api-examples/global.html">running live on GitHub</a>)를 볼 수 있습니다. <a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/global.html">source code</a>도 참조하십시오.</p>
</div>
<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', '#globals', 'WebAssembly.Global()')}}</td>
<td>{{Spec2('WebAssembly JS')}}</td>
<td>Initial draft definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("javascript.builtins.WebAssembly.Global")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/ko/docs/WebAssembly">WebAssembly</a> overview page</li>
<li><a href="/ko/docs/WebAssembly/Concepts">WebAssembly concepts</a></li>
<li><a href="/ko/docs/WebAssembly/Using_the_JavaScript_API">Using the WebAssembly JavaScript API</a></li>
<li><a href="https://github.com/WebAssembly/mutable-global/blob/master/proposals/mutable-global/Overview.md">Import/Export mutable globals proposal</a></li>
</ul>
|