@@ -567,6 +567,10 @@ This custom section will be used in the constructor of `WebAssembly.Instance`
567
567
to populate the imports with additional ` DescriptorOptions ` before core instantiation
568
568
and to populate the prototypes using exported functions after core instantiation.
569
569
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
+
570
574
### Custom Section
571
575
572
576
```
@@ -575,6 +579,7 @@ descindex ::= u32
575
579
descriptorsec ::= section_0(descriptordata)
576
580
577
581
descriptordata ::= n:name (if n = 'descriptors')
582
+ version:u32 (if version = 0)
578
583
modulename:name
579
584
vec(descriptorentry)
580
585
@@ -601,25 +606,41 @@ methodkind ::= 0x00 => method
601
606
| 0x03 => constructor
602
607
```
603
608
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.
607
620
A module may import configured ` DescriptorOptions ` values
608
621
from multiple different module names
609
622
by including multiple descriptors sections.
610
623
611
624
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.
623
644
624
645
Whether imported or declared,
625
646
each ` descriptorentry ` contains a vector of ` methodconfig `
0 commit comments