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
JsObjectJsHostObject
Constructors
| Name | Description |
|---|---|
| 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.csJsHostObject(JsObject?, object?, bool)
JsHostObject.csCreates a host object, telling whether its internal methods are the ordinary ones.
Parameters
prototypeJsObject?- The prototype of the object, or null.
targetobject?- A .NET object associated with the JavaScript object (e.g. the platform object it exposes).
hasOrdinaryInternalMethodsbooltruewhen 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
| Name | Description |
|---|---|
| HasCallInternalMethod | 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]]. |
| HasErrorData | 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. |
| HasImmutablePrototype | Gets or sets whether the prototype of the object cannot be changed (an immutable prototype exotic object, e.g. Object.prototype or a Window). |
| IsHtmlDdaObject | Gets or sets whether the object is an [[IsHTMLDDA]] object (document.all): typeof is "undefined", and it is falsy and loosely equal to null. |
| ModuleSourceClassName | 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). |
| RejectsPrivateElements | 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). |
| Target | Gets the .NET object associated with the JavaScript object. |
HasCallInternalMethod
JsHostObject.csGets 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
HasErrorData
JsHostObject.csGets 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
HasImmutablePrototype
JsHostObject.csIsHtmlDdaObject
JsHostObject.csModuleSourceClassName
JsHostObject.csGets 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
RejectsPrivateElements
JsHostObject.csGets 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
Target
JsHostObject.csMethods
| Name | Description |
|---|---|
| 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)DefineOwnPropertyCore(JsPropertyKey, JsPropertyDescriptor)
JsHostObject.cs[[DefineOwnProperty]]
protected virtual bool DefineOwnPropertyCore(JsPropertyKey key, in JsPropertyDescriptor descriptor)DeleteCore(JsPropertyKey)
JsHostObject.cs[[Delete]]
protected virtual bool DeleteCore(JsPropertyKey key)GetCore(JsPropertyKey, JsValue)
JsHostObject.cs[[Get]]
protected virtual JsValue GetCore(JsPropertyKey key, JsValue receiver)GetOwnPropertyCore(JsPropertyKey, JsPropertyDescriptor)
JsHostObject.cs[[GetOwnProperty]]
protected virtual bool GetOwnPropertyCore(JsPropertyKey key, out JsPropertyDescriptor descriptor)GetPrototypeOfCore()
JsHostObject.csHasPropertyCore(JsPropertyKey)
JsHostObject.cs[[HasProperty]]
protected virtual bool HasPropertyCore(JsPropertyKey key)InitializeErrorData(string)
JsHostObject.csGives 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).
Parameters
headerstring- The first line of the stack trace.
IsExtensibleCore()
JsHostObject.csOrdinaryDefineOwnProperty(JsPropertyKey, JsPropertyDescriptor)
JsHostObject.csOrdinaryDefineOwnProperty (https://tc39.es/ecma262/#sec-ordinarydefineownproperty), bypassing the overrides.
public bool OrdinaryDefineOwnProperty(JsPropertyKey key, in JsPropertyDescriptor descriptor)OrdinaryDelete(JsPropertyKey)
JsHostObject.csOrdinaryDelete (https://tc39.es/ecma262/#sec-ordinarydelete), bypassing the overrides.
public bool OrdinaryDelete(JsPropertyKey key)OrdinaryGetOwnProperty(JsPropertyKey, JsPropertyDescriptor)
JsHostObject.csOrdinaryGetOwnProperty (https://tc39.es/ecma262/#sec-ordinarygetownproperty), bypassing the overrides.
public bool OrdinaryGetOwnProperty(JsPropertyKey key, out JsPropertyDescriptor descriptor)OrdinaryOwnPropertyKeys()
JsHostObject.csOrdinaryOwnPropertyKeys (https://tc39.es/ecma262/#sec-ordinaryownpropertykeys), bypassing the overrides.
public IReadOnlyList<JsPropertyKey> OrdinaryOwnPropertyKeys()Returns
OwnPropertyKeysCore()
JsHostObject.csPreventExtensionsCore()
JsHostObject.csSetCore(JsPropertyKey, JsValue, JsValue)
JsHostObject.cs[[Set]]
protected virtual bool SetCore(JsPropertyKey key, JsValue value, JsValue receiver)