< Summary

Information
Class: Elsa.Expressions.JavaScript.Expressions.JavaScriptExpressionHandler
Assembly: Elsa.Expressions.JavaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Expressions.JavaScript/Expressions/JavaScriptExpressionHandler.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 42
Line coverage: 100%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
EvaluateAsync()50%22100%
ConfigureEngine(...)100%22100%

File(s)

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

#LineLine coverage
 1using System.Dynamic;
 2using Elsa.Expressions.Contracts;
 3using Elsa.Expressions.Helpers;
 4using Elsa.Expressions.Models;
 5using Elsa.Expressions.JavaScript.Contracts;
 6using Humanizer;
 7using Jint;
 8
 9namespace Elsa.Expressions.JavaScript.Expressions;
 10
 11/// <summary>
 12/// Evaluates JavaScript expressions.
 13/// </summary>
 14public class JavaScriptExpressionHandler : IExpressionHandler
 15{
 16    private readonly IJavaScriptEvaluator _javaScriptEvaluator;
 17
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="JavaScriptExpressionHandler"/> class.
 20    /// </summary>
 9821    public JavaScriptExpressionHandler(IJavaScriptEvaluator javaScriptEvaluator)
 22    {
 9823        _javaScriptEvaluator = javaScriptEvaluator;
 9824    }
 25
 26    /// <inheritdoc />
 27    public async ValueTask<object?> EvaluateAsync(Expression expression, Type returnType, ExpressionExecutionContext con
 28    {
 9829        var javaScriptExpression = expression.Value.ConvertTo<string>() ?? "";
 19630        return await _javaScriptEvaluator.EvaluateAsync(javaScriptExpression, returnType, context, options, engine => Co
 9831    }
 32
 33    private void ConfigureEngine(Engine engine, ExpressionEvaluatorOptions options)
 34    {
 9835        var args = new ExpandoObject() as IDictionary<string, object>;
 36
 20237        foreach (var (name, value) in options.Arguments)
 338            args[name.Camelize()] = value;
 39
 9840        engine.SetValue("args", args);
 9841    }
 42}