Skip to content

Commit 9e08aad

Browse files
committed
Require import/export names to be UTF-8.
This implements the UTF-8 proposal described in #989 (comment). This does not currently rename "name" to "utf8-name", because if UTF-8 is required for import/export names, there's a greater appeal to just saying that all strings are UTF-8, though this is debatable.
1 parent 0427c69 commit 9e08aad

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

BinaryEncoding.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ The import section declares all imports that will be used in the module.
253253
| Field | Type | Description |
254254
| ----- | ---- | ----------- |
255255
| module_len | `varuint32` | module string length |
256-
| module_str | `bytes` | module string of `module_len` bytes |
256+
| module_str | `bytes` | module name: `module_len` bytes holding valid utf8 string |
257257
| field_len | `varuint32` | field name length |
258-
| field_str | `bytes` | field name string of `field_len` bytes |
258+
| field_str | `bytes` | field name: `field_len` bytes holding valid utf8 string |
259259
| kind | `external_kind` | the kind of definition being imported |
260260

261261
Followed by, if the `kind` is `Function`:
@@ -356,7 +356,7 @@ The encoding of the [Export section](Modules.md#exports):
356356
| Field | Type | Description |
357357
| ----- | ---- | ----------- |
358358
| field_len | `varuint32` | field name string length |
359-
| field_str | `bytes` | field name string of `field_len` bytes |
359+
| field_str | `bytes` | field name: `field_len` bytes holding valid utf8 string |
360360
| kind | `external_kind` | the kind of definition being exported |
361361
| index | `varuint32` | the index into the corresponding [index space](Modules.md) |
362362

@@ -471,7 +471,7 @@ where a `naming` is encoded as:
471471
| ----- | ---- | ----------- |
472472
| index | `varuint32` | the index which is being named |
473473
| name_len | `varuint32` | number of bytes in name_str |
474-
| name_str | `bytes` | binary encoding of the name |
474+
| name_str | `bytes` | utf8 encoding of the name |
475475

476476
#### Function names
477477

Modules.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ In the future, other kinds of imports may be added. Imports are designed to
4848
allow modules to share code and data while still allowing separate compilation
4949
and caching.
5050

51-
All imports include two opaque names: a *module name* and an *export name*. The
51+
All imports include two opaque names: a *module name* and an *export name*,
52+
which are required to be [valid UTF-8]. The
5253
interpretation of these names is up to the host environment but designed to
5354
allow a host environments, like the [Web](Web.md), to support a two-level
5455
namespace.
@@ -108,7 +109,8 @@ native `syscall`. For example, a shell environment could define a builtin
108109

109110
A module can declare a sequence of **exports** which are returned at
110111
instantiation time to the host environment. Each export has three fields:
111-
a *name*, whose meaning is defined by the host environment, a *type*,
112+
a *name*, which is required to be [valid UTF-8],
113+
whose meaning is defined by the host environment, a *type*,
112114
indicating whether the export is a function, global, memory or table, and
113115
an *index* into the type's corresponding [index space](Modules.md).
114116

@@ -380,3 +382,4 @@ In the future, operators like `i32.add` could be added to allow more expressive
380382
[future types]: FutureFeatures.md#more-table-operators-and-types
381383
[future dom]: FutureFeatures.md#gc/dom-integration
382384
[future multiple tables]: FutureFeatures.md#multiple-tables-and-memories
385+
[valid UTF-8]: https://encoding.spec.whatwg.org/#utf-8-decode-without-bom-or-fail

0 commit comments

Comments
 (0)