ScriptEngine Class
A JavaScript engine plugged into the browsing contexts (BrowsingContextOptions.ScriptEngine). The library never executes scripts by itself: it implements the processing model of the HTML Standard (script elements, event handlers, javascript: URLs, error reporting, the event loop) and calls the engine at the points the standard defines, so the engine only runs code.
public abstract class ScriptEngineRemarks
Each Window is the global object of a realm of the engine (https://html.spec.whatwg.org/multipage/webappapis.html#realms-settings-objects-global-objects). The windows of the browsing contexts that share the same options (a top-level browsing context and its nested browsing contexts) belong to the same agent (https://html.spec.whatwg.org/multipage/webappapis.html#similar-origin-window-agent): the engine may share the objects between their realms.
All the methods are called on the thread of the DomEventLoop of the browsing contexts. Each worker has its own engine (ScriptEngine.CreateWorkerScriptEngine), used on the thread of the worker.
Constructors
| Name | Description |
|---|---|
| ScriptEngine() |
ScriptEngine()
protected ScriptEngine()No documentation is available.
Properties
| Name | Description |
|---|---|
| IsScriptRunning | Gets whether a script is running, i.e. whether the JavaScript execution context stack is not empty. The library performs a microtask checkpoint after running a script or a callback only when no script is running (https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-script). |
| SupportsModuleScripts | Gets whether the engine supports the module scripts (<script type="module">, import()). When it is false (the default), the module scripts are not fetched nor run. |
IsScriptRunning
Gets whether a script is running, i.e. whether the JavaScript execution context stack is not empty. The library performs a microtask checkpoint after running a script or a callback only when no script is running (https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-script).
protected internal abstract bool IsScriptRunning { get; }Property value
SupportsModuleScripts
ScriptEngine.csMethods
| Name | Description |
|---|---|
| CompileEventHandler(EventHandlerSource) | Compiles the value of an event handler content attribute (e.g. onclick="..."), the first time the event handler is used (https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler). |
| CreateRealm(GlobalScope) | Creates the realm whose global object is global (https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-browsing-context). It is called when a new window is created for a browsing context, before its document becomes the active document, and when the script of a worker is fetched (on the thread of the worker, with the engine returned by ScriptEngine.CreateWorkerScriptEngine). An engine may create the realm lazily, when a script first runs in it. |
| CreateWorkerScriptEngine(CancellationToken) | Creates the script engine of a new worker (https://html.spec.whatwg.org/multipage/workers.html#run-a-worker): each dedicated or shared worker is a new agent, whose event loop runs on its own thread, so it needs its own engine. The method is called on the thread of the worker, before ScriptEngine.CreateRealm is called with the WorkerGlobalScope of the worker; the engine is then only used on that thread, and is disposed (when it implements IDisposable) when the worker ends. |
| DestroyRealm(GlobalScope) | Called when the browsing context of a window is discarded (e.g. its iframe is removed from the document, or it navigates to another document), or when a worker ends: the realm no longer runs scripts, and the engine may release it. |
| EnterNestedMicrotaskQueue() | Enters a separate microtask queue: until the returned scope is disposed, the jobs of the engine and the microtasks queued with ScriptEngine.QueueMicrotask go to a new queue, which ScriptEngine.PerformMicrotaskCheckpoint runs; the microtasks that were pending are kept, and are not run in the scope. The scopes nest. A script is considered running in the scope (ScriptEngine.IsScriptRunning): the callbacks invoked in it perform no microtask checkpoint. |
| ExecuteClassicScript(ClassicScript) | Runs a classic script (https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script) in the realm of ClassicScript.Global. The library owns the ordering of the scripts and the "clean up after running script" steps: the engine only evaluates the code. |
| ExecuteModuleScript(ModuleScript) | Runs a module script (https://html.spec.whatwg.org/multipage/webappapis.html#run-a-module-script): links and evaluates the module graph, and reports the error to rethrow or the evaluation errors (including the errors of a top-level await) to the global object. |
| ExtractErrorInformation(object?) | Extracts the information of an exception (https://html.spec.whatwg.org/multipage/webappapis.html#extract-error): its message, the location of the script, and the value of the error attribute of the ErrorEvent. |
| FetchModuleScriptGraph(GlobalScope, string, ModuleFetchOptions, Element?, Action<ModuleScript?>) | Fetches the graph of an external module script ("fetch a module script graph", https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree): the root is fetched ("fetch a single module script"), then its descendants are loaded. onComplete is called with the module script, or with null when a module of the graph cannot be fetched. A parse error is stored in ModuleScript.ErrorToRethrow. |
| GetActiveScriptBaseUrl() | Returns the base URL of the active script (https://html.spec.whatwg.org/multipage/webappapis.html#active-script), or null when no script is running: the base URL of the strings compiled by setTimeout() and setInterval(). |
| GetActiveScriptFetchOptions() | Returns the fetch options of the active script (https://html.spec.whatwg.org/multipage/webappapis.html#active-script), or null when no script is running: the options of the modules imported by import() in a classic script. |
| GetCurrentGlobal() | Returns the global object of the current realm (https://tc39.es/ecma262/#current-realm), or null when no script is running: the realm of the running function (e.g. the realm of a promise job, which has no entry settings object in the library). |
| GetCurrentScriptLocation() | Returns the location of the code that is running (the source file, line and column of the innermost running script), or null when no script is running or when the engine cannot extract it: the source location of the violations of the content security policies (https://w3c.github.io/webappsec-csp/#create-violation-for-global, step 2). |
| IsPromiseHandled(object) | Gets whether a promise has a handler (its [[PromiseIsHandled]] internal slot). The promises rejected without handler are given to GlobalScope.TrackPromiseRejection by the engine. |
| LoadModuleScriptGraph(ModuleScript, Action<bool>) | Parses a module script and loads its descendants ("fetch the descendants of and link a module script", https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-and-link-a-module-script): the engine resolves the module specifiers and fetches the modules with the library. onComplete is called once the graph is loaded, with true, or with false when a module of the graph cannot be fetched (the script element then fires an error event). A parse error is stored in ModuleScript.ErrorToRethrow. |
| OnChildNavigablesChanged(Window) | Called when the document-tree child navigables of the document of a window change (an iframe is inserted or removed): the indexed properties of the WindowProxy (window[0]) changed (https://html.spec.whatwg.org/multipage/nav-history-apis.html#windowproxy-getownproperty). |
| OnDocumentActivated(Document) | Called when a document becomes the active document of its browsing context, before it is parsed. The window of the document may be a new window (see ScriptEngine.CreateRealm), or the window of the initial about:blank document, which is reused by a same-origin document. |
| ParseClassicScript(ClassicScript) | Parses a classic script (https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script) without running it: returns the error to rethrow of a script that cannot be parsed (e.g. the SyntaxError of a worker script, which fires an error event at the Worker object instead of being reported), or null. |
| PerformMicrotaskCheckpoint() | Runs the jobs of the engine and the microtasks queued with ScriptEngine.QueueMicrotask until the queue is empty (https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint). The exceptions of the jobs are reported by the engine. |
| PreloadModuleScript(GlobalScope, string, ModuleType, RequestDestination, ModuleFetchOptions, Element?, Action<bool>) | Fetches a module script without loading its descendants nor running it ("fetch a modulepreload module script graph", https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-modulepreload-module-script-graph): the module of a <link rel=modulepreload> element. onComplete is called with true when the module is fetched (even when it has a parse error), or with false when it cannot be fetched. |
| PrepareToRunScript(GlobalScope) | https://html.spec.whatwg.org/multipage/webappapis.html#prepare-to-run-script: the JavaScript execution context stack is not empty until the returned scope is disposed, which cleans up after running script (a microtask checkpoint when the stack becomes empty). The callbacks invoked in the scope do not perform a microtask checkpoint. |
| QueueMicrotask(Action) | Queues a microtask of the library (e.g. a mutation observer notification) in the job queue of the engine, so that the microtasks of the library and the jobs of the engine (promise reactions) run in order (https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-microtask). |
| StructuredDeserialize(GlobalScope, object?) | Deserializes a value serialized by ScriptEngine.StructuredSerialize in the realm of global (https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize): the result is a new value of the realm (e.g. the MessageEvent.Data of the message events). |
| StructuredSerialize(GlobalScope, object?) | Serializes a value (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserialize), e.g. the message of BroadcastChannel.PostMessage. The result is given to ScriptEngine.StructuredDeserialize, possibly several times and for other realms. |
| StructuredSerialize(GlobalScope, object?, IReadOnlyList<object>) | Serializes a value and transfers the objects of transferList (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer), e.g. for GlobalScope.StructuredClone: the transferred objects are detached. |
| StructuredSerializeForAgent(GlobalScope, object?, IReadOnlyList<object>) | Serializes a value for another agent (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer), e.g. a message posted to a worker or to a MessagePort: the result is given to ScriptEngine.StructuredDeserialize of another engine instance, on another thread, so it must not reference the values of this engine. The objects of transferList are transferred: the ArrayBuffer objects of the engine, and the MessagePort objects. |
| StructuredSerializeForStorage(GlobalScope, object?) | Serializes a value for storage (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeforstorage), e.g. the state of History.PushState: a SharedArrayBuffer throws a DataCloneError. |
| WaitForAll(GlobalScope, IReadOnlyList<object?>, Action, Action<object?>) | Runs the success steps once all the values are fulfilled promises, or the failure steps with the reason of the first rejected one (https://webidl.spec.whatwg.org/#wait-for-all). The values are values of the engine, resolved as promises of the realm of global, or RejectedPromise for a promise rejected with an exception. |
CompileEventHandler(EventHandlerSource)
Compiles the value of an event handler content attribute (e.g. onclick="..."), the first time the event handler is used (https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler).
protected internal abstract EventHandlerCallback CompileEventHandler(EventHandlerSource source)Parameters
sourceEventHandlerSource- The body of the function, its parameters and its scopes.
Returns
EventHandlerCallback The function.
Exceptions
Exception- Any exception (e.g. a
SyntaxError): the library reports it and the event handler is null.
CreateRealm(GlobalScope)
Creates the realm whose global object is global (https://html.spec.whatwg.org/multipage/document-sequences.html#creating-a-new-browsing-context). It is called when a new window is created for a browsing context, before its document becomes the active document, and when the script of a worker is fetched (on the thread of the worker, with the engine returned by ScriptEngine.CreateWorkerScriptEngine). An engine may create the realm lazily, when a script first runs in it.
protected internal abstract void CreateRealm(GlobalScope global)Parameters
globalGlobalScope- The global object of the realm: a
Windowor aWorkerGlobalScope.
CreateWorkerScriptEngine(CancellationToken)
ScriptEngine.csCreates the script engine of a new worker (https://html.spec.whatwg.org/multipage/workers.html#run-a-worker): each dedicated or shared worker is a new agent, whose event loop runs on its own thread, so it needs its own engine. The method is called on the thread of the worker, before ScriptEngine.CreateRealm is called with the WorkerGlobalScope of the worker; the engine is then only used on that thread, and is disposed (when it implements IDisposable) when the worker ends.
protected internal virtual ScriptEngine? CreateWorkerScriptEngine(CancellationToken terminationToken)Parameters
terminationTokenCancellationToken- Canceled when the worker is terminated (e.g.
worker.terminate()): the engine should abort the running script, by throwing any exception (it is not reported).
Returns
ScriptEngine? The engine of the worker, or null when the workers do not run scripts. The default implementation returns null.
DestroyRealm(GlobalScope)
ScriptEngine.csCalled when the browsing context of a window is discarded (e.g. its iframe is removed from the document, or it navigates to another document), or when a worker ends: the realm no longer runs scripts, and the engine may release it.
protected internal virtual void DestroyRealm(GlobalScope global)Parameters
globalGlobalScope- The global object of the realm.
EnterNestedMicrotaskQueue()
ScriptEngine.csEnters a separate microtask queue: until the returned scope is disposed, the jobs of the engine and the microtasks queued with ScriptEngine.QueueMicrotask go to a new queue, which ScriptEngine.PerformMicrotaskCheckpoint runs; the microtasks that were pending are kept, and are not run in the scope. The scopes nest. A script is considered running in the scope (ScriptEngine.IsScriptRunning): the callbacks invoked in it perform no microtask checkpoint.
protected internal virtual IDisposable EnterNestedMicrotaskQueue()Returns
IDisposable The scope, which restores the previous microtask queue when it is disposed.
Remarks
The callbacks of a worklet are specified to run in another agent, with its own microtask queue: the layout of a display: layout() box runs the microtasks of its layout worklet until the promise of its callback is settled (https://drafts.css-houdini.org/css-layout-api-1/#run-a-work-queue), possibly while a script of the document reads a geometry, and the microtasks of that script must not run. The default implementation returns a scope that does nothing: the microtasks of the document then run with the ones of the worklet.
ExecuteClassicScript(ClassicScript)
Runs a classic script (https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script) in the realm of ClassicScript.Global. The library owns the ordering of the scripts and the "clean up after running script" steps: the engine only evaluates the code.
protected internal abstract object? ExecuteClassicScript(ClassicScript script)Parameters
scriptClassicScript- The script to run.
Returns
object? The completion value of the script: a String when the value is a JavaScript string (the result of a javascript: URL is a string), otherwise any value (the library ignores it).
Exceptions
Exception- Any exception thrown when the script cannot be parsed or when its evaluation throws (an abrupt completion). The library reports it (https://html.spec.whatwg.org/multipage/webappapis.html#report-an-exception), using
ScriptEngine.ExtractErrorInformation.
ExecuteModuleScript(ModuleScript)
ScriptEngine.csRuns a module script (https://html.spec.whatwg.org/multipage/webappapis.html#run-a-module-script): links and evaluates the module graph, and reports the error to rethrow or the evaluation errors (including the errors of a top-level await) to the global object.
protected internal virtual void ExecuteModuleScript(ModuleScript script)Parameters
scriptModuleScript- The module script, whose graph is loaded.
ExtractErrorInformation(object?)
ScriptEngine.csExtracts the information of an exception (https://html.spec.whatwg.org/multipage/webappapis.html#extract-error): its message, the location of the script, and the value of the error attribute of the ErrorEvent.
protected internal virtual ScriptError ExtractErrorInformation(object? exception)Parameters
exceptionobject?- A .NET
Exceptionthrown by the engine or by the library, or a value of the engine (e.g. the reason of a rejected promise, or the argument ofreportError()).
Returns
ScriptError The error information. The default implementation uses the message of the .NET exceptions.
FetchModuleScriptGraph(GlobalScope, string, ModuleFetchOptions, Element?, Action<ModuleScript?>)
ScriptEngine.csFetches the graph of an external module script ("fetch a module script graph", https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-module-script-tree): the root is fetched ("fetch a single module script"), then its descendants are loaded. onComplete is called with the module script, or with null when a module of the graph cannot be fetched. A parse error is stored in ModuleScript.ErrorToRethrow.
protected internal virtual void FetchModuleScriptGraph(GlobalScope global, string url, ModuleFetchOptions options, Element? element, Action<ModuleScript?> onComplete)Parameters
globalGlobalScope- The global object of the realm in which the script runs.
urlstring- The URL of the root.
optionsModuleFetchOptions- The fetch options of the script.
elementElement?- The script element that fetches the script, or null.
onCompleteAction<ModuleScript?>- Called when the graph is loaded (possibly synchronously).
Remarks
The default implementation fetches the root with the library, then calls ScriptEngine.LoadModuleScriptGraph. An engine with a module map overrides it to reuse the module of the URL when it is already fetched (the module is evaluated once, and its parse error is remembered).
GetActiveScriptBaseUrl()
ScriptEngine.csReturns the base URL of the active script (https://html.spec.whatwg.org/multipage/webappapis.html#active-script), or null when no script is running: the base URL of the strings compiled by setTimeout() and setInterval().
protected internal virtual string? GetActiveScriptBaseUrl()Returns
string? The base URL of the innermost running classic or module script, or null.
GetActiveScriptFetchOptions()
ScriptEngine.csReturns the fetch options of the active script (https://html.spec.whatwg.org/multipage/webappapis.html#active-script), or null when no script is running: the options of the modules imported by import() in a classic script.
protected internal virtual ModuleFetchOptions? GetActiveScriptFetchOptions()Returns
ModuleFetchOptions? The fetch options of the innermost running classic or module script, or null.
GetCurrentGlobal()
ScriptEngine.csReturns the global object of the current realm (https://tc39.es/ecma262/#current-realm), or null when no script is running: the realm of the running function (e.g. the realm of a promise job, which has no entry settings object in the library).
protected internal virtual GlobalScope? GetCurrentGlobal()Returns
GlobalScope? The global object of the current realm, or null.
GetCurrentScriptLocation()
ScriptEngine.csReturns the location of the code that is running (the source file, line and column of the innermost running script), or null when no script is running or when the engine cannot extract it: the source location of the violations of the content security policies (https://w3c.github.io/webappsec-csp/#create-violation-for-global, step 2).
protected internal virtual ScriptLocation? GetCurrentScriptLocation()Returns
ScriptLocation? The location of the running code, or null.
IsPromiseHandled(object)
ScriptEngine.csGets whether a promise has a handler (its [[PromiseIsHandled]] internal slot). The promises rejected without handler are given to GlobalScope.TrackPromiseRejection by the engine.
Parameters
promiseobject- A promise given to
GlobalScope.TrackPromiseRejection.
Returns
bool Whether the promise is handled. The default implementation returns false.
LoadModuleScriptGraph(ModuleScript, Action<bool>)
ScriptEngine.csParses a module script and loads its descendants ("fetch the descendants of and link a module script", https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendants-of-and-link-a-module-script): the engine resolves the module specifiers and fetches the modules with the library. onComplete is called once the graph is loaded, with true, or with false when a module of the graph cannot be fetched (the script element then fires an error event). A parse error is stored in ModuleScript.ErrorToRethrow.
protected internal virtual void LoadModuleScriptGraph(ModuleScript script, Action<bool> onComplete)Parameters
scriptModuleScript- The root of the module graph.
onCompleteAction<bool>- Called when the graph is loaded (possibly synchronously).
OnDocumentActivated(Document)
ScriptEngine.csCalled when a document becomes the active document of its browsing context, before it is parsed. The window of the document may be a new window (see ScriptEngine.CreateRealm), or the window of the initial about:blank document, which is reused by a same-origin document.
Parameters
documentDocument- The new active document.
ParseClassicScript(ClassicScript)
ScriptEngine.csParses a classic script (https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script) without running it: returns the error to rethrow of a script that cannot be parsed (e.g. the SyntaxError of a worker script, which fires an error event at the Worker object instead of being reported), or null.
protected internal virtual object? ParseClassicScript(ClassicScript script)Parameters
scriptClassicScript- The script, run afterwards by
ScriptEngine.ExecuteClassicScriptwhen it can be parsed.
Returns
object? The parse error (a value of the engine), or null. The default implementation returns null: the parse errors are thrown by ScriptEngine.ExecuteClassicScript.
PerformMicrotaskCheckpoint()
Runs the jobs of the engine and the microtasks queued with ScriptEngine.QueueMicrotask until the queue is empty (https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint). The exceptions of the jobs are reported by the engine.
protected internal abstract void PerformMicrotaskCheckpoint()PreloadModuleScript(GlobalScope, string, ModuleType, RequestDestination, ModuleFetchOptions, Element?, Action<bool>)
ScriptEngine.csFetches a module script without loading its descendants nor running it ("fetch a modulepreload module script graph", https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-modulepreload-module-script-graph): the module of a <link rel=modulepreload> element. onComplete is called with true when the module is fetched (even when it has a parse error), or with false when it cannot be fetched.
protected internal virtual void PreloadModuleScript(GlobalScope global, string url, ModuleType type, RequestDestination destination, ModuleFetchOptions options, Element? element, Action<bool> onComplete)Parameters
globalGlobalScope- The global object of the realm of the module.
urlstring- The URL of the module.
typeModuleType- The type of the module, determined by the destination.
destinationRequestDestination- The destination of the request of a JavaScript module (a script-like destination).
optionsModuleFetchOptions- The fetch options of the module.
elementElement?- The link element that fetches the module, or null.
onCompleteAction<bool>- Called when the module is fetched (possibly synchronously).
Remarks
The default implementation fetches the module with the library and ignores its response. An engine with a module map overrides it to add the module to the module map, so that the module scripts and the imports do not fetch it again.
PrepareToRunScript(GlobalScope)
ScriptEngine.cshttps://html.spec.whatwg.org/multipage/webappapis.html#prepare-to-run-script: the JavaScript execution context stack is not empty until the returned scope is disposed, which cleans up after running script (a microtask checkpoint when the stack becomes empty). The callbacks invoked in the scope do not perform a microtask checkpoint.
protected internal virtual IDisposable PrepareToRunScript(GlobalScope global)Parameters
globalGlobalScope- The global object of the settings object.
Returns
IDisposable The scope. The default implementation returns a scope that does nothing.
QueueMicrotask(Action)
Queues a microtask of the library (e.g. a mutation observer notification) in the job queue of the engine, so that the microtasks of the library and the jobs of the engine (promise reactions) run in order (https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-microtask).
Parameters
microtaskAction- The microtask. The engine runs it when it performs a microtask checkpoint.
StructuredDeserialize(GlobalScope, object?)
ScriptEngine.csDeserializes a value serialized by ScriptEngine.StructuredSerialize in the realm of global (https://html.spec.whatwg.org/multipage/structured-data.html#structureddeserialize): the result is a new value of the realm (e.g. the MessageEvent.Data of the message events).
protected internal virtual object? StructuredDeserialize(GlobalScope global, object? serialized)Parameters
globalGlobalScope- The global object of the target realm.
serializedobject?- The value returned by
ScriptEngine.StructuredSerialize.
Returns
object? The deserialized value.
StructuredSerialize overloads
StructuredSerialize(GlobalScope, object?)
ScriptEngine.csSerializes a value (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserialize), e.g. the message of BroadcastChannel.PostMessage. The result is given to ScriptEngine.StructuredDeserialize, possibly several times and for other realms.
protected internal virtual object? StructuredSerialize(GlobalScope global, object? value)Parameters
globalGlobalScope- The global object of the current realm.
valueobject?- The value: a value of the engine, a .NET platform object, or null for
undefined(the value of an IDLanyargument).
Returns
object? The serialized value.
Exceptions
DomException- A
DataCloneErrorwhen the value cannot be serialized.
Remarks
The default implementation serializes the .NET primitive values and the serializable platform objects.
StructuredSerialize(GlobalScope, object?, IReadOnlyList<object>)
ScriptEngine.csSerializes a value and transfers the objects of transferList (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer), e.g. for GlobalScope.StructuredClone: the transferred objects are detached.
protected internal virtual object? StructuredSerialize(GlobalScope global, object? value, IReadOnlyList<object> transferList)Parameters
globalGlobalScope- The global object of the current realm.
valueobject?- The value (see
ScriptEngine.StructuredSerialize). transferListIReadOnlyList<object>- The objects to transfer: values of the engine or .NET platform objects.
Returns
object? The serialized value, given to ScriptEngine.StructuredDeserialize.
Exceptions
DomException- A
DataCloneErrorwhen the value cannot be serialized or an object cannot be transferred.
Remarks
The default implementation does not support transferring objects.
StructuredSerializeForAgent(GlobalScope, object?, IReadOnlyList<object>)
ScriptEngine.csSerializes a value for another agent (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer), e.g. a message posted to a worker or to a MessagePort: the result is given to ScriptEngine.StructuredDeserialize of another engine instance, on another thread, so it must not reference the values of this engine. The objects of transferList are transferred: the ArrayBuffer objects of the engine, and the MessagePort objects.
protected internal virtual object? StructuredSerializeForAgent(GlobalScope global, object? value, IReadOnlyList<object> transferList)Parameters
globalGlobalScope- The global object of the current realm.
valueobject?- The value (see
ScriptEngine.StructuredSerialize). transferListIReadOnlyList<object>- The objects to transfer.
Returns
object? The serialized value.
Exceptions
DomException- A
DataCloneErrorwhen the value cannot be serialized or an object cannot be transferred.
Remarks
The default implementation calls ScriptEngine.StructuredSerialize, whose default result does not depend on the engine.
StructuredSerializeForStorage(GlobalScope, object?)
ScriptEngine.csSerializes a value for storage (https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeforstorage), e.g. the state of History.PushState: a SharedArrayBuffer throws a DataCloneError.
protected internal virtual object? StructuredSerializeForStorage(GlobalScope global, object? value)Parameters
globalGlobalScope- The global object of the current realm.
valueobject?- The value (see
ScriptEngine.StructuredSerialize).
Returns
object? The serialized value, given to ScriptEngine.StructuredDeserialize.
Remarks
The default implementation calls ScriptEngine.StructuredSerialize.
WaitForAll(GlobalScope, IReadOnlyList<object?>, Action, Action<object?>)
ScriptEngine.csRuns the success steps once all the values are fulfilled promises, or the failure steps with the reason of the first rejected one (https://webidl.spec.whatwg.org/#wait-for-all). The values are values of the engine, resolved as promises of the realm of global, or RejectedPromise for a promise rejected with an exception.
protected internal virtual void WaitForAll(GlobalScope global, IReadOnlyList<object?> values, Action successSteps, Action<object?> failureSteps)Parameters
globalGlobalScope- The global object of the realm of the promises.
valuesIReadOnlyList<object?>- The values.
successStepsAction- The success steps, run by a promise reaction (or a microtask when there is no value).
failureStepsAction<object?>- The failure steps, given the rejection reason.
Remarks
The default implementation considers that the values are fulfilled promises: it queues a microtask to run the success steps.