From bd1f38bfd6d5d130a0591f17f57b50dd61beb4d2 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Tue, 22 Nov 2016 15:26:28 -0600 Subject: [PATCH 1/7] Add Module.sections --- JS.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/JS.md b/JS.md index d87fd84b..4ebdd8a2 100644 --- a/JS.md +++ b/JS.md @@ -205,6 +205,26 @@ to the Object `{ module: String(i.module_name), name: String(i.item_name), kind: Note: other fields like `signature` may be added in the future. +### `WebAssembly.Module.sections` + +The `sections` function has the signature: + +``` +Array sections(modueObject, sectionName) +``` + +If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) +is thrown. + +If `Type(sectionName)` is not String, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) +is thrown. + +This function returns an `Array` produced by mapping each +[user-defined section](BinaryEncoding.md#high-level-structure) (i.e., section with +`id` 0) whose `name` field ([decoded as UTF-8](Web.md#names)) is equal to +`sectionName` to an `ArrayBuffer` containing the section's `payload_data`. +(Note: `payload_data` does not include `name` or `name_len`.) + ### Structured Clone of a `WebAssembly.Module` A `WebAssembly.Module` is a From c10e7b48117535f343f8fc688af795ac3d45cf55 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 23 Nov 2016 09:59:12 -0600 Subject: [PATCH 2/7] Don't say 'instance' to avoid confusion --- JS.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/JS.md b/JS.md index 4ebdd8a2..ec28d0c7 100644 --- a/JS.md +++ b/JS.md @@ -174,7 +174,7 @@ The `exports` function has the signature: Array exports(moduleObject) ``` -If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) +If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) is thrown. This function returns an `Array` produced by mapping each @@ -193,7 +193,7 @@ The `imports` function has the signature: Array imports(moduleObject) ``` -If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) +If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) is thrown. This function returns an `Array` produced by mapping each @@ -213,7 +213,7 @@ The `sections` function has the signature: Array sections(modueObject, sectionName) ``` -If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) +If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) is thrown. If `Type(sectionName)` is not String, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) @@ -268,7 +268,7 @@ If the NewTarget is `undefined`, a [`TypeError`](https://tc39.github.io/ecma262/ exception is thrown (i.e., this constructor cannot be called as a function without `new`). -If `moduleObject` is not a `WebAssembly.Module` instance, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) +If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) is thrown. Let `module` be the [`Ast.module`](https://github.com/WebAssembly/spec/blob/master/interpreter/spec/ast.ml#L176) From 94f39426d61d2da32b036838f4fb3195472862cd Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 23 Nov 2016 10:06:07 -0600 Subject: [PATCH 3/7] s/sections/userSections/ --- JS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/JS.md b/JS.md index ec28d0c7..9099e583 100644 --- a/JS.md +++ b/JS.md @@ -205,12 +205,12 @@ to the Object `{ module: String(i.module_name), name: String(i.item_name), kind: Note: other fields like `signature` may be added in the future. -### `WebAssembly.Module.sections` +### `WebAssembly.Module.userSections` -The `sections` function has the signature: +The `userSections` function has the signature: ``` -Array sections(modueObject, sectionName) +Array userSections(modueObject, sectionName) ``` If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) From fea04e4fc14c02cf88429cb3b48fd33a280133c2 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 23 Nov 2016 10:11:15 -0600 Subject: [PATCH 4/7] Put ToString() back, for JS API regularity --- JS.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/JS.md b/JS.md index 9099e583..4392d9a7 100644 --- a/JS.md +++ b/JS.md @@ -216,13 +216,12 @@ Array userSections(modueObject, sectionName) If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) is thrown. -If `Type(sectionName)` is not String, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) -is thrown. +Let `sectionNameString` be the result of [`ToString`](https://tc39.github.io/ecma262/#sec-tostring)(`sectionName`). This function returns an `Array` produced by mapping each [user-defined section](BinaryEncoding.md#high-level-structure) (i.e., section with `id` 0) whose `name` field ([decoded as UTF-8](Web.md#names)) is equal to -`sectionName` to an `ArrayBuffer` containing the section's `payload_data`. +`sectionNameString` to an `ArrayBuffer` containing the section's `payload_data`. (Note: `payload_data` does not include `name` or `name_len`.) ### Structured Clone of a `WebAssembly.Module` From 8dde47e3f2d3fef917815a57009d06ca7c3ac803 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 23 Nov 2016 10:42:36 -0600 Subject: [PATCH 5/7] Fix spelling of moduleObject --- JS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JS.md b/JS.md index 4392d9a7..a81dfacc 100644 --- a/JS.md +++ b/JS.md @@ -210,7 +210,7 @@ Note: other fields like `signature` may be added in the future. The `userSections` function has the signature: ``` -Array userSections(modueObject, sectionName) +Array userSections(moduleObject, sectionName) ``` If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) From 1ae783e11d52e0f81ad42c82b73e60c3ed8ea6df Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Wed, 23 Nov 2016 10:43:45 -0600 Subject: [PATCH 6/7] Clarify returning a copy --- JS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JS.md b/JS.md index a81dfacc..a4355f84 100644 --- a/JS.md +++ b/JS.md @@ -221,8 +221,8 @@ Let `sectionNameString` be the result of [`ToString`](https://tc39.github.io/ecm This function returns an `Array` produced by mapping each [user-defined section](BinaryEncoding.md#high-level-structure) (i.e., section with `id` 0) whose `name` field ([decoded as UTF-8](Web.md#names)) is equal to -`sectionNameString` to an `ArrayBuffer` containing the section's `payload_data`. -(Note: `payload_data` does not include `name` or `name_len`.) +`sectionNameString` to an `ArrayBuffer` containing a copy of the section's +`payload_data`. (Note: `payload_data` does not include `name` or `name_len`.) ### Structured Clone of a `WebAssembly.Module` From a441a8c8576c5555a29a4265032ab2fa299f44df Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Mon, 28 Nov 2016 16:16:14 -0600 Subject: [PATCH 7/7] s/user|unknown/custom/ and in BinaryEncoding.md too --- BinaryEncoding.md | 16 ++++++++-------- JS.md | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/BinaryEncoding.md b/BinaryEncoding.md index d0081fe2..57bd1a8f 100644 --- a/BinaryEncoding.md +++ b/BinaryEncoding.md @@ -177,11 +177,11 @@ The module starts with a preamble of two fields: | version | `uint32` | Version number, currently 0xd. The version for MVP will be reset to 1. | The module preamble is followed by a sequence of sections. -Each section is identified by a 1-byte *section code* that encodes either a known section or a user-defined section. +Each section is identified by a 1-byte *section code* that encodes either a known section or a custom section. The section length and payload data then follow. -Known sections have non-zero ids, while unknown sections have a `0` id followed by an identifying string as +Known sections have non-zero ids, while custom sections have a `0` id followed by an identifying string as part of the payload. -Unknown sections are ignored by the WebAssembly implementation, and thus validation errors within them do not +Custom sections are ignored by the WebAssembly implementation, and thus validation errors within them do not invalidate a module. | Field | Type | Description | @@ -193,7 +193,7 @@ invalidate a module. | payload_data | `bytes` | content of this section, of length `payload_len - sizeof(name) - sizeof(name_len)` | Each known section is optional and may appear at most once. -Unknown sections all have the same `id`, and can be named non-uniquely (all bytes composing their names can be identical). +Custom sections all have the same `id`, and can be named non-uniquely (all bytes composing their names can be identical). Known sections from this list may not appear out of order. The content of each section is encoded in its `payload_data`. @@ -413,11 +413,11 @@ a `data_segment` is: ### Name section -User-defined section string: `"name"` +Custom section `name` field: `"name"` -The names section does not change execution semantics, and thus is not allocated a section code. -It is encoded as an unknown section (id `0`) followed by the identification string `"name"`. -Like all unknown sections, a validation error in this section does not cause validation of the module to fail. +The names section is a [custom section](#high-level-structure). +It is therefore encoded with id `0` followed by the name string `"name"`. +Like all custom sections, a validation error in this section does not cause validation of the module to fail. The name section may appear only once, and only after the [Data section](#Data-section). The expectation is that, when a binary WebAssembly module is viewed in a browser or other development environment, the names in this section will be used as the names of functions diff --git a/JS.md b/JS.md index a4355f84..1cfd4ee4 100644 --- a/JS.md +++ b/JS.md @@ -205,12 +205,12 @@ to the Object `{ module: String(i.module_name), name: String(i.item_name), kind: Note: other fields like `signature` may be added in the future. -### `WebAssembly.Module.userSections` +### `WebAssembly.Module.customSections` -The `userSections` function has the signature: +The `customSections` function has the signature: ``` -Array userSections(moduleObject, sectionName) +Array customSections(moduleObject, sectionName) ``` If `moduleObject` is not a `WebAssembly.Module`, a [`TypeError`](https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror) @@ -219,7 +219,7 @@ is thrown. Let `sectionNameString` be the result of [`ToString`](https://tc39.github.io/ecma262/#sec-tostring)(`sectionName`). This function returns an `Array` produced by mapping each -[user-defined section](BinaryEncoding.md#high-level-structure) (i.e., section with +[custom section](BinaryEncoding.md#high-level-structure) (i.e., section with `id` 0) whose `name` field ([decoded as UTF-8](Web.md#names)) is equal to `sectionNameString` to an `ArrayBuffer` containing a copy of the section's `payload_data`. (Note: `payload_data` does not include `name` or `name_len`.)