From ad9ea64ce997fb0bf4e8bef04605ec4b1cff1147 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Tue, 7 Sep 2021 00:43:38 +0900 Subject: Global_Objects/WebAssembly/Module 以下を更新 (#2275) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化 - 2021/08/28 時点の英語版に同期 - コンストラクターの文書を新規翻訳 --- .../webassembly/module/customsections/index.html | 88 ---------------------- .../webassembly/module/customsections/index.md | 84 +++++++++++++++++++++ 2 files changed, 84 insertions(+), 88 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.md (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 deleted file mode 100644 index 1915dd6f59..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.html +++ /dev/null @@ -1,88 +0,0 @@ ---- -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')}}初回ドラフト定義。
- -

ブラウザ実装状況

- -

{{Compat("javascript.builtins.WebAssembly.Module.customSections")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.md b/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.md new file mode 100644 index 0000000000..401ddba03f --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/webassembly/module/customsections/index.md @@ -0,0 +1,84 @@ +--- +title: WebAssembly.Module.customSections() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections +tags: + - API + - JavaScript + - Method + - Module + - Object + - Reference + - WebAssembly + - customSections +browser-compat: javascript.builtins.WebAssembly.Module.customSections +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections +--- +{{JSRef}} + +**`WebAssembly.customSections()`** 関数はモジュールと文字列名を指定して、すべてのカスタムセクションのコンテンツのコピーを返します。 + +## 構文 + +```js +WebAssembly.Module.customSections(module, sectionName) +``` + +### 引数 + +- _module_ + - : カスタムセクションを考慮する {{jsxref("WebAssembly.Module")}} オブジェクト。 +- _sectionName_ + - : 目的のカスタムセクションの文字列名。 + +### 返値 + +`sectionName` に一致するすべてのカスタムセクションの {{jsxref("ArrayBuffer")}} コピーの配列 (空の場合もあります)。 + +### 例外 + +`module` が {{jsxref("WebAssembly.Module")}} オブジェクトのインスタンスでない場合、{{jsxref("TypeError")}} が発生します。 + +## 解説 + +wasm モジュールは一連の **セクション** で構成されています。これらのセクションのほとんどは wasm の仕様によって完全に指定、検証されますが、検証中に無視されスキップされる **カスタムセクション** をモジュールに含めることができます (通常のセクション ("既知のセクション") とカスタムセクションを区別するための情報は [高レベルの構造](https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#high-level-structure) を読んでください)。 + +これにより開発者は他の目的のために wasm モジュール内にカスタムデータを含めることができます。例えば、開発者がモジュール内の全ての関数とローカル変数に名前を付けられる (ネイティブビルドにおける "シンボル" のようなもの) [ネームカスタムセクション](https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section) のようなものがあります 。 + +なお、 WebAssembly テキストフォーマットには現在新しいカスタムセクションのための構文の仕様がありません。しかし、テキストフォーマットから .wasm に変換するときに wasm にネームセクションを追加することができます。 [wabt tool](https://github.com/webassembly/wabt) の一部である wast2wasm コマンドで `--debug-names` オプションを指定することができ、これを指定することにより、ネームカスタムセクションを持つ .wasm に変換することができます。 + +```bash +wast2wasm simple-name-section.was -o simple-name-section.wasm --debug-names +``` + +## 例 + +### customSections の使用 + +次の例では (custom-section.html の[ソース](https://github.com/mdn/webassembly-examples/blob/master/other-examples/custom-section.html)と[動作例](https://mdn.github.io/webassembly-examples/other-examples/custom-section.html)をご確認ください) 、読み込んだ section.wasm バイトコードをコンパイルします。 + +それから、`WebAssembly.Module.customSections` を使用して `length` が 0 より大きいかチェックして、モジュールに "name" カスタムセクションが含まれているかどうかチェックします。この例では "name" カスタムセクションが存在するため、`ArrayBuffer` オブジェクトが返されます。 + +```js +WebAssembly.compileStreaming(fetch('simple-name-section.wasm')) +.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]); +  }; +}); +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [WebAssembly](/ja/docs/WebAssembly) 概要ページ +- [WebAssembly の概念](/ja/docs/WebAssembly/Concepts) +- [WebAssembly JavaScript API の使用](/ja/docs/WebAssembly/Using_the_JavaScript_API) -- cgit v1.2.3-54-g00ecf