From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../webassembly/module/customsections/index.html | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html (limited to 'files/ja/web/javascript/reference/global_objects/webassembly/module/customsections') diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html new file mode 100644 index 0000000000..757c3e33e4 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html @@ -0,0 +1,144 @@ +--- +title: WebAssembly.Module.customSections() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections +--- +
{{JSRef}}{{SeeCompatTable}}
+ +

WebAssembly.customSections() 関数はモジュールと文字列名を指定して、全てのカスタムセクションのコンテンツのコピーを返します。

+ +

構文

+ +
var custSec = WebAssembly.Module.customSections(module, sectionName);
+ +

パラメータ

+ +
+
module
+
カスタムセクションが考慮されている {{jsxref("WebAssembly.Module")}} オブジェクト。
+
sectionName
+
目的のカスタムセクションの文字列名。
+
+ +

戻り値

+ +

sectionName にマッチした全てのカスタムセクションの {{domxref("ArrayBuffer")}} コピーの配列 (もしかしたら空の場合もあります) 。

+ +

例外

+ +

もし module が {{jsxref("WebAssembly.Module")}} オブジェクトインスタンスでない場合、{{jsxref("TypeError")}} がスローされます。

+ +

カスタムセクション

+ +

wasm モジュールは一連の セクション で構成されています。これらのセクションのほとんどは wasm の仕様によって完全に指定、バリデーションされますが、バリデーション中に無視されスキップされる カスタムセクション をモジュールに含めることができます (通常のセクション("既知のセクション")とカスタムセクションを区別するための情報は 高レベルの構造 を読んでください)。

+ +

これにより開発者は他の目的のために wasm モジュール内にカスタムデータを含めることができます。例えば、開発者がモジュール内の全ての関数とローカル変数に名前を付けられる (ネイティブビルドにおける "シンボル" のようなもの) ネームカスタムセクション のようなものがあります 。

+ +

Note that the WebAssembly テキストフォーマットには現在新しいカスタムセクションのための構文の仕様がありません。しかし、テキストフォーマットから .wasm に変換するときに wasm にネームセクションを追加することができます。wabt tool  の一部である wast2wasm コマンドで --debug-names オプションを指定することができます。これを指定することにより、ネームカスタムセクションを持つ .wasm に変換することができます:

+ +
wast2wasm simple-name-section.was -o simple-name-section.wasm --debug-names
+ +

+ +

次の例では(custom-section.html の ソース と 動作例 をご確認ください) 、ロードした section.wasm バイトコードをコンパイルしています。

+ +

それから、WebAssembly.Module.customSections を使用して length が0より大きいかチェックして、モジュールに "name" カスタムセクションが含まれているかどうかチェックします。この例では "name" カスタムセクションが存在するため、ArrayBuffer オブジェクトが返されます。

+ +
fetch('simple-name-section.wasm').then(response =>
+  response.arrayBuffer()
+).then(bytes =>
+  WebAssembly.compile(bytes)
+).then(function(mod) {
+  var nameSections = WebAssembly.Module.customSections(mod, "name");
+  if (nameSections.length != 0) {
+    console.log("Module contains a name section");
+    console.log(nameSections[0]);
+  };
+});
+ +

仕様

+ + + + + + + + + + + + + + + + +
仕様策定状況コメント
{{SpecName('WebAssembly JS', '#webassemblymodulecustomsections', 'customSections()')}}{{Spec2('WebAssembly JS')}}初回ドラフト定義。
+ +

ブラウザ実装状況

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
基本サポート5715[2]{{CompatGeckoDesktop(52)}}[1]{{CompatNo}}4411
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureChrome for AndroidAndroid WebviewEdge MobileFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基本サポート5757{{CompatNo}}{{CompatGeckoMobile(52)}}[1]{{CompatNo}}{{CompatNo}}11
+
+ +

[1] WebAssemblyはFirefox 52+で有効です。Firefox 52 Extended Support Release (ESR.)では無効化されています。

+ +

[2] 現在、“Experimental JavaScript Features” フラグを付けることでサポートされます。詳細については このブログ記事 を参照してください。

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf