WebIdlRealm<TAdapter, TValue> Class

The realm of a global object (https://html.spec.whatwg.org/multipage/webappapis.html#realms-settings-objects-global-objects): its global object is a window or the global object of a worker, and its interface objects expose the interfaces of the platform that are exposed in the global object. The interface objects of a realm are created on first use.

public sealed class WebIdlRealm<TAdapter, TValue> where TAdapter : struct, IJsAdapter<TValue> where TValue : class

Type parameters

TAdapter
The adapter of the JavaScript engine.
TValue
The type of the JavaScript values of the engine.

Properties

NameDescription
AdapterGets the adapter of the engine.
AgentGets the bindings of the engine.
EngineRealmGets the realm of the engine.
FunctionPrototypeGets Function.prototype of the realm.
GlobalGets the global object of the realm.
GlobalScopeGets the .NET global object (a window or the global object of a worker), whose JavaScript object is the global object of the realm.
ObjectPrototypeGets Object.prototype of the realm.
WindowGets the window when the global object of the realm is a window, else null.

Gets the adapter of the engine.

public TAdapter Adapter { get; }

Property value

TAdapter

Gets the bindings of the engine.

public WebIdlAgent<TAdapter, TValue> Agent { get; }

EngineRealm

WebIdlRealm.cs

Gets the realm of the engine.

public object EngineRealm { get; }

Property value

object

FunctionPrototype

WebIdlRealm.cs

Gets Function.prototype of the realm.

public TValue FunctionPrototype { get; }

Property value

TValue

Gets the global object of the realm.

public TValue Global { get; }

Property value

TValue

GlobalScope

WebIdlRealm.cs

Gets the .NET global object (a window or the global object of a worker), whose JavaScript object is the global object of the realm.

public GlobalScope GlobalScope { get; }

Property value

GlobalScope

ObjectPrototype

WebIdlRealm.cs

Gets Object.prototype of the realm.

public TValue ObjectPrototype { get; }

Property value

TValue

Gets the window when the global object of the realm is a window, else null.

public Window? Window { get; }

Property value

Window?

Methods

NameDescription
CreateError(string, string)Creates an error object of this realm (e.g. TypeError).
CreateEventHandlerCallback(TValue, bool)Creates the value of an event handler whose function is function (e.g. a compiled event handler content attribute).
CreateRangeError(string)Returns the exception that throws a RangeError of this realm.
CreateTypeError(string)Returns the exception that throws a TypeError of this realm.
Evaluate(string)Evaluates code in the realm, as an indirect eval. It does not run the pending jobs.
FromDate(DateTime?)Returns the Date object of a date and time; null is a Date object whose time value is NaN (an "Invalid Date").
GetInterfaceObject(string)Returns the interface object of an interface, creating it in this realm.
GetPrototype(string)Returns the interface prototype object of an interface, creating it in this realm.
GetWindowProxy(Window)Returns the WindowProxy of the browsing context of a window (https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy): one object per browsing context, shared by the realms of the agent, whose [[Window]] is the active window of the browsing context, so that it is the same object before and after a navigation (e.g. the window returned by window.open() and the source of the messages of the documents it navigates to). It is the value of a window for every realm, also the this value of the scripts of the window and the value of globalThis.
GetWrapper(object, TValue?)Returns the JavaScript object of a .NET platform object.
Run<TResult>(Func<TResult>)Runs code with this realm as the current realm, and its global object as the current global object.
ToDomString(TValue)https://webidl.spec.whatwg.org/#js-DOMString
ToJs(object?)Converts a .NET value to a JavaScript value, using its runtime type (for the IDL type any).
ToJsError(Exception)Returns the JavaScript value of a .NET exception thrown by the DOM.
ToJsException(Exception)Converts a .NET exception thrown by the DOM to the JavaScript exception a browser would throw.
Unwrap(TValue)Returns the .NET object of a JavaScript platform object (or the window of a global object), or null.

CreateError(string, string)

WebIdlRealm.cs

Creates an error object of this realm (e.g. TypeError).

public TValue CreateError(string constructorName, string message)

Parameters

constructorName string
message string

Returns

TValue

CreateEventHandlerCallback(TValue, bool)

WebIdlRealm.Callbacks.cs

Creates the value of an event handler whose function is function (e.g. a compiled event handler content attribute).

public EventHandlerCallback CreateEventHandlerCallback(TValue function, bool isOnBeforeUnloadEventHandler)

Parameters

function TValue
isOnBeforeUnloadEventHandler bool

Returns

EventHandlerCallback

CreateRangeError(string)

WebIdlRealm.cs

Returns the exception that throws a RangeError of this realm.

public Exception CreateRangeError(string message)

Parameters

message string

Returns

Exception

CreateTypeError(string)

WebIdlRealm.cs

Returns the exception that throws a TypeError of this realm.

public Exception CreateTypeError(string message)

Parameters

message string

Returns

Exception

Evaluate(string)

WebIdlRealm.cs

Evaluates code in the realm, as an indirect eval. It does not run the pending jobs.

public TValue Evaluate(string code)

Parameters

code string

Returns

TValue

FromDate(DateTime?)

WebIdlRealm.cs

Returns the Date object of a date and time; null is a Date object whose time value is NaN (an "Invalid Date").

public TValue FromDate(DateTime? dateTime)

Parameters

dateTime DateTime?

Returns

TValue

GetInterfaceObject(string)

WebIdlRealm.cs

Returns the interface object of an interface, creating it in this realm.

public TValue GetInterfaceObject(string interfaceName)

Parameters

interfaceName string

Returns

TValue

GetPrototype(string)

WebIdlRealm.cs

Returns the interface prototype object of an interface, creating it in this realm.

public TValue GetPrototype(string interfaceName)

Parameters

interfaceName string

Returns

TValue

GetWindowProxy(Window)

WebIdlRealm.WindowProxy.cs

Returns the WindowProxy of the browsing context of a window (https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy): one object per browsing context, shared by the realms of the agent, whose [[Window]] is the active window of the browsing context, so that it is the same object before and after a navigation (e.g. the window returned by window.open() and the source of the messages of the documents it navigates to). It is the value of a window for every realm, also the this value of the scripts of the window and the value of globalThis.

public TValue GetWindowProxy(Window window)

Parameters

window Window

Returns

TValue

Remarks

When the window is not same origin-domain with the realm of the caller, the internal methods are the ones of the cross-origin objects (only the cross-origin properties are visible, the others throw a "SecurityError" DOMException). A window that never had a browsing context (e.g. the window of a document created by DOMParser) has no WindowProxy: its global object is returned, as when the engine does not support the WindowProxy objects.

GetWrapper(object, TValue?)

WebIdlRealm.cs

Returns the JavaScript object of a .NET platform object.

public TValue GetWrapper(object target, TValue? prototype = null)

Parameters

target object
prototype TValue?

Returns

TValue

Run<TResult>(Func<TResult>)

WebIdlRealm.cs

Runs code with this realm as the current realm, and its global object as the current global object.

public TResult Run<TResult>(Func<TResult> action)

Type parameters

TResult

Parameters

action Func<TResult>

Returns

TResult

ToDomString(TValue)

WebIdlRealm.Conversions.cs

https://webidl.spec.whatwg.org/#js-DOMString

public string ToDomString(TValue value)

Parameters

value TValue

Returns

string

ToJs(object?)

WebIdlRealm.cs

Converts a .NET value to a JavaScript value, using its runtime type (for the IDL type any).

public TValue ToJs(object? value)

Parameters

value object?

Returns

TValue

ToJsError(Exception)

WebIdlRealm.cs

Returns the JavaScript value of a .NET exception thrown by the DOM.

public TValue ToJsError(Exception exception)

Parameters

exception Exception

Returns

TValue

ToJsException(Exception)

WebIdlRealm.cs

Converts a .NET exception thrown by the DOM to the JavaScript exception a browser would throw.

public Exception ToJsException(Exception exception)

Parameters

exception Exception

Returns

Exception

Unwrap(TValue)

WebIdlRealm.cs

Returns the .NET object of a JavaScript platform object (or the window of a global object), or null.

public object? Unwrap(TValue value)

Parameters

value TValue

Returns

object?