Skip to content

Commit c6a86c4

Browse files
authored
Add more details to custom section description (#24)
- Add a version number in anticipation of future changes - Introduce the mental model of creating wrapper modules earlier - Clarify that imports should be prototypes, not other DescriptorOptions - Clarify the role of the exportname vector. - Add a note about possibly not mutating the imports object.
1 parent 6b42bc2 commit c6a86c4

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

proposals/custom-descriptors/Overview.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ This custom section will be used in the constructor of `WebAssembly.Instance`
567567
to populate the imports with additional `DescriptorOptions` before core instantiation
568568
and to populate the prototypes using exported functions after core instantiation.
569569

570+
The custom section essentially describes (and is polyfillable by) wrapper modules
571+
updating the imports object before core Wasm instantiation
572+
and updating the exports object after instantiation.
573+
570574
### Custom Section
571575

572576
```
@@ -575,6 +579,7 @@ descindex ::= u32
575579
descriptorsec ::= section_0(descriptordata)
576580
577581
descriptordata ::= n:name (if n = 'descriptors')
582+
version:u32 (if version = 0)
578583
modulename:name
579584
vec(descriptorentry)
580585
@@ -601,25 +606,41 @@ methodkind ::= 0x00 => method
601606
| 0x03 => constructor
602607
```
603608

604-
The descriptors custom section starts with `modulename`,
605-
which is the module name from which the configured `DescriptorOptions` values
606-
will be imported by the Wasm module.
609+
The descriptors custom section starts with a version number,
610+
which is intended to help tools and engines manage
611+
backward-incompatible changes to this custom section format
612+
during proposal development.
613+
It will be removed from the final version of the custom section.
614+
615+
Next comes `modulename`, which serves two purposes.
616+
It is the module name used to look up user-provided prototypes on the import object
617+
for use in configuring `DescriptorOptions` objects,
618+
and it is also the module name where the configured `DescriptorOptions`
619+
are written back to the import object to be looked up by core instantiation.
607620
A module may import configured `DescriptorOptions` values
608621
from multiple different module names
609622
by including multiple descriptors sections.
610623

611624
Following the `modulename` is a sequence of `descriptorentry`,
612-
each of which describes a single `DescriptorOptions` value.
613-
Each value can either be imported,
614-
meaning that it is provided as an argument to instantiation,
615-
or it is declared,
616-
meaning that the instantiation procedure will create it.
617-
A declared value can optionally specify the index of a previous value
618-
to serve as the parent in the configured prototype chain.
619-
Imported values are assumed to already have their prototype chain configured.
620-
621-
Each configured descriptor has a vector of export names.
622-
These are the names from which the Wasm module will import the descriptor values.
625+
each of which describes a declared `DescriptorOptions` value or an imported prototype
626+
for use in the prototype chain of subsequent declared `DescriptorOptions`.
627+
A declaration value can optionally specify the index of a previous entry
628+
to provide the parent in the configured prototype chain.
629+
If the previous entry is an `importentry`, the `modulename` and `importname`
630+
are used to look up the prototype in the imports object.
631+
Otherwise, if the previous entry is a `declentry`,
632+
the prototype is looked up from the declared `DescriptorOptions`.
633+
634+
Each declared descriptor has a vector of export names.
635+
After the descriptor is created,
636+
it is written into the import object under `modulename` with each of these export names.
637+
The core Wasm module will then import the descriptors using these names.
638+
Typically there will be no more than one name in the vector.
639+
The vector may be empty if the descriptor only exists
640+
to declaratively populate links in the prototype chain used by other descriptors.
641+
642+
> Note: alternatively, instead of mutating the imports object, we could populate
643+
> a new imports object to pass on to core instantiation.
623644
624645
Whether imported or declared,
625646
each `descriptorentry` contains a vector of `methodconfig`

0 commit comments

Comments
 (0)