JsHostDefinedModule Class
A cyclic module defined by the host (e.g. a WebAssembly Module Record, https://webassembly.github.io/esm-integration/js-api/index.html#integration-with-ecmascript-modules): its dependencies are loaded, linked and evaluated before it, like the imports of a JavaScript module, and it can be part of a cycle. Its exports are uninitialized bindings until the host sets them, when the module is evaluated.
public sealed class JsHostDefinedModule : JsCyclicModuleRemarks
The module is created by JsRealm.CreateHostDefinedModule. When it is linked, the names it declares to import must be exported by the modules it requests (a SyntaxError otherwise, before any module of the graph runs, as for a JavaScript module). When it is evaluated, after the modules it requests, the evaluation steps read the values of its imports with JsHostDefinedModule.GetImport and set its exports with JsHostDefinedModule.SetExport or JsHostDefinedModule.SetExportGetter. An export that is not set stays uninitialized: reading it throws a ReferenceError.
- Inheritance
JsCyclicModuleJsHostDefinedModule
Properties
| Name | Description |
|---|---|
| ExportNames | Gets the names of the exports of the module. |
| ImportedNames | Gets the names that the module declares to import, validated when the module is linked: the specifier of a module of JsHostDefinedModule.RequestedModuleSpecifiers (the key) and the name of the export it imports (the value), in order and without duplicates. |
| RequestedModuleSpecifiers | Gets the specifiers of the modules the module imports, in order and without duplicates. |
ExportNames
JsHostDefinedModule.csGets the names of the exports of the module.
public IReadOnlyList<string> ExportNames { get; }Property value
ImportedNames
JsHostDefinedModule.csGets the names that the module declares to import, validated when the module is linked: the specifier of a module of JsHostDefinedModule.RequestedModuleSpecifiers (the key) and the name of the export it imports (the value), in order and without duplicates.
public IReadOnlyList<KeyValuePair<string, string>> ImportedNames { get; }Property value
RequestedModuleSpecifiers
JsHostDefinedModule.csGets the specifiers of the modules the module imports, in order and without duplicates.
public IReadOnlyList<string> RequestedModuleSpecifiers { get; }Property value
Methods
| Name | Description |
|---|---|
| GetImport(string, string) | Resolves an import of the module (the binding importName of the module requested with specifier, ResolveExport), followed through the re-exports. The module must be linked. |
| GetRequestedModule(string) | Gets the module that the module imports with specifier. The module must be loaded. |
| SetExport(string, JsValue) | Initializes or sets the value of an export of the module. The module must be linked. |
| SetExportGetter(string, Func<JsValue>) | Initializes an export of the module with a live binding: its value is read from getter each time the binding is read (e.g. the value of a mutable WebAssembly global, which the WebAssembly code can change). The module must be linked. |
GetImport(string, string)
JsHostDefinedModule.csResolves an import of the module (the binding importName of the module requested with specifier, ResolveExport), followed through the re-exports. The module must be linked.
public JsModuleBinding GetImport(string specifier, string importName)Parameters
specifierstring- The specifier of a module of
JsHostDefinedModule.RequestedModuleSpecifiers. importNamestring- The name of the export of the requested module.
Returns
Exceptions
ArgumentExceptionspecifieris not a requested module.JsException- The requested module does not export the name, or exports it ambiguously (a SyntaxError).
GetRequestedModule(string)
JsHostDefinedModule.csGets the module that the module imports with specifier. The module must be loaded.
SetExport(string, JsValue)
JsHostDefinedModule.csInitializes or sets the value of an export of the module. The module must be linked.
Parameters
Exceptions
ArgumentException- The module does not export
name. InvalidOperationException- The module is not linked.
SetExportGetter(string, Func<JsValue>)
JsHostDefinedModule.csInitializes an export of the module with a live binding: its value is read from getter each time the binding is read (e.g. the value of a mutable WebAssembly global, which the WebAssembly code can change). The module must be linked.
Parameters
namestringgetterFunc<JsValue>
Exceptions
ArgumentException- The module does not export
name. InvalidOperationException- The module is not linked.