Skip to content

Commit 08f2ea6

Browse files
committed
Add JS API notes about variants
Resolve #25
1 parent b4e513e commit 08f2ea6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

design/mvp/Explainer.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ At a high level, the additional coercions would be:
967967
| `float32`, `float64` | as a Number, mapping the canonical NaN to [JS NaN] | `ToNumber` mapping [JS NaN] to the canonical NaN |
968968
| `char` | same as [`USVString`] | same as [`USVString`], throw if the USV length is not 1 |
969969
| `record` | TBD: maybe a [JS Record]? | same as [`dictionary`] |
970-
| `variant` | TBD | TBD |
970+
| `variant` | see below | see below |
971971
| `list` | create a typed array copy for number types; otherwise produce a JS array (like [`sequence`]) | same as [`sequence`] |
972972
| `string` | same as [`USVString`] | same as [`USVString`] |
973973
| `tuple` | TBD: maybe a [JS Tuple]? | TBD |
@@ -985,6 +985,14 @@ Notes:
985985
the return value is specified by `ToJSValue` above. Otherwise, the function
986986
result is wrapped into a JS object whose field names are taken from the result
987987
names and whose field values are specified by `ToJSValue` above.
988+
* In lieu of an existing standard JS representation for `variant`, the JS API
989+
would need to define its own custom binding built from objects. As a sketch,
990+
the JS values accepted by `(variant (case "a" u32) (case "b" string))` could
991+
include `{ a: 42 }` and `{ b: "hi" }`.
992+
* For `union` and `option`, when Web IDL doesn't support particular type
993+
combinations (e.g., `(option (option u32))`), the JS API would fall back to
994+
the JS API of the unspecialized `variant` (e.g.,
995+
`(variant (case "some" (variant (case "some" u32) (case "none"))) (case "none"))`).
988996
* The forthcoming addition of [resource and handle types] would additionally
989997
allow coercion to and from the remaining Symbol and Object JavaScript value
990998
types.

0 commit comments

Comments
 (0)