JsHost Class

The host-defined operations of the engine (https://tc39.es/ecma262/#sec-host-hooks-summary). The default implementations are the ones of the specification; a host (e.g. a browser) derives from this class to integrate the engine with its event loop, and sets it in JsEngineOptions.Host.

public class JsHost

Constructors

NameDescription
JsHost()

JsHost()

public JsHost()

No documentation is available.

Methods

NameDescription
CallContinuation(JsEngine, object, JsContinuation)HostCallJobCallback(jobCallback, V, argumentsList) for the handlers created by the engine whose [[HostDefined]] value (JsHost.MakeContinuationHostDefined) is not null: calls JsContinuation.Invoke, restoring the host-defined state.
CallJobCallback(JsEngine, JsJobCallback, JsValue, ReadOnlySpan<JsValue>)HostCallJobCallback(jobCallback, V, argumentsList): calls the callback, restoring the host-defined state captured by JsHost.MakeJobCallback.
EnqueueGenericJob(JsEngine, JsHostJob)HostEnqueueGenericJob(job, realm): e.g. the cleanup of a FinalizationRegistry, or the resolution of the promise of Atomics.waitAsync. It can be called from any thread (the finalizer thread, the thread of another agent). The default implementation adds the job to the queue of the engine: JsEngine.RunJobs runs it.
EnqueueTimeoutJob(JsEngine, JsHostJob, TimeSpan)HostEnqueueTimeoutJob(timeoutJob, realm, milliseconds): e.g. the timeout of Atomics.waitAsync. The default implementation runs the job from JsEngine.RunJobs once the delay has elapsed (measured with the JsEngineOptions.TimeProvider).
EnsureCanCompileStrings(JsEngine, JsRealm, IReadOnlyList<string>, string, string, JsCompilationType, IReadOnlyList<JsValue>, JsValue)HostEnsureCanCompileStrings: throws (e.g. an EvalError) when the host forbids the compilation of the code (a content security policy).
GetCodeForEval(JsEngine, JsValue)HostGetCodeForEval(argument): the code of a value given to eval (a string; the host may accept other objects, e.g. a TrustedScript), or null.
MakeContinuationHostDefined(JsEngine)HostMakeJobCallback(callback) for the handlers that the engine creates without a function object (the continuations of await, of the async generators, of the module loading...): returns the [[HostDefined]] value, which JsHost.CallContinuation restores when the handler runs, or null when there is no state to restore (the default: the handler is then called directly).
MakeJobCallback(JsEngine, JsObject)HostMakeJobCallback(callback): called when a callback is registered (e.g. by then), to capture a host-defined state (e.g. the incumbent settings object).
PromiseRejectionTracker(JsEngine, JsObject, JsPromiseRejectionOperation)HostPromiseRejectionTracker(promise, operation). The default implementation does nothing.
ReportJobException(JsEngine, JsException)Reports the exception thrown by a job (HostReportErrors). The default implementation rethrows it: it propagates out of JsEngine.RunJobs, and the other jobs stay in the queue.

CallContinuation(JsEngine, object, JsContinuation)

JsJob.cs

HostCallJobCallback(jobCallback, V, argumentsList) for the handlers created by the engine whose [[HostDefined]] value (JsHost.MakeContinuationHostDefined) is not null: calls JsContinuation.Invoke, restoring the host-defined state.

public virtual void CallContinuation(JsEngine engine, object hostDefined, JsContinuation continuation)

Parameters

engine JsEngine
hostDefined object
continuation JsContinuation

CallJobCallback(JsEngine, JsJobCallback, JsValue, ReadOnlySpan<JsValue>)

JsJob.cs

HostCallJobCallback(jobCallback, V, argumentsList): calls the callback, restoring the host-defined state captured by JsHost.MakeJobCallback.

public virtual JsValue CallJobCallback(JsEngine engine, in JsJobCallback jobCallback, JsValue thisValue, ReadOnlySpan<JsValue> arguments)

Parameters

engine JsEngine
jobCallback JsJobCallback
thisValue JsValue
arguments ReadOnlySpan<JsValue>

Returns

JsValue

EnqueueGenericJob(JsEngine, JsHostJob)

JsJob.cs

HostEnqueueGenericJob(job, realm): e.g. the cleanup of a FinalizationRegistry, or the resolution of the promise of Atomics.waitAsync. It can be called from any thread (the finalizer thread, the thread of another agent). The default implementation adds the job to the queue of the engine: JsEngine.RunJobs runs it.

public virtual void EnqueueGenericJob(JsEngine engine, JsHostJob job)

Parameters

engine JsEngine
job JsHostJob

EnqueueTimeoutJob(JsEngine, JsHostJob, TimeSpan)

JsJob.cs

HostEnqueueTimeoutJob(timeoutJob, realm, milliseconds): e.g. the timeout of Atomics.waitAsync. The default implementation runs the job from JsEngine.RunJobs once the delay has elapsed (measured with the JsEngineOptions.TimeProvider).

public virtual void EnqueueTimeoutJob(JsEngine engine, JsHostJob job, TimeSpan delay)

Parameters

engine JsEngine
job JsHostJob
delay TimeSpan

EnsureCanCompileStrings(JsEngine, JsRealm, IReadOnlyList<string>, string, string, JsCompilationType, IReadOnlyList<JsValue>, JsValue)

JsJob.cs

HostEnsureCanCompileStrings: throws (e.g. an EvalError) when the host forbids the compilation of the code (a content security policy).

public virtual void EnsureCanCompileStrings(JsEngine engine, JsRealm realm, IReadOnlyList<string> parameterStrings, string bodyString, string codeString, JsCompilationType compilationType, IReadOnlyList<JsValue> parameterArgs, JsValue bodyArg)

Parameters

engine JsEngine
realm JsRealm
parameterStrings IReadOnlyList<string>
bodyString string
codeString string
compilationType JsCompilationType
parameterArgs IReadOnlyList<JsValue>
bodyArg JsValue

GetCodeForEval(JsEngine, JsValue)

JsJob.cs

HostGetCodeForEval(argument): the code of a value given to eval (a string; the host may accept other objects, e.g. a TrustedScript), or null.

public virtual string? GetCodeForEval(JsEngine engine, JsValue argument)

Parameters

engine JsEngine
argument JsValue

Returns

string?

MakeContinuationHostDefined(JsEngine)

JsJob.cs

HostMakeJobCallback(callback) for the handlers that the engine creates without a function object (the continuations of await, of the async generators, of the module loading...): returns the [[HostDefined]] value, which JsHost.CallContinuation restores when the handler runs, or null when there is no state to restore (the default: the handler is then called directly).

public virtual object? MakeContinuationHostDefined(JsEngine engine)

Parameters

engine JsEngine

Returns

object?

MakeJobCallback(JsEngine, JsObject)

JsJob.cs

HostMakeJobCallback(callback): called when a callback is registered (e.g. by then), to capture a host-defined state (e.g. the incumbent settings object).

public virtual JsJobCallback MakeJobCallback(JsEngine engine, JsObject callback)

Parameters

engine JsEngine
callback JsObject

Returns

JsJobCallback

PromiseRejectionTracker(JsEngine, JsObject, JsPromiseRejectionOperation)

JsJob.cs

HostPromiseRejectionTracker(promise, operation). The default implementation does nothing.

public virtual void PromiseRejectionTracker(JsEngine engine, JsObject promise, JsPromiseRejectionOperation operation)

Parameters

engine JsEngine
promise JsObject
operation JsPromiseRejectionOperation

ReportJobException(JsEngine, JsException)

JsJob.cs

Reports the exception thrown by a job (HostReportErrors). The default implementation rethrows it: it propagates out of JsEngine.RunJobs, and the other jobs stay in the queue.

public virtual void ReportJobException(JsEngine engine, JsException exception)

Parameters

engine JsEngine
exception JsException