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/global/index.html | |
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/global/index.html')
-rw-r--r-- | files/ja/web/javascript/reference/global_objects/webassembly/global/index.html | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/global/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/global/index.html new file mode 100644 index 0000000000..16817b0777 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/webassembly/global/index.html @@ -0,0 +1,118 @@ +--- +title: WebAssembly.Global +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Global +tags: + - API + - Constructor + - JavaScript + - Reference + - WebAssembly + - global +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Global +--- +<div>{{JSRef}}</div> + +<p><strong><code>WebAssembly.Global</code></strong> はグローバル変数として存在し、JavaScript または {{jsxref("WebAssembly.Module")}} インスタンスから参照することができます。これにより動的に複数のモジュールをリンクすることができます。</p> + +<h2 id="Constructor_Syntax" name="Constructor_Syntax">コンストラクターの文法</h2> + +<pre class="syntaxbox">var myGlobal = new WebAssembly.Global(<em>descriptor</em>, <em>value</em>);</pre> + +<h3 id="Parameters" name="Parameters">パラメーター</h3> + +<dl> + <dt><em>descriptor</em></dt> + <dd><code>GlobalDescriptor</code> 辞書オブジェクト、2 つの要素を持っている: + <ul> + <li><code>value</code>: {{domxref("USVString")}} はグローバルデータ形式を表し値として <code>i32</code>、<code>i64</code>、<code>f32</code>、<code>f64</code> のうち一つを取ります。</li> + <li><code>mutable</code>: グローバルがミュータブルかどうかの真偽値です。デフォルトでは <code>false</code> です。</li> + </ul> + </dd> + <dt><em>value</em></dt> + <dd>変数が保持する値です。変数のデータ型に合う限りどんな値でも取れます。もしも何の値も渡されないと、<a href="https://webassembly.github.io/spec/js-api/#defaultvalue"><code>DefaultValue</code> algorithm</a> で指定した時の様な 型ありの 0 が使われます。</dd> +</dl> + +<h2 id="Function_properties_of_the_Global_constructor" name="Function_properties_of_the_Global_constructor">グローバルコンストラクターによる関数プロパティ</h2> + +<p>無し</p> + +<h2 id="Global_instances" name="Global_instances">グローバルインスタンス</h2> + +<p>すべてのグローバルインスタンスは <code>Global()</code> コンストラクターのプロパティオブジェクトを受け継ぐ — これによりすべての <code>Global</code> インスタンスを変更できる</p> + +<h3 id="Instance_properties" name="Instance_properties">インスタンスプロパティ</h3> + +<p>{{page('/ja/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/prototype', 'Properties')}}</p> + +<h3 id="Instance_methods" name="Instance_methods">インスタンスメソッド</h3> + +<p>{{page('/ja/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/prototype', 'Methods')}}</p> + +<h2 id="Examples" name="Examples">例</h2> + +<p>以下の例では新しいグローバルインスタンスは <code>WebAssembly.Global()</code> コンストラクターを用いて初期化され、初期値 0 のミュータブルな <code>i32</code> 型として定義されます。</p> + +<p>その後この値は、<code>Global.value</code> プロパティを使うことによって <code>42</code> に、<code>global.wasm</code> モジュールから公開された <code>incGlobal()</code> 関数 (入力に限らず 1 を加算する) を使うことによって <code>43</code> になります。</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>メモ</strong>: <a href="https://mdn.github.io/webassembly-examples/js-api-examples/global.html">GitHub 上で動くデモ</a>が試せます。<a href="https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/global.html">ソースコード</a>も確認してみてください。</p> +</div> + +<h2 id="Specifications" name="Specifications">仕様</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', '#globals', 'WebAssembly.Global()')}}</td> + <td>{{Spec2('WebAssembly JS')}}</td> + <td>初回ドラフト定義</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</h2> + +<div> + + +<p>{{Compat("javascript.builtins.WebAssembly.Global")}}</p> +</div> + +<h2 id="See_also" name="See_also">参考</h2> + +<ul> + <li><a href="/ja/docs/WebAssembly">WebAssembly</a> 概要ページ</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> + <li><a href="https://github.com/WebAssembly/mutable-global/blob/master/proposals/mutable-global/Overview.md">Import/Export mutable globals proposal</a></li> +</ul> |