< Summary

Information
Class: Elsa.Expressions.JavaScript.Options.JintOptions
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Options/JintOptions.cs
Line coverage
70%
Covered lines: 14
Uncovered lines: 6
Coverable lines: 20
Total lines: 139
Line coverage: 70%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_AllowClrAccess()100%11100%
get_AllowConfigurationAccess()100%11100%
get_ExecutionTimeout()100%11100%
get_MaxStatements()100%11100%
get_MemoryLimit()100%11100%
get_MaxRecursionDepth()100%11100%
get_ScriptCacheTimeout()100%11100%
get_DisableWrappers()100%11100%
get_DisableVariableCopying()100%11100%
ConfigureEngineOptions(...)100%210%
ConfigureEngineOptions(...)100%210%
ConfigureEngine(...)100%11100%
ConfigureEngine(...)100%11100%
RegisterType()0%620%
RegisterType(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Options/JintOptions.cs

#LineLine coverage
 1using Elsa.Expressions.Models;
 2using Elsa.Extensions;
 3using Jint;
 4
 5namespace Elsa.Expressions.JavaScript.Options;
 6
 7/// <summary>
 8/// Options for the Jint JavaScript engine.
 9/// </summary>
 10public class JintOptions
 11{
 12    /// <summary>
 13    /// A list of callbacks that are invoked when the Jint engine options is created. Use this to configure the engine o
 14    /// </summary>
 47315    internal Action<Jint.Options, ExpressionExecutionContext> ConfigureEngineOptionsCallback = (_, _) => { };
 16
 17    /// <summary>
 18    /// A list of callbacks that are invoked when the Jint engine is created. Use this to configure the engine.
 19    /// </summary>
 47320    internal Action<Engine, ExpressionExecutionContext> ConfigureEngineCallback = (_, _) => { };
 21
 22    /// <summary>
 23    /// Enables access to any .NET class. Do not enable if you are executing workflows from untrusted sources (e.g. user
 24    ///
 25    /// See Jint docs for more: https://github.com/sebastienros/jint#accessing-net-assemblies-and-classes
 26    /// </summary>
 29127    public bool AllowClrAccess { get; set; }
 28
 29    /// <summary>
 30    /// Enables access to .NET configuration via the <c>getConfig</c> function.
 31    /// Do not enable if you are executing workflows from untrusted sources (e.g user defined workflows).
 32    /// </summary>
 28533    public bool AllowConfigurationAccess { get; set; }
 34
 35    /// <summary>
 36    /// The maximum wall-clock time a single JavaScript expression may run for. Set to <c>null</c> to remove the limit.
 37    /// </summary>
 38    /// <remarks>
 39    /// Without a limit, an expression such as <c>while (true) {}</c> occupies the calling thread indefinitely.
 40    /// The default is deliberately generous so that legitimate expressions are unaffected; hosts that evaluate
 41    /// user-defined workflows are encouraged to lower it.
 42    /// </remarks>
 47843    public TimeSpan? ExecutionTimeout { get; set; } = TimeSpan.FromSeconds(30);
 44
 45    /// <summary>
 46    /// The maximum number of statements a single JavaScript expression may execute. Set to <c>null</c> (the default) to
 47    /// </summary>
 28648    public int? MaxStatements { get; set; }
 49
 50    /// <summary>
 51    /// The maximum amount of memory, in bytes, a single JavaScript expression may allocate. Set to <c>null</c> (the def
 52    /// </summary>
 28653    public long? MemoryLimit { get; set; }
 54
 55    /// <summary>
 56    /// The maximum recursion depth allowed within a single JavaScript expression. Set to <c>null</c> (the default) to r
 57    /// </summary>
 58    /// <remarks>
 59    /// Unbounded recursion in a script exhausts the CLR stack, which cannot be recovered from. Hosts that evaluate
 60    /// user-defined workflows are encouraged to set a limit.
 61    /// </remarks>
 28662    public int? MaxRecursionDepth { get; set; }
 63
 64    /// <summary>
 65    /// The timeout for script caching.
 66    /// </summary>
 67    /// <remarks>
 68    /// The <c>ScriptCacheTimeout</c> property specifies the duration for which the scripts are cached in the Jint JavaS
 69    /// If the value of <c>ScriptCacheTimeout</c> is <c>null</c>, the scripts are cached indefinitely. If a time value i
 70    /// </remarks>
 64271    public TimeSpan? ScriptCacheTimeout { get; set; } = TimeSpan.FromDays(1);
 72
 73    /// <summary>
 74    /// Disables the generation of variable wrappers. E.g. <c>getMyVariable()</c> will no longer be available for variab
 75    /// This is useful if your application requires the use of invalid JavaScript variable names.
 76    /// </summary>
 86077    public bool DisableWrappers { get; set; }
 78
 79    /// <summary>
 80    /// Disables copying workflow variables into the Jint engine and copying them back into the workflow execution conte
 81    /// Disabling this option will increase performance but will also prevent you from accessing workflow variables from
 82    /// </summary>
 57083    public bool DisableVariableCopying { get; set; }
 84
 85    /// <summary>
 86    /// Configures the Jint engine options.
 87    /// </summary>
 88    /// <param name="configurator">A callback that is invoked when the Jint engine options are created. Use this to conf
 89    public JintOptions ConfigureEngineOptions(Action<Jint.Options> configurator)
 90    {
 091        ConfigureEngineOptionsCallback += (options, _) => configurator(options);
 092        return this;
 93    }
 94
 95    /// <summary>
 96    /// Configures the Jint engine options.
 97    /// </summary>
 98    /// <param name="configurator">A callback that is invoked when the Jint engine options are created. Use this to conf
 99    public JintOptions ConfigureEngineOptions(Action<Jint.Options, ExpressionExecutionContext> configurator)
 100    {
 0101        ConfigureEngineOptionsCallback += configurator;
 0102        return this;
 103    }
 104
 105    /// <summary>
 106    /// Configures the Jint engine.
 107    /// </summary>
 108    /// <param name="configurator">A callback that is invoked when the Jint engine is created. Use this to configure the
 109    public JintOptions ConfigureEngine(Action<Engine, ExpressionExecutionContext> configurator)
 110    {
 9111        ConfigureEngineCallback += configurator;
 9112        return this;
 113    }
 114
 115    /// <summary>
 116    /// Configures the Jint engine.
 117    /// </summary>
 118    /// <param name="configurator">A callback that is invoked when the Jint engine is created. Use this to configure the
 119    public JintOptions ConfigureEngine(Action<Engine> configurator)
 120    {
 50121        return ConfigureEngine((engine, _) => configurator(engine));
 122    }
 123
 124    /// <summary>
 125    /// Registers the specified type <c>T</c> with the engine.
 126    /// </summary>
 127    public JintOptions RegisterType<T>()
 128    {
 0129        return ConfigureEngine(engine => engine.RegisterType<T>());
 130    }
 131
 132    /// <summary>
 133    /// Registers the specified type with the engine.
 134    /// </summary>
 135    public JintOptions RegisterType(Type type)
 136    {
 0137        return ConfigureEngine(engine => engine.RegisterType(type));
 138    }
 139}