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 JsHostConstructors
| Name | Description |
|---|---|
| JsHost() |
JsHost()
public JsHost()No documentation is available.
Methods
| Name | Description |
|---|---|
| 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.csHostCallJobCallback(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
engineJsEnginehostDefinedobjectcontinuationJsContinuation
CallJobCallback(JsEngine, JsJobCallback, JsValue, ReadOnlySpan<JsValue>)
JsJob.csHostCallJobCallback(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
engineJsEnginejobCallbackJsJobCallbackthisValueJsValueargumentsReadOnlySpan<JsValue>
Returns
EnqueueGenericJob(JsEngine, JsHostJob)
JsJob.csHostEnqueueGenericJob(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)
JsJob.csHostEnqueueTimeoutJob(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)
JsJob.csHostEnsureCanCompileStrings: 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
engineJsEnginerealmJsRealmparameterStringsIReadOnlyList<string>bodyStringstringcodeStringstringcompilationTypeJsCompilationTypeparameterArgsIReadOnlyList<JsValue>bodyArgJsValue
GetCodeForEval(JsEngine, JsValue)
JsJob.csMakeContinuationHostDefined(JsEngine)
JsJob.csHostMakeJobCallback(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)
JsJob.csHostMakeJobCallback(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)PromiseRejectionTracker(JsEngine, JsObject, JsPromiseRejectionOperation)
JsJob.csHostPromiseRejectionTracker(promise, operation). The default implementation does nothing.
public virtual void PromiseRejectionTracker(JsEngine engine, JsObject promise, JsPromiseRejectionOperation operation)Parameters
engineJsEnginepromiseJsObjectoperationJsPromiseRejectionOperation
ReportJobException(JsEngine, JsException)
JsJob.csReports 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
engineJsEngineexceptionJsException