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 : JsCyclicModule

Remarks

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
JsCyclicModule JsHostDefinedModule

Properties

NameDescription
ExportNamesGets the names of the exports of the module.
ImportedNamesGets 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.
RequestedModuleSpecifiersGets the specifiers of the modules the module imports, in order and without duplicates.

Gets the names of the exports of the module.

public IReadOnlyList<string> ExportNames { get; }

Property value

IReadOnlyList<string>

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.

public IReadOnlyList<KeyValuePair<string, string>> ImportedNames { get; }

RequestedModuleSpecifiers

JsHostDefinedModule.cs

Gets the specifiers of the modules the module imports, in order and without duplicates.

public IReadOnlyList<string> RequestedModuleSpecifiers { get; }

Property value

IReadOnlyList<string>

Methods

NameDescription
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.cs

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.

public JsModuleBinding GetImport(string specifier, string importName)

Parameters

specifier string
The specifier of a module of JsHostDefinedModule.RequestedModuleSpecifiers.
importName string
The name of the export of the requested module.

Returns

JsModuleBinding

Exceptions

ArgumentException
specifier is not a requested module.
JsException
The requested module does not export the name, or exports it ambiguously (a SyntaxError).

GetRequestedModule(string)

JsHostDefinedModule.cs

Gets the module that the module imports with specifier. The module must be loaded.

public JsModule GetRequestedModule(string specifier)

Parameters

specifier string

Returns

JsModule

Exceptions

ArgumentException
specifier is not a requested module.

SetExport(string, JsValue)

JsHostDefinedModule.cs

Initializes or sets the value of an export of the module. The module must be linked.

public void SetExport(string name, JsValue value)

Parameters

name string
value JsValue

Exceptions

ArgumentException
The module does not export name.
InvalidOperationException
The module is not linked.

SetExportGetter(string, Func<JsValue>)

JsHostDefinedModule.cs

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.

public void SetExportGetter(string name, Func<JsValue> getter)

Parameters

name string
getter Func<JsValue>

Exceptions

ArgumentException
The module does not export name.
InvalidOperationException
The module is not linked.