@@ -1022,22 +1022,30 @@ a 16-bit `layer` field with `0` for modules and `1` for components).
1022
1022
1023
1023
Once compiled, a ` WebAssembly.Component ` could be instantiated using the
1024
1024
existing JS API ` WebAssembly.instantiate(Streaming) ` . Since components have the
1025
- same basic import/export structure as modules, this mostly just means extending
1026
- the [ * read the imports* ] logic to support single-level imports as well as
1025
+ same basic import/export structure as modules, this means extending the [ * read
1026
+ the imports* ] logic to support single-level imports (of kebab-case component
1027
+ import names converted to lowerCamelCase JavaScript identifiers) as well as
1027
1028
imports of modules, components and instances. Since the results of
1028
1029
instantiating a component is a record of JavaScript values, just like an
1029
1030
instantiated module, ` WebAssembly.instantiate ` would always produce a
1030
- ` WebAssembly.Instance ` object for both module and component arguments.
1031
+ ` WebAssembly.Instance ` object for both module and component arguments
1032
+ (again, with kebab-case component export names converted to lowerCamelCase).
1033
+
1034
+ Since the JavaScript embedding is generic, loading all component types, it
1035
+ needs to allow the JS client to refer to either of the ` name ` or ` URL ` fields
1036
+ of component ` externname ` s. On the import side, this means that, when a ` URL `
1037
+ is present, * read the imports* will first attempt to [ ` Get ` ] the ` URL ` and, on
1038
+ failure, ` Get ` the ` name ` . On the export side, this means that * both* the
1039
+ ` name ` and ` URL ` are exposed as exports in the export object (both holding the
1040
+ same value). Since ` name ` and ` URL ` are necessarily disjoint sets of strings
1041
+ (in particular, ` URL ` s must contain a ` : ` , ` name ` must not), there should not
1042
+ be any conflicts in either of these cases.
1031
1043
1032
1044
Lastly, when given a component binary, the compile-then-instantiate overloads
1033
1045
of ` WebAssembly.instantiate(Streaming) ` would inherit the compound behavior of
1034
1046
the abovementioned functions (again, using the ` layer ` field to eagerly
1035
1047
distinguish between modules and components).
1036
1048
1037
- TODO: describe how kebab-names are mapped to JS identifiers
1038
-
1039
- TODO: describe how the fields can accept either a name or a URL (which are disjoint sets of strings)
1040
-
1041
1049
For example, the following component:
1042
1050
``` wasm
1043
1051
;; a.wasm
@@ -1139,8 +1147,10 @@ the same places where modules can be loaded today, branching on the `layer`
1139
1147
field in the binary format to determine whether to decode as a module or a
1140
1148
component.
1141
1149
1142
- TODO: explain how ` URL ` field is used as module specifier, if present, falling
1143
- back to the ` name ` field, which can be implemented by [ import maps]
1150
+ When the ` URL ` field of an imported ` externname ` is present, the ` URL ` is
1151
+ used as the module specifier, using the same resolution path as JS module.
1152
+ Otherwise, the ` name ` field is used as the module specifier, which requires
1153
+ [ Import Maps] support to resolve to a ` URL ` .
1144
1154
1145
1155
The main question is how to deal with component imports having a
1146
1156
single string as well as the new importable component, module and instance
@@ -1244,6 +1254,7 @@ and will be added over the coming months to complete the MVP proposal:
1244
1254
[ `enum` ] : https://webidl.spec.whatwg.org/#es-enumeration
1245
1255
[ `T?` ] : https://webidl.spec.whatwg.org/#es-nullable-type
1246
1256
[ `union` ] : https://webidl.spec.whatwg.org/#es-union
1257
+ [ `Get` ] : https://tc39.es/ecma262/#sec-get-o-p
1247
1258
[ JS NaN ] : https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type
1248
1259
[ Import Reflection ] : https://github.com/tc39-transfer/proposal-import-reflection
1249
1260
[ Module Record ] : https://tc39.es/ecma262/#sec-abstract-module-records
0 commit comments