JsModule Class

A Module Record (https://tc39.es/ecma262/#sec-abstract-module-records). A module is loaded (JsModule.LoadRequestedModules), linked (JsModule.Link), then evaluated (JsModule.Evaluate).

public abstract class JsModule : JsScriptOrModule
Inheritance
JsScriptOrModule JsModule

Properties

NameDescription
EvaluationErrorGets the error thrown by the evaluation of the module ([[EvaluationError]]), or undefined.
EvaluationErrorLocationGets the position of the code that threw JsModule.EvaluationError, when the error was thrown synchronously by the evaluation of a module of the graph.
HasEvaluationErrorGets whether the evaluation of the module threw an error.
ModuleSourceGets or sets the module source object of the module ([[ModuleSource]], https://tc39.es/proposal-source-phase-imports/): the value of a source phase import of the module (import source x from and import.source()), e.g. a WebAssembly.Module. The host sets it when it creates the module, before the module loader returns it. The object should extend JsRealm.AbstractModuleSource and be a JsHostObject whose JsHostObject.ModuleSourceClassName is set. When it is null (e.g. a JavaScript or a JSON module), a source phase import of the module throws a SyntaxError.
StatusGets the status of the module.

EvaluationError

JsModule.cs

Gets the error thrown by the evaluation of the module ([[EvaluationError]]), or undefined.

public JsValue EvaluationError { get; }

Property value

JsValue

EvaluationErrorLocation

JsModule.cs

Gets the position of the code that threw JsModule.EvaluationError, when the error was thrown synchronously by the evaluation of a module of the graph.

public JsSourceLocation? EvaluationErrorLocation { get; }

Property value

JsSourceLocation?

HasEvaluationError

JsModule.cs

Gets whether the evaluation of the module threw an error.

public bool HasEvaluationError { get; }

Property value

bool

ModuleSource

JsModule.cs

Gets or sets the module source object of the module ([[ModuleSource]], https://tc39.es/proposal-source-phase-imports/): the value of a source phase import of the module (import source x from and import.source()), e.g. a WebAssembly.Module. The host sets it when it creates the module, before the module loader returns it. The object should extend JsRealm.AbstractModuleSource and be a JsHostObject whose JsHostObject.ModuleSourceClassName is set. When it is null (e.g. a JavaScript or a JSON module), a source phase import of the module throws a SyntaxError.

public JsObject? ModuleSource { get; set; }

Property value

JsObject?

Gets the status of the module.

public JsModuleStatus Status { get; }

Property value

JsModuleStatus

Methods

NameDescription
Evaluate()Evaluates the module and its dependencies (Evaluate).
GetNamespace()Gets the namespace object of the module (GetModuleNamespace). The module must be linked.
Link()Links the module and its dependencies (Link): creates the environments and resolves the imports.
LoadRequestedModules(object?)Loads the dependencies of the module, recursively (LoadRequestedModules).

Evaluate()

JsModule.cs

Evaluates the module and its dependencies (Evaluate).

public JsValue Evaluate()

Returns

JsValue A promise fulfilled when the evaluation completes, rejected with the error of the evaluation.

GetNamespace()

JsModule.cs

Gets the namespace object of the module (GetModuleNamespace). The module must be linked.

public JsValue GetNamespace()

Returns

JsValue

LoadRequestedModules(object?)

JsModule.cs

Loads the dependencies of the module, recursively (LoadRequestedModules).

public JsValue LoadRequestedModules(object? hostDefined = null)

Parameters

hostDefined object?
A value given to the module loader for each module it loads.

Returns

JsValue A promise fulfilled when the whole graph is loaded, rejected when a module cannot be loaded.