ModuleScript Class

A module script (https://html.spec.whatwg.org/multipage/webappapis.html#module-script): the root of a module graph, the script of a <script type="module"> element, whose descendants are loaded and that is run by the ScriptEngine (see ScriptEngine.LoadModuleScriptGraph and ScriptEngine.ExecuteModuleScript).

public sealed class ModuleScript

Constructors

NameDescription
ModuleScript(GlobalScope, string, string)Creates a module script.

ModuleScript(GlobalScope, string, string)

ModuleScript.cs

Creates a module script.

public ModuleScript(GlobalScope global, string sourceText, string baseUrl)

Parameters

global GlobalScope
The global object of the realm in which the script runs.
sourceText string
The source text of the script.
baseUrl string
The base URL of the script: the URL of an external script, or the base URL of the document of an inline script.

Properties

NameDescription
BaseUrlGets the base URL of the script, used to resolve its module specifiers and as import.meta.url.
ElementGets the script element whose script this is.
ErrorToRethrowGets or sets the error to rethrow (https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-error-to-rethrow): a parse error, or an error of the module graph, reported when the script runs. Set by the engine.
FetchOptionsGets the options used to fetch the descendants of the script (https://html.spec.whatwg.org/multipage/webappapis.html#descendant-script-fetch-options).
GlobalGets the global object of the realm of the script.
IsInlineGets whether the script is an inline script (its source text is the child text content of the element).
RecordGets or sets the record of the script in the engine (e.g. its module record). Set by the engine.
SourceTextGets the source text of the script.
SourceTextColumnGets the column (0-based, in UTF-16 code units) of the start of the source text in its line (see ModuleScript.SourceTextLine).
SourceTextLineGets the line (1-based) of the start of the source text in the document of an inline script: the line numbers of its errors are the lines in the document. The default value is 1.
UrlGets the URL of the script, used as the file name of the errors: the URL of an external script, or the URL of the document of an inline script.

Gets the base URL of the script, used to resolve its module specifiers and as import.meta.url.

public string BaseUrl { get; }

Property value

string

Gets the script element whose script this is.

public Element? Element { get; init; }

Property value

Element?

ErrorToRethrow

ModuleScript.cs

Gets or sets the error to rethrow (https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-error-to-rethrow): a parse error, or an error of the module graph, reported when the script runs. Set by the engine.

public object? ErrorToRethrow { get; set; }

Property value

object?

FetchOptions

ModuleScript.cs

Gets the options used to fetch the descendants of the script (https://html.spec.whatwg.org/multipage/webappapis.html#descendant-script-fetch-options).

public ModuleFetchOptions FetchOptions { get; init; }

Property value

ModuleFetchOptions

Gets the global object of the realm of the script.

public GlobalScope Global { get; }

Property value

GlobalScope

Gets whether the script is an inline script (its source text is the child text content of the element).

public bool IsInline { get; init; }

Property value

bool

Gets or sets the record of the script in the engine (e.g. its module record). Set by the engine.

public object? Record { get; set; }

Property value

object?

SourceText

ModuleScript.cs

Gets the source text of the script.

public string SourceText { get; }

Property value

string

SourceTextColumn

ModuleScript.cs

Gets the column (0-based, in UTF-16 code units) of the start of the source text in its line (see ModuleScript.SourceTextLine).

public int SourceTextColumn { get; init; }

Property value

int

SourceTextLine

ModuleScript.cs

Gets the line (1-based) of the start of the source text in the document of an inline script: the line numbers of its errors are the lines in the document. The default value is 1.

public int SourceTextLine { get; init; }

Property value

int

Gets the URL of the script, used as the file name of the errors: the URL of an external script, or the URL of the document of an inline script.

public string Url { get; init; }

Property value

string