@@ -968,7 +968,7 @@ At a high level, the additional coercions would be:
968
968
| ` float32 ` , ` float64 ` | as a Number, mapping the canonical NaN to [ JS NaN] | ` ToNumber ` mapping [ JS NaN] to the canonical NaN |
969
969
| ` char ` | same as [ ` USVString ` ] | same as [ ` USVString ` ] , throw if the USV length is not 1 |
970
970
| ` record ` | TBD: maybe a [ JS Record] ? | same as [ ` dictionary ` ] |
971
- | ` variant ` | TBD | TBD |
971
+ | ` variant ` | see below | see below |
972
972
| ` list ` | create a typed array copy for number types; otherwise produce a JS array (like [ ` sequence ` ] ) | same as [ ` sequence ` ] |
973
973
| ` string ` | same as [ ` USVString ` ] | same as [ ` USVString ` ] |
974
974
| ` tuple ` | TBD: maybe a [ JS Tuple] ? | TBD |
@@ -986,6 +986,15 @@ Notes:
986
986
the return value is specified by ` ToJSValue ` above. Otherwise, the function
987
987
result is wrapped into a JS object whose field names are taken from the result
988
988
names and whose field values are specified by ` ToJSValue ` above.
989
+ * In lieu of an existing standard JS representation for ` variant ` , the JS API
990
+ would need to define its own custom binding built from objects. As a sketch,
991
+ the JS values accepted by ` (variant (case "a" u32) (case "b" string)) ` could
992
+ include ` { tag: 'a', value: 42 } ` and ` { tag: 'b', value: "hi" } ` .
993
+ * For ` union ` and ` option ` , when Web IDL doesn't support particular type
994
+ combinations (e.g., ` (option (option u32)) ` ), the JS API would fall back to
995
+ the JS API of the unspecialized ` variant ` (e.g.,
996
+ ` (variant (case "some" (option u32)) (case "none")) ` , despecializing only
997
+ the problematic outer ` option ` ).
989
998
* The forthcoming addition of [ resource and handle types] would additionally
990
999
allow coercion to and from the remaining Symbol and Object JavaScript value
991
1000
types.
0 commit comments