Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Module.customSections #877

Merged
merged 7 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions BinaryEncoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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`.

Expand Down Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions JS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -205,6 +205,25 @@ 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.customSections`

The `customSections` function has the signature:

```
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)
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
[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`.)

### Structured Clone of a `WebAssembly.Module`

A `WebAssembly.Module` is a
Expand Down Expand Up @@ -248,7 +267,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)
Expand Down