Skip to content

Commit b105035

Browse files
committed
Fill in some JS Embedding details
1 parent e7a22d8 commit b105035

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

design/mvp/Explainer.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,22 +1022,30 @@ a 16-bit `layer` field with `0` for modules and `1` for components).
10221022

10231023
Once compiled, a `WebAssembly.Component` could be instantiated using the
10241024
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
10271028
imports of modules, components and instances. Since the results of
10281029
instantiating a component is a record of JavaScript values, just like an
10291030
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.
10311043

10321044
Lastly, when given a component binary, the compile-then-instantiate overloads
10331045
of `WebAssembly.instantiate(Streaming)` would inherit the compound behavior of
10341046
the abovementioned functions (again, using the `layer` field to eagerly
10351047
distinguish between modules and components).
10361048

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-
10411049
For example, the following component:
10421050
```wasm
10431051
;; a.wasm
@@ -1139,8 +1147,10 @@ the same places where modules can be loaded today, branching on the `layer`
11391147
field in the binary format to determine whether to decode as a module or a
11401148
component.
11411149

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`.
11441154

11451155
The main question is how to deal with component imports having a
11461156
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:
12441254
[`enum`]: https://webidl.spec.whatwg.org/#es-enumeration
12451255
[`T?`]: https://webidl.spec.whatwg.org/#es-nullable-type
12461256
[`union`]: https://webidl.spec.whatwg.org/#es-union
1257+
[`Get`]: https://tc39.es/ecma262/#sec-get-o-p
12471258
[JS NaN]: https://tc39.es/ecma262/#sec-ecmascript-language-types-number-type
12481259
[Import Reflection]: https://github.com/tc39-transfer/proposal-import-reflection
12491260
[Module Record]: https://tc39.es/ecma262/#sec-abstract-module-records

0 commit comments

Comments
 (0)