JsHostObject Class

An object implemented by the host (e.g. a platform object of a browser): a derived class can override its internal methods (https://tc39.es/ecma262/#sec-object-internal-methods-and-internal-slots). The default implementations are the ones of an ordinary object, also available with the Ordinary* methods.

public class JsHostObject : JsObject
Inheritance
JsObject JsHostObject

Constructors

NameDescription
JsHostObject(JsObject?, object?)Creates a host object.
JsHostObject(JsObject?, object?, bool)Creates a host object, telling whether its internal methods are the ordinary ones.

JsHostObject overloads

JsHostObject(JsObject?, object?)

JsHostObject.cs

Creates a host object.

public JsHostObject(JsObject? prototype, object? target = null)
Parameters
prototype JsObject?
The prototype of the object, or null.
target object?
A .NET object associated with the JavaScript object (e.g. the platform object it exposes).

JsHostObject(JsObject?, object?, bool)

JsHostObject.cs

Creates a host object, telling whether its internal methods are the ordinary ones.

protected JsHostObject(JsObject? prototype, object? target, bool hasOrdinaryInternalMethods)
Parameters
prototype JsObject?
The prototype of the object, or null.
target object?
A .NET object associated with the JavaScript object (e.g. the platform object it exposes).
hasOrdinaryInternalMethods bool
true when the type of the object does not override the methods that read or write properties (JsHostObject.GetOwnPropertyCore, JsHostObject.DefineOwnPropertyCore, JsHostObject.HasPropertyCore, JsHostObject.GetCore, JsHostObject.SetCore, JsHostObject.DeleteCore, JsHostObject.OwnPropertyKeysCore, JsHostObject.GetPrototypeOfCore): the engine then reads and writes its properties with the fast paths of the ordinary objects (shapes and inline caches) instead of calling these methods.

Properties

NameDescription
HasCallInternalMethodGets or sets whether the object has a [[Call]] internal method, implemented by JsHostObject.CallCore (e.g. the legacy caller of document.all): typeof is "function" unless it is an [[IsHTMLDDA]] object. It has no [[Construct]].
HasErrorDataGets whether the object has an [[ErrorData]] internal slot (see JsHostObject.InitializeErrorData): Error.isError returns true for it, and the Error.prototype.stack getter returns its stack trace.
HasImmutablePrototypeGets or sets whether the prototype of the object cannot be changed (an immutable prototype exotic object, e.g. Object.prototype or a Window).
IsHtmlDdaObjectGets or sets whether the object is an [[IsHTMLDDA]] object (document.all): typeof is "undefined", and it is falsy and loosely equal to null.
ModuleSourceClassNameGets or sets the class name of a module source object ([[ModuleSourceClassName]], https://tc39.es/proposal-source-phase-imports/), e.g. WebAssembly.Module: the value of the %AbstractModuleSource%.prototype[@@toStringTag] getter for the object. Null when the object is not a module source (see JsModule.ModuleSource).
RejectsPrivateElementsGets or sets whether HostEnsureCanAddPrivateElement(O) (https://tc39.es/ecma262/#sec-hostensurecanaddprivateelement) throws a TypeError for the object: a class cannot add private fields, methods or accessors to it (e.g. a WindowProxy or a Location object, https://html.spec.whatwg.org/multipage/webappapis.html#the-hostensurecanaddprivateelement-implementation).
TargetGets the .NET object associated with the JavaScript object.

HasCallInternalMethod

JsHostObject.cs

Gets or sets whether the object has a [[Call]] internal method, implemented by JsHostObject.CallCore (e.g. the legacy caller of document.all): typeof is "function" unless it is an [[IsHTMLDDA]] object. It has no [[Construct]].

public bool HasCallInternalMethod { get; set; }

Property value

bool

HasErrorData

JsHostObject.cs

Gets whether the object has an [[ErrorData]] internal slot (see JsHostObject.InitializeErrorData): Error.isError returns true for it, and the Error.prototype.stack getter returns its stack trace.

public bool HasErrorData { get; }

Property value

bool

HasImmutablePrototype

JsHostObject.cs

Gets or sets whether the prototype of the object cannot be changed (an immutable prototype exotic object, e.g. Object.prototype or a Window).

public bool HasImmutablePrototype { get; set; }

Property value

bool

IsHtmlDdaObject

JsHostObject.cs

Gets or sets whether the object is an [[IsHTMLDDA]] object (document.all): typeof is "undefined", and it is falsy and loosely equal to null.

public bool IsHtmlDdaObject { get; set; }

Property value

bool

ModuleSourceClassName

JsHostObject.cs

Gets or sets the class name of a module source object ([[ModuleSourceClassName]], https://tc39.es/proposal-source-phase-imports/), e.g. WebAssembly.Module: the value of the %AbstractModuleSource%.prototype[@@toStringTag] getter for the object. Null when the object is not a module source (see JsModule.ModuleSource).

public string? ModuleSourceClassName { get; set; }

Property value

string?

RejectsPrivateElements

JsHostObject.cs

Gets or sets whether HostEnsureCanAddPrivateElement(O) (https://tc39.es/ecma262/#sec-hostensurecanaddprivateelement) throws a TypeError for the object: a class cannot add private fields, methods or accessors to it (e.g. a WindowProxy or a Location object, https://html.spec.whatwg.org/multipage/webappapis.html#the-hostensurecanaddprivateelement-implementation).

public bool RejectsPrivateElements { get; set; }

Property value

bool

Gets the .NET object associated with the JavaScript object.

public object? Target { get; }

Property value

object?

Methods

NameDescription
CallCore(JsValue, ReadOnlySpan<JsValue>)[[Call]], when JsHostObject.HasCallInternalMethod is true. It runs in the realm of the caller.
DefineOwnPropertyCore(JsPropertyKey, JsPropertyDescriptor)[[DefineOwnProperty]]
DeleteCore(JsPropertyKey)[[Delete]]
GetCore(JsPropertyKey, JsValue)[[Get]]
GetOwnPropertyCore(JsPropertyKey, JsPropertyDescriptor)[[GetOwnProperty]]
GetPrototypeOfCore()[[GetPrototypeOf]]
HasPropertyCore(JsPropertyKey)[[HasProperty]]
InitializeErrorData(string)Gives the object an [[ErrorData]] internal slot, as an error object (e.g. a DOMException, https://webidl.spec.whatwg.org/#es-DOMException-specialness), and sets its stack trace to the one of the running code, whose first line is header (e.g. "SyntaxError: message"). Call it in a scope of the engine (see JsEngine.Enter).
IsExtensibleCore()[[IsExtensible]]
OrdinaryDefineOwnProperty(JsPropertyKey, JsPropertyDescriptor)OrdinaryDefineOwnProperty (https://tc39.es/ecma262/#sec-ordinarydefineownproperty), bypassing the overrides.
OrdinaryDelete(JsPropertyKey)OrdinaryDelete (https://tc39.es/ecma262/#sec-ordinarydelete), bypassing the overrides.
OrdinaryGetOwnProperty(JsPropertyKey, JsPropertyDescriptor)OrdinaryGetOwnProperty (https://tc39.es/ecma262/#sec-ordinarygetownproperty), bypassing the overrides.
OrdinaryOwnPropertyKeys()OrdinaryOwnPropertyKeys (https://tc39.es/ecma262/#sec-ordinaryownpropertykeys), bypassing the overrides.
OwnPropertyKeysCore()[[OwnPropertyKeys]]
PreventExtensionsCore()[[PreventExtensions]]
SetCore(JsPropertyKey, JsValue, JsValue)[[Set]]
SetPrototypeOfCore(JsObject?)[[SetPrototypeOf]]

CallCore(JsValue, ReadOnlySpan<JsValue>)

JsHostObject.cs

[[Call]], when JsHostObject.HasCallInternalMethod is true. It runs in the realm of the caller.

protected virtual JsValue CallCore(JsValue thisValue, ReadOnlySpan<JsValue> arguments)

Parameters

thisValue JsValue
arguments ReadOnlySpan<JsValue>

Returns

JsValue

DefineOwnPropertyCore(JsPropertyKey, JsPropertyDescriptor)

JsHostObject.cs

[[DefineOwnProperty]]

protected virtual bool DefineOwnPropertyCore(JsPropertyKey key, in JsPropertyDescriptor descriptor)

Parameters

key JsPropertyKey
descriptor JsPropertyDescriptor

Returns

bool

DeleteCore(JsPropertyKey)

JsHostObject.cs

[[Delete]]

protected virtual bool DeleteCore(JsPropertyKey key)

Parameters

key JsPropertyKey

Returns

bool

GetCore(JsPropertyKey, JsValue)

JsHostObject.cs

[[Get]]

protected virtual JsValue GetCore(JsPropertyKey key, JsValue receiver)

Parameters

key JsPropertyKey
receiver JsValue

Returns

JsValue

GetOwnPropertyCore(JsPropertyKey, JsPropertyDescriptor)

JsHostObject.cs

[[GetOwnProperty]]

protected virtual bool GetOwnPropertyCore(JsPropertyKey key, out JsPropertyDescriptor descriptor)

Parameters

key JsPropertyKey
descriptor JsPropertyDescriptor

Returns

bool

GetPrototypeOfCore()

JsHostObject.cs

[[GetPrototypeOf]]

protected virtual JsObject? GetPrototypeOfCore()

Returns

JsObject?

HasPropertyCore(JsPropertyKey)

JsHostObject.cs

[[HasProperty]]

protected virtual bool HasPropertyCore(JsPropertyKey key)

Parameters

key JsPropertyKey

Returns

bool

InitializeErrorData(string)

JsHostObject.cs

Gives the object an [[ErrorData]] internal slot, as an error object (e.g. a DOMException, https://webidl.spec.whatwg.org/#es-DOMException-specialness), and sets its stack trace to the one of the running code, whose first line is header (e.g. "SyntaxError: message"). Call it in a scope of the engine (see JsEngine.Enter).

public void InitializeErrorData(string header)

Parameters

header string
The first line of the stack trace.

IsExtensibleCore()

JsHostObject.cs

[[IsExtensible]]

protected virtual bool IsExtensibleCore()

Returns

bool

OrdinaryDefineOwnProperty(JsPropertyKey, JsPropertyDescriptor)

JsHostObject.cs

OrdinaryDefineOwnProperty (https://tc39.es/ecma262/#sec-ordinarydefineownproperty), bypassing the overrides.

public bool OrdinaryDefineOwnProperty(JsPropertyKey key, in JsPropertyDescriptor descriptor)

Parameters

key JsPropertyKey
descriptor JsPropertyDescriptor

Returns

bool

OrdinaryDelete(JsPropertyKey)

JsHostObject.cs

OrdinaryDelete (https://tc39.es/ecma262/#sec-ordinarydelete), bypassing the overrides.

public bool OrdinaryDelete(JsPropertyKey key)

Parameters

key JsPropertyKey

Returns

bool

OrdinaryGetOwnProperty(JsPropertyKey, JsPropertyDescriptor)

JsHostObject.cs

OrdinaryGetOwnProperty (https://tc39.es/ecma262/#sec-ordinarygetownproperty), bypassing the overrides.

public bool OrdinaryGetOwnProperty(JsPropertyKey key, out JsPropertyDescriptor descriptor)

Parameters

key JsPropertyKey
descriptor JsPropertyDescriptor

Returns

bool

OrdinaryOwnPropertyKeys()

JsHostObject.cs

OrdinaryOwnPropertyKeys (https://tc39.es/ecma262/#sec-ordinaryownpropertykeys), bypassing the overrides.

public IReadOnlyList<JsPropertyKey> OrdinaryOwnPropertyKeys()

OwnPropertyKeysCore()

JsHostObject.cs

[[OwnPropertyKeys]]

protected virtual IReadOnlyList<JsPropertyKey> OwnPropertyKeysCore()

PreventExtensionsCore()

JsHostObject.cs

[[PreventExtensions]]

protected virtual bool PreventExtensionsCore()

Returns

bool

SetCore(JsPropertyKey, JsValue, JsValue)

JsHostObject.cs

[[Set]]

protected virtual bool SetCore(JsPropertyKey key, JsValue value, JsValue receiver)

Parameters

key JsPropertyKey
value JsValue
receiver JsValue

Returns

bool

SetPrototypeOfCore(JsObject?)

JsHostObject.cs

[[SetPrototypeOf]]

protected virtual bool SetPrototypeOfCore(JsObject? prototype)

Parameters

prototype JsObject?

Returns

bool