IJsAdapter<TValue> Interface

The primitives of a JavaScript engine used by the WebIDL bindings (WebIdlAgent<TAdapter, TValue>). An engine exposes the DOM by implementing this interface with a struct: the bindings are generic over the adapter (where TAdapter : struct, IJsAdapter<TValue>), so the JIT specializes them for each engine (no boxing, no interface dispatch).

public interface IJsAdapter<TValue> where TValue : class

Type parameters

TValue
The type of the JavaScript values of the engine (e.g. object for Meziantou.Framework.JavaScriptEngine).

Remarks

The operations that can run JavaScript code (IJsAdapter<TValue>.ToNumber, IJsAdapter<TValue>.Get, IJsAdapter<TValue>.Call...) throw the exceptions of the engine; IJsAdapter<TValue>.TryGetThrownValue converts them back to JavaScript values.

Realms are represented by opaque objects (IJsAdapter<TValue>.CurrentRealm). The objects and functions created by the adapter belong to the current realm: the bindings use IJsAdapter<TValue>.RunInRealm to create them in the realm of a window.

Identity: the bindings compare the JavaScript objects by reference and cache data per object (the wrappers of the callbacks, the custom element constructors...), so the adapter must return the same TValue instance for the same JavaScript object. TValue may be Object (e.g. when the values of the engine are .NET strings and numbers).

Versioning: new primitives are added to this interface as default interface members implemented with the existing primitives, so that the existing adapters keep compiling; an engine overrides them for performance.

Properties

NameDescription
CurrentRealmGets the realm of the running execution context.
NullGets the null value.
UndefinedGets the undefined value.

CurrentRealm

Gets the realm of the running execution context.

object CurrentRealm { get; }

Property value

object

Null

Gets the null value.

TValue Null { get; }

Property value

TValue

Undefined

Gets the undefined value.

TValue Undefined { get; }

Property value

TValue

Methods

NameDescription
AsBoolean(TValue)Returns the value of a boolean.
AsDate(TValue)Returns the time value of a Date object (milliseconds since the Unix epoch, or NaN).
AsNumber(TValue)Returns the value of a number.
AsString(TValue)Returns the value of a string.
Call(TValue, TValue, ReadOnlySpan<TValue>)[[Call]] (https://tc39.es/ecma262/#sec-call).
Construct(TValue, ReadOnlySpan<TValue>, TValue)[[Construct]] (https://tc39.es/ecma262/#sec-construct).
CreateArray(ReadOnlySpan<TValue>)Creates an array in the current realm.
CreateArrayBuffer(ReadOnlySpan<byte>)Creates an ArrayBuffer containing a copy of bytes in the current realm. The default implementation constructs it with the ArrayBuffer and Uint8Array constructors of the global object.
CreateArrayBufferView(JsBufferKind, TValue, int, int)Creates a typed array or a DataView (kind) of length elements viewing buffer from byteOffset, in the current realm. The default implementation calls the constructor of the global object.
CreateArrayBufferWithData(byte[], string)Creates an ArrayBuffer in the current realm whose data block is data (the bytes are shared, not copied), and whose [[ArrayBufferDetachKey]] is detachKey: it cannot be transferred or detached by scripts (e.g. the buffer of a WebAssembly.Memory). Returns null when the engine does not support it. The default implementation returns null.
CreateConstructor(string, int, JsHostConstructor<TValue>)Creates a built-in function object that is a constructor in the current realm (e.g. an interface object, https://webidl.spec.whatwg.org/#interface-object): its name and length properties are set, it has no prototype property, and Function.prototype.toString returns its NativeFunction representation (function name() { [native code] }). [[Call]] and [[Construct]] call constructor; NewTarget is undefined for [[Call]]. The default implementation returns a Proxy of a script function.
CreateCrossOriginPlatformObject(TValue, object, IJsCrossOriginObjectHandler<TValue>)Creates the JavaScript object of a cross-origin platform object (a Location object, https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface) in the current realm: its prototype cannot be changed, it cannot be made non-extensible, and its internal methods are the cross-origin ones of handler when the current realm is not same origin-domain with the object. Returns null when the engine does not support it (the object is then created by IJsAdapter<TValue>.CreatePlatformObject, and only its members check the origin of their caller). The default implementation returns null.
CreateDate(double)Creates a Date object in the current realm.
CreateException(TValue)Returns the .NET exception that throws value in the engine.
CreateFunction(string, int, JsHostFunction<TValue>)Creates a built-in function object in the current realm (https://tc39.es/ecma262/#sec-createbuiltinfunction): its name and length properties are set, it is not a constructor, and it has no prototype property.
CreateHtmlDdaPlatformObject(TValue, object, IJsHostObjectHandler<TValue>, JsHostFunction<TValue>)Creates the JavaScript object of a .NET platform object in the current realm, as IJsAdapter<TValue>.CreatePlatformObject with a handler, that also has a [[Call]] internal method (call) and an [[IsHTMLDDA]] internal slot (https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot): document.all, whose typeof is "undefined", that is falsy and loosely equal to null and undefined. The default implementation returns a Proxy of a function whose target is a platform object: it is not an [[IsHTMLDDA]] object, and IJsAdapter<TValue>.TryGetPlatformObject does not return its .NET object.
CreateObject(TValue)Creates an ordinary object in the current realm, whose prototype is prototype (an object or null).
CreatePlatformObject(TValue, object, IJsHostObjectHandler<TValue>?)Creates the JavaScript object of a .NET platform object in the current realm. When handler is not null, the object is a host exotic object whose internal methods call the handler first (the legacy platform objects).
CreateSharedArrayBuffer(object)Creates a SharedArrayBuffer in the current realm whose data block is a data block returned by IJsAdapter<TValue>.GetSharedDataBlock (of any engine instance of the adapter), so that the buffers share their memory. Returns null when it is not supported (the bindings then use IJsAdapter<TValue>.SetSharedDataBlock). The default implementation returns null.
CreateWindowProxy(IJsWindowProxyHandler<TValue>)Creates a WindowProxy exotic object (https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-windowproxy-exotic-object) whose internal methods are implemented with handler. It belongs to no realm. Returns null when the engine does not support it: a window is then exposed by its global object. The default implementation returns null.
DefineLazyAccessorProperty(TValue, TValue, IJsLazyAccessor<TValue>, bool, bool, bool)Defines an accessor property whose functions are created on first access by factory (one object per property instead of closures: the attributes of the interfaces are defined this way). The default implementation calls IJsAdapter<TValue>.DefineLazyAccessorProperty.
DefineLazyAccessorProperty(TValue, TValue, Func<TValue>, Func<TValue>?, bool, bool)Defines an accessor property whose functions are created on first access (e.g. the attributes of the interfaces, most of which are never used). setterFactory is null when the property has no setter. The default implementation creates the functions immediately.
DefineLazyDataProperty(TValue, TValue, IJsLazyValue<TValue>, bool, bool, bool)Defines a data property whose value is created on first access by factory (one object per property instead of a closure: the interface objects of a realm are defined this way). The default implementation calls IJsAdapter<TValue>.DefineLazyDataProperty.
DefineLazyDataProperty(TValue, TValue, Func<TValue>, bool, bool, bool)Defines a data property whose value is created on first access (e.g. the interface objects of the global object, most of which are never used). The default implementation creates the value immediately.
DefineOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)[[DefineOwnProperty]] (https://tc39.es/ecma262/#sec-definepropertyorthrow). Returns false on failure.
Delete(TValue, TValue)[[Delete]].
DetachArrayBuffer(TValue)Detaches an ArrayBuffer created by IJsAdapter<TValue>.CreateArrayBufferWithData (DetachArrayBuffer with its detach key).
Evaluate(object, string)Evaluates code in a realm, as an indirect eval (https://tc39.es/ecma262/#sec-performeval). It does not run the jobs.
EvaluateBuiltIn(object, string)Evaluates a script of the implementation (a constant source text, e.g. Fetch.js) in a realm, as IJsAdapter<TValue>.Evaluate: the adapter may parse it once for all the realms. It does not run the jobs. The default implementation calls IJsAdapter<TValue>.Evaluate.
FromBigInt(BigInteger)Creates a BigInt value.
FromBoolean(bool)Creates a boolean value.
FromNumber(double)Creates a number value.
FromString(string)Creates a string value.
Get(TValue, TValue)[[Get]] (https://tc39.es/ecma262/#sec-get-o-p). key is a string or a symbol.
GetAbstractModuleSource()Returns %AbstractModuleSource% of the current realm (https://tc39.es/proposal-source-phase-imports/#sec-abstractmodulesource-objects), which the interface object of WebAssembly.Module extends (https://webassembly.github.io/esm-integration/js-api/index.html#webassembly-module-objects), or null when the engine does not implement the source phase imports: the interface then extends nothing. The default implementation returns null.
GetErrorInformation(TValue)Returns the information of an error value: its message, file name, line and column.
GetGlobalObject(object)Gets the global object of a realm.
GetOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)[[GetOwnProperty]]. Returns false when the property does not exist.
GetPropertyCount(TValue)Gets the number of own properties of an object, without running code: the bindings remember the sizes of the objects they create, and call IJsAdapter<TValue>.ReserveProperties with them in the next realms. The default implementation returns 0 (unknown).
GetPrototypeOf(TValue)[[GetPrototypeOf]].
GetSharedDataBlock(TValue)Returns the shared data block of a SharedArrayBuffer ([[ArrayBufferData]]), an opaque object that IJsAdapter<TValue>.SetSharedDataBlock can give to another SharedArrayBuffer of any engine instance of the adapter (possibly on another thread), so that they share their memory (the structured serialization of the SharedArrayBuffer objects). Returns null for other values, or when the engine cannot share the memory of its buffers. The default implementation returns null.
GetWellKnownSymbol(JsWellKnownSymbol)Returns a well-known symbol (https://tc39.es/ecma262/#sec-well-known-symbols).
HasInternalSlot(TValue, JsInternalSlot)Returns whether a value is an object that has an internal slot, or null when the adapter cannot tell: the structured serialization then calls the intrinsic function that reads the slot, which throws when the slot is missing (a thrown exception is slow, and most objects are ordinary objects). The default implementation returns null.
HasProperty(TValue, TValue)[[HasProperty]].
IsArray(TValue)Gets whether the value is an Array exotic object (https://tc39.es/ecma262/#sec-array-exotic-objects), not a Proxy of an array.
IsBigInt(TValue)Gets whether the value is a BigInt.
IsBoolean(TValue)Gets whether the value is a boolean.
IsCallable(TValue)Gets whether the value is callable (https://tc39.es/ecma262/#sec-iscallable).
IsConstructor(TValue)Gets whether the value is a constructor (https://tc39.es/ecma262/#sec-isconstructor).
IsCurrentRealm(object)Returns whether realm is the realm of the running execution context.
IsDate(TValue)Gets whether the value is a Date object.
IsNull(TValue)Gets whether the value is null.
IsNumber(TValue)Gets whether the value is a number.
IsObject(TValue)Gets whether the value is an object (including functions).
IsResizableBuffer(TValue)Gets whether a buffer source is backed by a resizable ArrayBuffer or a growable SharedArrayBuffer (the buffer itself, or the buffer that a view views), which the buffer source types reject unless they have the [AllowResizable] extended attribute (https://webidl.spec.whatwg.org/#AllowResizable). The default implementation returns false: the resizable buffers are accepted.
IsRevokedProxy(TValue, TValue?)Whether the value is a revoked proxy (its [[GetPrototypeOf]] throws). objectPrototype is the %Object.prototype% of the realm in which the proxy was created, or null when the engine does not track it.
IsString(TValue)Gets whether the value is a string.
IsSymbol(TValue)Gets whether the value is a symbol.
IsTerminationException(Exception)Returns whether an exception aborts the running script (e.g. the termination of a worker): it is not a JavaScript exception, and is not converted by the DOM. The default implementation returns false.
IsUndefined(TValue)Gets whether the value is undefined.
IsValue(object)Returns whether a .NET object is a value of the engine, and not another .NET object given to the bindings (e.g. a platform object or a list, which the bindings convert). The default implementation tests whether it is a TValue: an adapter whose values have no specific type (e.g. TValue is Object) overrides it.
OrdinaryDefineOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)OrdinaryDefineOwnProperty (https://tc39.es/ecma262/#sec-ordinarydefineownproperty) of a host exotic object.
OrdinaryDelete(TValue, TValue)OrdinaryDelete (https://tc39.es/ecma262/#sec-ordinarydelete) of a host exotic object.
OrdinaryGetOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)Performs an ordinary internal method of a host exotic object, bypassing its IJsHostObjectHandler<TValue> (e.g. OrdinaryGetOwnProperty, https://tc39.es/ecma262/#sec-ordinarygetownproperty).
OrdinaryOwnKeys(TValue)OrdinaryOwnPropertyKeys (https://tc39.es/ecma262/#sec-ordinaryownpropertykeys) of a host exotic object.
OwnKeys(TValue)[[OwnPropertyKeys]]: the strings and symbols.
ReserveProperties(TValue, int)Prepares an object for count more properties (e.g. the interface objects of a global object), so that an engine can allocate their storage once. It does not change the behavior of the object. The default implementation does nothing.
RunInRealm<TResult>(object, Func<TResult>)Runs action with realm as the current realm.
Set(TValue, TValue, TValue)[[Set]] (https://tc39.es/ecma262/#sec-set-o-p-v-throw), throwing a TypeError on failure.
SetModuleSourceClassName(TValue, string)Sets the [[ModuleSourceClassName]] internal slot of a platform object created by IJsAdapter<TValue>.CreatePlatformObject (e.g. WebAssembly.Module), read by the %AbstractModuleSource%.prototype[@@toStringTag] getter. The default implementation does nothing.
SetPrototypeOf(TValue, TValue)[[SetPrototypeOf]].
SetSharedDataBlock(TValue, object)Replaces the data block of a new SharedArrayBuffer of the same byte length by a data block returned by IJsAdapter<TValue>.GetSharedDataBlock. Returns false when it is not supported. The default implementation returns false.
ToBigInt(TValue)https://tc39.es/ecma262/#sec-tobigint
ToBoolean(TValue)https://tc39.es/ecma262/#sec-toboolean
ToNumber(TValue)https://tc39.es/ecma262/#sec-tonumber
ToString(TValue)https://tc39.es/ecma262/#sec-tostring (throws a TypeError for a symbol).
TryGetBufferSource(TValue, JsBufferKind, bool, Memory<byte>)Gets the kind and the bytes of an ArrayBuffer, a SharedArrayBuffer, a typed array or a DataView (the objects with an [[ArrayBufferData]], [[TypedArrayName]] or [[DataView]] internal slot), without running JavaScript code. bytes is a view of the data block of the buffer, so that the writes are visible to JavaScript; it is empty when the buffer is detached. isShared is true when the buffer (or the viewed buffer) is a SharedArrayBuffer. Returns false for other values. The default implementation returns false: the buffer source types cannot be converted.
TryGetPlatformObject(TValue, object?)Returns the .NET object of a JavaScript platform object created by IJsAdapter<TValue>.CreatePlatformObject.
TryGetThrownValue(Exception, TValue?)Returns the JavaScript value thrown by an exception of the engine, or false for another exception.
TryInitializeErrorData(TValue, string)Gives a platform object created by IJsAdapter<TValue>.CreatePlatformObject an [[ErrorData]] internal slot: a DOMException (https://webidl.spec.whatwg.org/#es-DOMException-specialness), for which Error.isError returns true. The engine also sets its stack trace to the one of the running code, whose first line is stackHeader, read by the Error.prototype.stack accessor (https://tc39.es/proposal-error-stack-accessor/). Returns false when the engine does not support it: the object then gets an own stack data property. The default implementation returns false.
TryMakePrototypeImmutable(TValue)Makes an object an immutable prototype exotic object (https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects), if the engine supports it: its [[SetPrototypeOf]] only accepts its current prototype. A proxy is left unchanged (its handler defines its [[SetPrototypeOf]]). Returns false when the engine does not support it: the bindings then replace the built-in functions that change prototypes (see WebIdlRealm<TAdapter, TValue>). The default implementation returns false.
TrySetErrorStack(TValue, string)Sets the [[Stack]] internal slot of an error (https://tc39.es/proposal-error-stack-accessor/), read by the Error.prototype.stack accessor: the stack of a deserialized error (https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize). Returns false when the engine has no such slot (the stack is then an own data property of the error). The default implementation returns false.
TrySetGlobalThis(object, TValue)Sets the this value of the global code of a realm (its [[GlobalThisValue]], also the value of globalThis): the WindowProxy of a window. Returns false when the engine does not support it (the this value is then the global object). The default implementation returns false.

AsBoolean(TValue)

Returns the value of a boolean.

bool AsBoolean(TValue value)

Parameters

value TValue

Returns

bool

AsDate(TValue)

Returns the time value of a Date object (milliseconds since the Unix epoch, or NaN).

double AsDate(TValue value)

Parameters

value TValue

Returns

double

AsNumber(TValue)

Returns the value of a number.

double AsNumber(TValue value)

Parameters

value TValue

Returns

double

AsString(TValue)

Returns the value of a string.

string AsString(TValue value)

Parameters

value TValue

Returns

string

Call(TValue, TValue, ReadOnlySpan<TValue>)

[[Call]] (https://tc39.es/ecma262/#sec-call).

TValue Call(TValue function, TValue thisValue, ReadOnlySpan<TValue> arguments)

Parameters

function TValue
thisValue TValue
arguments ReadOnlySpan<TValue>

Returns

TValue

Construct(TValue, ReadOnlySpan<TValue>, TValue)

[[Construct]] (https://tc39.es/ecma262/#sec-construct).

TValue Construct(TValue constructor, ReadOnlySpan<TValue> arguments, TValue newTarget)

Parameters

constructor TValue
arguments ReadOnlySpan<TValue>
newTarget TValue

Returns

TValue

CreateArray(ReadOnlySpan<TValue>)

Creates an array in the current realm.

TValue CreateArray(ReadOnlySpan<TValue> items)

Parameters

items ReadOnlySpan<TValue>

Returns

TValue

CreateArrayBuffer(ReadOnlySpan<byte>)

IJsAdapter.cs

Creates an ArrayBuffer containing a copy of bytes in the current realm. The default implementation constructs it with the ArrayBuffer and Uint8Array constructors of the global object.

public TValue CreateArrayBuffer(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

Returns

TValue

CreateArrayBufferView(JsBufferKind, TValue, int, int)

IJsAdapter.cs

Creates a typed array or a DataView (kind) of length elements viewing buffer from byteOffset, in the current realm. The default implementation calls the constructor of the global object.

public TValue CreateArrayBufferView(JsBufferKind kind, TValue buffer, int byteOffset, int length)

Parameters

kind JsBufferKind
buffer TValue
byteOffset int
length int

Returns

TValue

CreateArrayBufferWithData(byte[], string)

IJsAdapter.cs

Creates an ArrayBuffer in the current realm whose data block is data (the bytes are shared, not copied), and whose [[ArrayBufferDetachKey]] is detachKey: it cannot be transferred or detached by scripts (e.g. the buffer of a WebAssembly.Memory). Returns null when the engine does not support it. The default implementation returns null.

public TValue? CreateArrayBufferWithData(byte[] data, string detachKey)

Parameters

data byte[]
detachKey string

Returns

TValue?

CreateConstructor(string, int, JsHostConstructor<TValue>)

IJsAdapter.cs

Creates a built-in function object that is a constructor in the current realm (e.g. an interface object, https://webidl.spec.whatwg.org/#interface-object): its name and length properties are set, it has no prototype property, and Function.prototype.toString returns its NativeFunction representation (function name() { [native code] }). [[Call]] and [[Construct]] call constructor; NewTarget is undefined for [[Call]]. The default implementation returns a Proxy of a script function.

public TValue CreateConstructor(string name, int length, JsHostConstructor<TValue> constructor)

Parameters

name string
length int
constructor JsHostConstructor<TValue>

Returns

TValue

CreateCrossOriginPlatformObject(TValue, object, IJsCrossOriginObjectHandler<TValue>)

IJsAdapter.cs

Creates the JavaScript object of a cross-origin platform object (a Location object, https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface) in the current realm: its prototype cannot be changed, it cannot be made non-extensible, and its internal methods are the cross-origin ones of handler when the current realm is not same origin-domain with the object. Returns null when the engine does not support it (the object is then created by IJsAdapter<TValue>.CreatePlatformObject, and only its members check the origin of their caller). The default implementation returns null.

public TValue? CreateCrossOriginPlatformObject(TValue prototype, object target, IJsCrossOriginObjectHandler<TValue> handler)

Parameters

prototype TValue
target object
handler IJsCrossOriginObjectHandler<TValue>

Returns

TValue?

CreateDate(double)

Creates a Date object in the current realm.

TValue CreateDate(double timeValue)

Parameters

timeValue double

Returns

TValue

CreateException(TValue)

Returns the .NET exception that throws value in the engine.

Exception CreateException(TValue value)

Parameters

value TValue

Returns

Exception

CreateFunction(string, int, JsHostFunction<TValue>)

Creates a built-in function object in the current realm (https://tc39.es/ecma262/#sec-createbuiltinfunction): its name and length properties are set, it is not a constructor, and it has no prototype property.

TValue CreateFunction(string name, int length, JsHostFunction<TValue> function)

Parameters

name string
length int
function JsHostFunction<TValue>

Returns

TValue

CreateHtmlDdaPlatformObject(TValue, object, IJsHostObjectHandler<TValue>, JsHostFunction<TValue>)

IJsAdapter.cs

Creates the JavaScript object of a .NET platform object in the current realm, as IJsAdapter<TValue>.CreatePlatformObject with a handler, that also has a [[Call]] internal method (call) and an [[IsHTMLDDA]] internal slot (https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot): document.all, whose typeof is "undefined", that is falsy and loosely equal to null and undefined. The default implementation returns a Proxy of a function whose target is a platform object: it is not an [[IsHTMLDDA]] object, and IJsAdapter<TValue>.TryGetPlatformObject does not return its .NET object.

public TValue CreateHtmlDdaPlatformObject(TValue prototype, object target, IJsHostObjectHandler<TValue> handler, JsHostFunction<TValue> call)

Parameters

prototype TValue
target object
handler IJsHostObjectHandler<TValue>
call JsHostFunction<TValue>

Returns

TValue

CreateObject(TValue)

Creates an ordinary object in the current realm, whose prototype is prototype (an object or null).

TValue CreateObject(TValue prototype)

Parameters

prototype TValue

Returns

TValue

CreatePlatformObject(TValue, object, IJsHostObjectHandler<TValue>?)

Creates the JavaScript object of a .NET platform object in the current realm. When handler is not null, the object is a host exotic object whose internal methods call the handler first (the legacy platform objects).

TValue CreatePlatformObject(TValue prototype, object target, IJsHostObjectHandler<TValue>? handler)

Parameters

prototype TValue
target object
handler IJsHostObjectHandler<TValue>?

Returns

TValue

CreateSharedArrayBuffer(object)

IJsAdapter.cs

Creates a SharedArrayBuffer in the current realm whose data block is a data block returned by IJsAdapter<TValue>.GetSharedDataBlock (of any engine instance of the adapter), so that the buffers share their memory. Returns null when it is not supported (the bindings then use IJsAdapter<TValue>.SetSharedDataBlock). The default implementation returns null.

public TValue? CreateSharedArrayBuffer(object dataBlock)

Parameters

dataBlock object

Returns

TValue?

CreateWindowProxy(IJsWindowProxyHandler<TValue>)

IJsAdapter.cs

Creates a WindowProxy exotic object (https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-windowproxy-exotic-object) whose internal methods are implemented with handler. It belongs to no realm. Returns null when the engine does not support it: a window is then exposed by its global object. The default implementation returns null.

public TValue? CreateWindowProxy(IJsWindowProxyHandler<TValue> handler)

Parameters

handler IJsWindowProxyHandler<TValue>

Returns

TValue?

DefineLazyAccessorProperty overloads

DefineLazyAccessorProperty(TValue, TValue, IJsLazyAccessor<TValue>, bool, bool, bool)

IJsAdapter.cs

Defines an accessor property whose functions are created on first access by factory (one object per property instead of closures: the attributes of the interfaces are defined this way). The default implementation calls IJsAdapter<TValue>.DefineLazyAccessorProperty.

public void DefineLazyAccessorProperty(TValue obj, TValue key, IJsLazyAccessor<TValue> factory, bool hasSetter, bool enumerable, bool configurable)
Parameters
obj TValue
key TValue
factory IJsLazyAccessor<TValue>
hasSetter bool
enumerable bool
configurable bool

DefineLazyAccessorProperty(TValue, TValue, Func<TValue>, Func<TValue>?, bool, bool)

IJsAdapter.cs

Defines an accessor property whose functions are created on first access (e.g. the attributes of the interfaces, most of which are never used). setterFactory is null when the property has no setter. The default implementation creates the functions immediately.

public void DefineLazyAccessorProperty(TValue obj, TValue key, Func<TValue> getterFactory, Func<TValue>? setterFactory, bool enumerable, bool configurable)
Parameters
obj TValue
key TValue
getterFactory Func<TValue>
setterFactory Func<TValue>?
enumerable bool
configurable bool

DefineLazyDataProperty overloads

DefineLazyDataProperty(TValue, TValue, IJsLazyValue<TValue>, bool, bool, bool)

IJsAdapter.cs

Defines a data property whose value is created on first access by factory (one object per property instead of a closure: the interface objects of a realm are defined this way). The default implementation calls IJsAdapter<TValue>.DefineLazyDataProperty.

public void DefineLazyDataProperty(TValue obj, TValue key, IJsLazyValue<TValue> factory, bool writable, bool enumerable, bool configurable)
Parameters
obj TValue
key TValue
factory IJsLazyValue<TValue>
writable bool
enumerable bool
configurable bool

DefineLazyDataProperty(TValue, TValue, Func<TValue>, bool, bool, bool)

IJsAdapter.cs

Defines a data property whose value is created on first access (e.g. the interface objects of the global object, most of which are never used). The default implementation creates the value immediately.

public void DefineLazyDataProperty(TValue obj, TValue key, Func<TValue> factory, bool writable, bool enumerable, bool configurable)
Parameters
obj TValue
key TValue
factory Func<TValue>
writable bool
enumerable bool
configurable bool

DefineOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)

[[DefineOwnProperty]] (https://tc39.es/ecma262/#sec-definepropertyorthrow). Returns false on failure.

bool DefineOwnProperty(TValue obj, TValue key, in JsPropertyDescriptor<TValue> descriptor)

Parameters

obj TValue
key TValue
descriptor JsPropertyDescriptor<TValue>

Returns

bool

Delete(TValue, TValue)

[[Delete]].

bool Delete(TValue obj, TValue key)

Parameters

obj TValue
key TValue

Returns

bool

DetachArrayBuffer(TValue)

IJsAdapter.cs

Detaches an ArrayBuffer created by IJsAdapter<TValue>.CreateArrayBufferWithData (DetachArrayBuffer with its detach key).

public void DetachArrayBuffer(TValue arrayBuffer)

Parameters

arrayBuffer TValue

Evaluate(object, string)

Evaluates code in a realm, as an indirect eval (https://tc39.es/ecma262/#sec-performeval). It does not run the jobs.

TValue Evaluate(object realm, string code)

Parameters

realm object
code string

Returns

TValue

EvaluateBuiltIn(object, string)

IJsAdapter.cs

Evaluates a script of the implementation (a constant source text, e.g. Fetch.js) in a realm, as IJsAdapter<TValue>.Evaluate: the adapter may parse it once for all the realms. It does not run the jobs. The default implementation calls IJsAdapter<TValue>.Evaluate.

public TValue EvaluateBuiltIn(object realm, string code)

Parameters

realm object
code string

Returns

TValue

FromBigInt(BigInteger)

Creates a BigInt value.

TValue FromBigInt(BigInteger value)

Parameters

value BigInteger

Returns

TValue

FromBoolean(bool)

Creates a boolean value.

TValue FromBoolean(bool value)

Parameters

value bool

Returns

TValue

FromNumber(double)

Creates a number value.

TValue FromNumber(double value)

Parameters

value double

Returns

TValue

FromString(string)

Creates a string value.

TValue FromString(string value)

Parameters

value string

Returns

TValue

Get(TValue, TValue)

[[Get]] (https://tc39.es/ecma262/#sec-get-o-p). key is a string or a symbol.

TValue Get(TValue obj, TValue key)

Parameters

obj TValue
key TValue

Returns

TValue

GetAbstractModuleSource()

IJsAdapter.cs
  • Experimental (WEBPLATEXP0014)

Returns %AbstractModuleSource% of the current realm (https://tc39.es/proposal-source-phase-imports/#sec-abstractmodulesource-objects), which the interface object of WebAssembly.Module extends (https://webassembly.github.io/esm-integration/js-api/index.html#webassembly-module-objects), or null when the engine does not implement the source phase imports: the interface then extends nothing. The default implementation returns null.

[Experimental("WEBPLATEXP0014", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public TValue? GetAbstractModuleSource()

Returns

TValue?

GetErrorInformation(TValue)

Returns the information of an error value: its message, file name, line and column.

JsErrorInformation GetErrorInformation(TValue error)

Parameters

error TValue

Returns

JsErrorInformation

GetGlobalObject(object)

Gets the global object of a realm.

TValue GetGlobalObject(object realm)

Parameters

realm object

Returns

TValue

GetOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)

[[GetOwnProperty]]. Returns false when the property does not exist.

bool GetOwnProperty(TValue obj, TValue key, out JsPropertyDescriptor<TValue> descriptor)

Parameters

obj TValue
key TValue
descriptor JsPropertyDescriptor<TValue>

Returns

bool

GetPropertyCount(TValue)

IJsAdapter.cs

Gets the number of own properties of an object, without running code: the bindings remember the sizes of the objects they create, and call IJsAdapter<TValue>.ReserveProperties with them in the next realms. The default implementation returns 0 (unknown).

public int GetPropertyCount(TValue obj)

Parameters

obj TValue

Returns

int

GetPrototypeOf(TValue)

[[GetPrototypeOf]].

TValue GetPrototypeOf(TValue obj)

Parameters

obj TValue

Returns

TValue

GetSharedDataBlock(TValue)

IJsAdapter.cs

Returns the shared data block of a SharedArrayBuffer ([[ArrayBufferData]]), an opaque object that IJsAdapter<TValue>.SetSharedDataBlock can give to another SharedArrayBuffer of any engine instance of the adapter (possibly on another thread), so that they share their memory (the structured serialization of the SharedArrayBuffer objects). Returns null for other values, or when the engine cannot share the memory of its buffers. The default implementation returns null.

public object? GetSharedDataBlock(TValue sharedArrayBuffer)

Parameters

sharedArrayBuffer TValue

Returns

object?

GetWellKnownSymbol(JsWellKnownSymbol)

Returns a well-known symbol (https://tc39.es/ecma262/#sec-well-known-symbols).

TValue GetWellKnownSymbol(JsWellKnownSymbol symbol)

Parameters

symbol JsWellKnownSymbol

Returns

TValue

HasInternalSlot(TValue, JsInternalSlot)

IJsAdapter.cs

Returns whether a value is an object that has an internal slot, or null when the adapter cannot tell: the structured serialization then calls the intrinsic function that reads the slot, which throws when the slot is missing (a thrown exception is slow, and most objects are ordinary objects). The default implementation returns null.

public bool? HasInternalSlot(TValue value, JsInternalSlot slot)

Parameters

value TValue
slot JsInternalSlot

Returns

bool?

HasProperty(TValue, TValue)

[[HasProperty]].

bool HasProperty(TValue obj, TValue key)

Parameters

obj TValue
key TValue

Returns

bool

IsArray(TValue)

Gets whether the value is an Array exotic object (https://tc39.es/ecma262/#sec-array-exotic-objects), not a Proxy of an array.

bool IsArray(TValue value)

Parameters

value TValue

Returns

bool

IsBigInt(TValue)

Gets whether the value is a BigInt.

bool IsBigInt(TValue value)

Parameters

value TValue

Returns

bool

IsBoolean(TValue)

Gets whether the value is a boolean.

bool IsBoolean(TValue value)

Parameters

value TValue

Returns

bool

IsCallable(TValue)

Gets whether the value is callable (https://tc39.es/ecma262/#sec-iscallable).

bool IsCallable(TValue value)

Parameters

value TValue

Returns

bool

IsConstructor(TValue)

Gets whether the value is a constructor (https://tc39.es/ecma262/#sec-isconstructor).

bool IsConstructor(TValue value)

Parameters

value TValue

Returns

bool

IsCurrentRealm(object)

IJsAdapter.cs

Returns whether realm is the realm of the running execution context.

public bool IsCurrentRealm(object realm)

Parameters

realm object

Returns

bool

IsDate(TValue)

Gets whether the value is a Date object.

bool IsDate(TValue value)

Parameters

value TValue

Returns

bool

IsNull(TValue)

Gets whether the value is null.

bool IsNull(TValue value)

Parameters

value TValue

Returns

bool

IsNumber(TValue)

Gets whether the value is a number.

bool IsNumber(TValue value)

Parameters

value TValue

Returns

bool

IsObject(TValue)

Gets whether the value is an object (including functions).

bool IsObject(TValue value)

Parameters

value TValue

Returns

bool

IsResizableBuffer(TValue)

IJsAdapter.cs

Gets whether a buffer source is backed by a resizable ArrayBuffer or a growable SharedArrayBuffer (the buffer itself, or the buffer that a view views), which the buffer source types reject unless they have the [AllowResizable] extended attribute (https://webidl.spec.whatwg.org/#AllowResizable). The default implementation returns false: the resizable buffers are accepted.

public bool IsResizableBuffer(TValue value)

Parameters

value TValue

Returns

bool

IsRevokedProxy(TValue, TValue?)

IJsAdapter.cs

Whether the value is a revoked proxy (its [[GetPrototypeOf]] throws). objectPrototype is the %Object.prototype% of the realm in which the proxy was created, or null when the engine does not track it.

public bool IsRevokedProxy(TValue value, out TValue? objectPrototype)

Parameters

value TValue
objectPrototype TValue?

Returns

bool

IsString(TValue)

Gets whether the value is a string.

bool IsString(TValue value)

Parameters

value TValue

Returns

bool

IsSymbol(TValue)

Gets whether the value is a symbol.

bool IsSymbol(TValue value)

Parameters

value TValue

Returns

bool

IsTerminationException(Exception)

IJsAdapter.cs

Returns whether an exception aborts the running script (e.g. the termination of a worker): it is not a JavaScript exception, and is not converted by the DOM. The default implementation returns false.

public bool IsTerminationException(Exception exception)

Parameters

exception Exception

Returns

bool

IsUndefined(TValue)

Gets whether the value is undefined.

bool IsUndefined(TValue value)

Parameters

value TValue

Returns

bool

IsValue(object)

IJsAdapter.cs

Returns whether a .NET object is a value of the engine, and not another .NET object given to the bindings (e.g. a platform object or a list, which the bindings convert). The default implementation tests whether it is a TValue: an adapter whose values have no specific type (e.g. TValue is Object) overrides it.

public bool IsValue(object value)

Parameters

value object

Returns

bool

OrdinaryDefineOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)

OrdinaryDefineOwnProperty (https://tc39.es/ecma262/#sec-ordinarydefineownproperty) of a host exotic object.

bool OrdinaryDefineOwnProperty(TValue obj, TValue key, in JsPropertyDescriptor<TValue> descriptor)

Parameters

obj TValue
key TValue
descriptor JsPropertyDescriptor<TValue>

Returns

bool

OrdinaryDelete(TValue, TValue)

OrdinaryDelete (https://tc39.es/ecma262/#sec-ordinarydelete) of a host exotic object.

bool OrdinaryDelete(TValue obj, TValue key)

Parameters

obj TValue
key TValue

Returns

bool

OrdinaryGetOwnProperty(TValue, TValue, JsPropertyDescriptor<TValue>)

Performs an ordinary internal method of a host exotic object, bypassing its IJsHostObjectHandler<TValue> (e.g. OrdinaryGetOwnProperty, https://tc39.es/ecma262/#sec-ordinarygetownproperty).

bool OrdinaryGetOwnProperty(TValue obj, TValue key, out JsPropertyDescriptor<TValue> descriptor)

Parameters

obj TValue
key TValue
descriptor JsPropertyDescriptor<TValue>

Returns

bool

OrdinaryOwnKeys(TValue)

OrdinaryOwnPropertyKeys (https://tc39.es/ecma262/#sec-ordinaryownpropertykeys) of a host exotic object.

IReadOnlyList<TValue> OrdinaryOwnKeys(TValue obj)

Parameters

obj TValue

Returns

IReadOnlyList<TValue>

OwnKeys(TValue)

[[OwnPropertyKeys]]: the strings and symbols.

IReadOnlyList<TValue> OwnKeys(TValue obj)

Parameters

obj TValue

Returns

IReadOnlyList<TValue>

ReserveProperties(TValue, int)

IJsAdapter.cs

Prepares an object for count more properties (e.g. the interface objects of a global object), so that an engine can allocate their storage once. It does not change the behavior of the object. The default implementation does nothing.

public void ReserveProperties(TValue obj, int count)

Parameters

obj TValue
count int

RunInRealm<TResult>(object, Func<TResult>)

Runs action with realm as the current realm.

TResult RunInRealm<TResult>(object realm, Func<TResult> action)

Type parameters

TResult

Parameters

realm object
action Func<TResult>

Returns

TResult

Set(TValue, TValue, TValue)

[[Set]] (https://tc39.es/ecma262/#sec-set-o-p-v-throw), throwing a TypeError on failure.

void Set(TValue obj, TValue key, TValue value)

Parameters

obj TValue
key TValue
value TValue

SetModuleSourceClassName(TValue, string)

IJsAdapter.cs
  • Experimental (WEBPLATEXP0014)

Sets the [[ModuleSourceClassName]] internal slot of a platform object created by IJsAdapter<TValue>.CreatePlatformObject (e.g. WebAssembly.Module), read by the %AbstractModuleSource%.prototype[@@toStringTag] getter. The default implementation does nothing.

[Experimental("WEBPLATEXP0014", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void SetModuleSourceClassName(TValue obj, string className)

Parameters

obj TValue
className string

SetPrototypeOf(TValue, TValue)

[[SetPrototypeOf]].

bool SetPrototypeOf(TValue obj, TValue prototype)

Parameters

obj TValue
prototype TValue

Returns

bool

SetSharedDataBlock(TValue, object)

IJsAdapter.cs

Replaces the data block of a new SharedArrayBuffer of the same byte length by a data block returned by IJsAdapter<TValue>.GetSharedDataBlock. Returns false when it is not supported. The default implementation returns false.

public bool SetSharedDataBlock(TValue sharedArrayBuffer, object dataBlock)

Parameters

sharedArrayBuffer TValue
dataBlock object

Returns

bool

ToBigInt(TValue)

https://tc39.es/ecma262/#sec-tobigint

BigInteger ToBigInt(TValue value)

Parameters

value TValue

Returns

BigInteger

ToBoolean(TValue)

https://tc39.es/ecma262/#sec-toboolean

bool ToBoolean(TValue value)

Parameters

value TValue

Returns

bool

ToNumber(TValue)

https://tc39.es/ecma262/#sec-tonumber

double ToNumber(TValue value)

Parameters

value TValue

Returns

double

ToString(TValue)

https://tc39.es/ecma262/#sec-tostring (throws a TypeError for a symbol).

string ToString(TValue value)

Parameters

value TValue

Returns

string

TryGetBufferSource(TValue, JsBufferKind, bool, Memory<byte>)

IJsAdapter.cs

Gets the kind and the bytes of an ArrayBuffer, a SharedArrayBuffer, a typed array or a DataView (the objects with an [[ArrayBufferData]], [[TypedArrayName]] or [[DataView]] internal slot), without running JavaScript code. bytes is a view of the data block of the buffer, so that the writes are visible to JavaScript; it is empty when the buffer is detached. isShared is true when the buffer (or the viewed buffer) is a SharedArrayBuffer. Returns false for other values. The default implementation returns false: the buffer source types cannot be converted.

public bool TryGetBufferSource(TValue value, out JsBufferKind kind, out bool isShared, out Memory<byte> bytes)

Parameters

value TValue
kind JsBufferKind
isShared bool
bytes Memory<byte>

Returns

bool

TryGetPlatformObject(TValue, object?)

Returns the .NET object of a JavaScript platform object created by IJsAdapter<TValue>.CreatePlatformObject.

bool TryGetPlatformObject(TValue value, out object? target)

Parameters

value TValue
target object?

Returns

bool

TryGetThrownValue(Exception, TValue?)

Returns the JavaScript value thrown by an exception of the engine, or false for another exception.

bool TryGetThrownValue(Exception exception, out TValue? value)

Parameters

exception Exception
value TValue?

Returns

bool

TryInitializeErrorData(TValue, string)

IJsAdapter.cs

Gives a platform object created by IJsAdapter<TValue>.CreatePlatformObject an [[ErrorData]] internal slot: a DOMException (https://webidl.spec.whatwg.org/#es-DOMException-specialness), for which Error.isError returns true. The engine also sets its stack trace to the one of the running code, whose first line is stackHeader, read by the Error.prototype.stack accessor (https://tc39.es/proposal-error-stack-accessor/). Returns false when the engine does not support it: the object then gets an own stack data property. The default implementation returns false.

public bool TryInitializeErrorData(TValue obj, string stackHeader)

Parameters

obj TValue
stackHeader string

Returns

bool

TryMakePrototypeImmutable(TValue)

IJsAdapter.cs

Makes an object an immutable prototype exotic object (https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects), if the engine supports it: its [[SetPrototypeOf]] only accepts its current prototype. A proxy is left unchanged (its handler defines its [[SetPrototypeOf]]). Returns false when the engine does not support it: the bindings then replace the built-in functions that change prototypes (see WebIdlRealm<TAdapter, TValue>). The default implementation returns false.

public bool TryMakePrototypeImmutable(TValue obj)

Parameters

obj TValue

Returns

bool

TrySetErrorStack(TValue, string)

IJsAdapter.cs
  • Experimental (WEBPLATEXP0011)

Sets the [[Stack]] internal slot of an error (https://tc39.es/proposal-error-stack-accessor/), read by the Error.prototype.stack accessor: the stack of a deserialized error (https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize). Returns false when the engine has no such slot (the stack is then an own data property of the error). The default implementation returns false.

[Experimental("WEBPLATEXP0011", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public bool TrySetErrorStack(TValue error, string stack)

Parameters

error TValue
stack string

Returns

bool

TrySetGlobalThis(object, TValue)

IJsAdapter.cs

Sets the this value of the global code of a realm (its [[GlobalThisValue]], also the value of globalThis): the WindowProxy of a window. Returns false when the engine does not support it (the this value is then the global object). The default implementation returns false.

public bool TrySetGlobalThis(object realm, TValue thisValue)

Parameters

realm object
thisValue TValue

Returns

bool