JsEngineOptions Class
The options of a JsEngine: the limits of the scripts and the host services.
public sealed class JsEngineOptionsRemarks
The engine copies the options when it is created: changing the instance given to the constructor afterwards does not change the engine, so one instance can configure several engines. JsEngine.Options is the copy of the engine.
The limits (JsEngineOptions.RecursionLimit, JsEngineOptions.Timeout, JsEngineOptions.MemoryLimit, JsEngineOptions.MaxStatements, JsEngineOptions.RegExpTimeout and JsEngineOptions.CancellationToken) can be changed through JsEngine.Options on the thread of the engine: the change applies from the next check of the limits. So can JsEngineOptions.CanBlock and JsEngineOptions.Debugger. The other options configure the engine for its whole life: setting them on JsEngine.Options throws an InvalidOperationException.
Constructors
| Name | Description |
|---|---|
| JsEngineOptions() |
JsEngineOptions()
JsEngineOptions.cspublic JsEngineOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| AllowStringCompilation | Gets or sets whether the scripts can compile code given as a string: eval, new Function(...), the constructors of the generator and async functions, and ShadowRealm.prototype.evaluate. When it is false, they throw an EvalError, before JsHost.EnsureCanCompileStrings is called. The default is true. |
| CanBlock | Gets or sets whether the scripts can block the thread with Atomics.wait (the [[CanBlock]] field of the agent). When false, Atomics.wait throws a TypeError, as on the main thread of a browser; Atomics.waitAsync still works. A blocking wait is bounded by JsEngineOptions.Timeout and JsEngineOptions.CancellationToken either way. |
| CancellationToken | Gets or sets the token that stops the running script when it is canceled. |
| Debugger | Gets or sets the debugger that receives the execution events of the scripts (a statement runs, a debugger statement), or null. The code compiled while it is null raises no event and does not pay for it. |
| DefaultLocale | Gets or sets the default locale of Intl (ECMA-402 DefaultLocale), a BCP 47 language tag such as "fr-FR". The engine uses its own copy of the CLDR data, so the results do not depend on the operating system; a tag that is not valid or that matches no locale of the data is replaced by "en-US". |
| EnableV8StackTraceApi | Gets or sets whether the realms have the stack trace API of V8 (https://v8.dev/docs/stack-trace-api), used by some npm packages: Error.captureStackTrace(object, constructorOpt) defines the stack property of an object, and Error.stackTraceLimit (10 by default) sets the number of frames of the stack traces. They are not part of ECMAScript, so they are disabled by default. Error.prepareStackTrace is not supported. |
| Host | Gets or sets the host-defined operations (promise rejection tracking, job callbacks, compilation of strings...), or null for the default ones. |
| MaxStatements | Gets or sets the maximum number of statements of an entry into JavaScript, or null for no limit. The engine counts the iterations of the loops and the calls, which bound the work of a script as the statements do. |
| MemoryLimit | Gets or sets the maximum number of bytes allocated by the thread during an entry into JavaScript (a script, a callback...), or null for no limit. The allocations are measured with GC.GetAllocatedBytesForCurrentThread. |
| ModuleLoader | Gets or sets the loader of the modules imported by the scripts and the modules, or null when the scripts cannot import modules. |
| RecursionLimit | Gets or sets the maximum depth of the calls (JavaScript functions and re-entries from .NET); a deeper call throws a RangeError. |
| RegExpTimeout | Gets or sets the maximum duration of a regular expression match, or null for no limit (the matches are still bounded by JsEngineOptions.Timeout). A match that exceeds it stops the script (JsTerminationReason.Timeout). |
| TimeProvider | Gets or sets the clock of Date.now(), new Date() and the time zone of the dates. |
| TimeZone | Gets or sets the identifier of the IANA time zone of the local time of the scripts (e.g. "Europe/Paris"), or null to use the local time zone of JsEngineOptions.TimeProvider (a Windows identifier is mapped to its IANA identifier). The engine uses its own copy of the IANA time zone database, so the local times do not depend on the operating system. A local time zone that is not in the database, such as a zone created by TimeZoneInfo.CreateCustomTimeZone, uses its own rules: a zone without daylight saving time is an offset time zone ("+05:00"), and a zone with daylight saving time keeps its identifier. Set this property to "UTC" to use UTC instead. An identifier that is not a time zone of the database (such as an offset) throws an InvalidOperationException when the scripts first use the local time zone. |
| Timeout | Gets or sets the maximum duration of an entry into JavaScript (a script, a callback...), or null for no limit. |
AllowStringCompilation
JsEngineOptions.csGets or sets whether the scripts can compile code given as a string: eval, new Function(...), the constructors of the generator and async functions, and ShadowRealm.prototype.evaluate. When it is false, they throw an EvalError, before JsHost.EnsureCanCompileStrings is called. The default is true.
public bool AllowStringCompilation { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).
CanBlock
JsEngineOptions.csGets or sets whether the scripts can block the thread with Atomics.wait (the [[CanBlock]] field of the agent). When false, Atomics.wait throws a TypeError, as on the main thread of a browser; Atomics.waitAsync still works. A blocking wait is bounded by JsEngineOptions.Timeout and JsEngineOptions.CancellationToken either way.
public bool CanBlock { get; set; }Property value
CancellationToken
JsEngineOptions.csGets or sets the token that stops the running script when it is canceled.
public CancellationToken CancellationToken { get; set; }Property value
Debugger
JsEngineOptions.csGets or sets the debugger that receives the execution events of the scripts (a statement runs, a debugger statement), or null. The code compiled while it is null raises no event and does not pay for it.
public JsDebugger? Debugger { get; set; }Property value
DefaultLocale
JsEngineOptions.csGets or sets the default locale of Intl (ECMA-402 DefaultLocale), a BCP 47 language tag such as "fr-FR". The engine uses its own copy of the CLDR data, so the results do not depend on the operating system; a tag that is not valid or that matches no locale of the data is replaced by "en-US".
public string DefaultLocale { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).
EnableV8StackTraceApi
JsEngineOptions.csGets or sets whether the realms have the stack trace API of V8 (https://v8.dev/docs/stack-trace-api), used by some npm packages: Error.captureStackTrace(object, constructorOpt) defines the stack property of an object, and Error.stackTraceLimit (10 by default) sets the number of frames of the stack traces. They are not part of ECMAScript, so they are disabled by default. Error.prepareStackTrace is not supported.
public bool EnableV8StackTraceApi { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).
Gets or sets the host-defined operations (promise rejection tracking, job callbacks, compilation of strings...), or null for the default ones.
public JsHost? Host { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).
MaxStatements
JsEngineOptions.csMemoryLimit
JsEngineOptions.csGets or sets the maximum number of bytes allocated by the thread during an entry into JavaScript (a script, a callback...), or null for no limit. The allocations are measured with GC.GetAllocatedBytesForCurrentThread.
public long? MemoryLimit { get; set; }Property value
ModuleLoader
JsEngineOptions.csGets or sets the loader of the modules imported by the scripts and the modules, or null when the scripts cannot import modules.
public JsModuleLoader? ModuleLoader { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).
RecursionLimit
JsEngineOptions.csRegExpTimeout
JsEngineOptions.csGets or sets the maximum duration of a regular expression match, or null for no limit (the matches are still bounded by JsEngineOptions.Timeout). A match that exceeds it stops the script (JsTerminationReason.Timeout).
public TimeSpan? RegExpTimeout { get; set; }Property value
TimeProvider
JsEngineOptions.csGets or sets the clock of Date.now(), new Date() and the time zone of the dates.
public TimeProvider TimeProvider { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).
TimeZone
JsEngineOptions.csGets or sets the identifier of the IANA time zone of the local time of the scripts (e.g. "Europe/Paris"), or null to use the local time zone of JsEngineOptions.TimeProvider (a Windows identifier is mapped to its IANA identifier). The engine uses its own copy of the IANA time zone database, so the local times do not depend on the operating system. A local time zone that is not in the database, such as a zone created by TimeZoneInfo.CreateCustomTimeZone, uses its own rules: a zone without daylight saving time is an offset time zone ("+05:00"), and a zone with daylight saving time keeps its identifier. Set this property to "UTC" to use UTC instead. An identifier that is not a time zone of the database (such as an offset) throws an InvalidOperationException when the scripts first use the local time zone.
public string? TimeZone { get; set; }Property value
Exceptions
InvalidOperationException- The options are the ones of an engine (
JsEngine.Options).