Skip to content

Commit e054039

Browse files
authored
Add static methods (#25)
Add a vector of static methods, getters, and setters to the declaration of a constructor function.
1 parent c6a86c4 commit e054039

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

proposals/custom-descriptors/Overview.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -586,24 +586,23 @@ descriptordata ::= n:name (if n = 'descriptors')
586586
descriptorentry ::= 0x00 importentry
587587
| 0x01 declentry
588588
589-
importentry ::= importname:name descconfig
589+
importentry ::= importname:name descconfig
590590
591-
declentry ::= protoconfig descconfig
591+
declentry ::= protoconfig descconfig
592592
593-
protoconfig ::= v:vec(descindex) (if |v| <= 1)
593+
protoconfig ::= v:vec(descindex) (if |v| <= 1)
594594
595-
descconfig ::= exportnames vec(methodconfig)
595+
descconfig ::= exportnames:vec(name) methods:vec(methodconsconfig)
596596
597-
exportnames ::= vec(name)
597+
methodnames ::= methodname:name exportname:name
598598
599-
methodconfig ::= kind:methodkind
600-
methodname:name
601-
exportname:name
599+
methodconfig ::= 0x00 methodnames => method
600+
| 0x01 methodnames => getter
601+
| 0x02 methodnames => setter
602+
603+
methodconsconfig ::= methodconfig
604+
| 0x03 methodnames vec(methodconfig) => constructor
602605
603-
methodkind ::= 0x00 => method
604-
| 0x01 => getter
605-
| 0x02 => setter
606-
| 0x03 => constructor
607606
```
608607

609608
The descriptors custom section starts with a version number,
@@ -624,12 +623,14 @@ by including multiple descriptors sections.
624623
Following the `modulename` is a sequence of `descriptorentry`,
625624
each of which describes a declared `DescriptorOptions` value or an imported prototype
626625
for use in the prototype chain of subsequent declared `DescriptorOptions`.
627-
A declaration value can optionally specify the index of a previous entry
626+
A declaration can optionally specify the index of a previous entry
628627
to provide the parent in the configured prototype chain.
629628
If the previous entry is an `importentry`, the `modulename` and `importname`
630629
are used to look up the prototype in the imports object.
631630
Otherwise, if the previous entry is a `declentry`,
632631
the prototype is looked up from the declared `DescriptorOptions`.
632+
If there is no configured parent,
633+
the parent of the new prototype is `Object.prototype`.
633634

634635
Each declared descriptor has a vector of export names.
635636
After the descriptor is created,
@@ -648,9 +649,9 @@ describing the methods that should be attached to the prototype
648649
after instantiation.
649650
Each configured method can be either a
650651
normal method, a getter, a setter, or a constructor.
651-
Methods also have two associated names: the first their property name
652-
in the configured prototype and the second
653-
the name of the exported function they wrap.
652+
Methods each have two associated names:
653+
the first is their property name in the configured prototype
654+
and the second is the name of the exported function they wrap.
654655

655656
All methods pass the receiver as the first argument:
656657

@@ -670,9 +671,15 @@ function methodname() { return exports[exportname](...arguments); }
670671

671672
Furthermore, they are not installed on the configured prototype.
672673
Instead, they are added to the `exports` object.
673-
The configured prototype is added as the `prototype` property of the generated function
674+
The configured prototype is added as the `prototype` property of the generated constructor function
674675
and the generated function is added as the `constructor` property of the configured prototype.
675676

677+
Constructor declarations also contain additional methods, getters, and setters
678+
that will be installed as properties of the constructor itself
679+
rather than the prototype.
680+
Like the constructor function itself,
681+
these "static" methods, getters, and setters do not pass their receiver as an argument.
682+
676683
### Instantiation
677684

678685
When constructing a WebAssembly instance,

0 commit comments

Comments
 (0)