--- title: WebAssembly slug: Web/JavaScript/Reference/Global_Objects/WebAssembly tags: - API - JavaScript - Namespace - Object - Reference - WebAssembly translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly ---
WebAssembly JavaScript オブジェクトは全ての WebAssembly に関連する機能の名前空間として振る舞います。
他のグローバルオブジェクトとは異なり、WebAssembly はコンストラクタではありません (関数オブジェクトではない) 。数学定数、関数の名前空間である {{jsxref("Math")}} や 、国際化コンストラクタと他の言語に依存する関数のための {{jsxref("Intl")}} と同等のものです。
WebAssembly オブジェクトの主な用途は次のとおりです:
Module と、その最初の Instance を返します。Module と、その最初の Instance を返します。true) 否か (false) を返します。Module オブジェクトを生成します。Instance オブジェクトを生成します。Memory オブジェクトを生成します。Table オブジェクトを生成します。CompileError オブジェクトを生成します。LinkError オブジェクトを生成します。RuntimeError オブジェクトを生成します。fetch を使用して WebAssembly バイトコードをフェッチした後、{{jsxref("WebAssembly.instantiate()")}} 関数を使用してモジュールをコンパイル、インスタンス化します。その過程で、WebAssembly モジュールに JavaScript の関数をインポートします。このプロミスは解決時に Module と Instance を含むオブジェクト (result) を渡します。次に、Instance からエクスポートされている エクスポートされた WebAssembly 関数 を呼び出します。
var importObject = {
imports: {
imported_func: function(arg) {
console.log(arg);
}
}
};
fetch('simple.wasm').then(response =>
response.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, importObject)
).then(result =>
result.instance.exports.exported_func()
);
注: GitHub上の例 (動作例) のindex.htmlでは、我々で定義した fetchAndInstantiate() ライブラリ関数を使用しています。
| 仕様 | 策定状況 | コメント |
|---|---|---|
| {{SpecName('WebAssembly JS', '#the-webassembly-object', 'WebAssembly')}} | {{Spec2('WebAssembly JS')}} | 初回ドラフト定義。 |