| | | 1 | | using Elsa.Expressions.JavaScript.Helpers; |
| | | 2 | | using Elsa.Expressions.JavaScript.Options; |
| | | 3 | | using Jint; |
| | | 4 | | using Jint.Runtime.Interop; |
| | | 5 | | using Microsoft.Extensions.Options; |
| | | 6 | | |
| | | 7 | | // ReSharper disable once CheckNamespace |
| | | 8 | | namespace Elsa.Extensions; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Extends <see cref="Engine"/>. |
| | | 12 | | /// </summary> |
| | | 13 | | public static class EngineExtensions |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Register the specified type <c>T</c> with the engine. |
| | | 17 | | /// </summary> |
| | 1185 | 18 | | public static void RegisterType<T>(this Engine engine) => engine.SetValue(typeof(T).Name, TypeReference.CreateTypeRe |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Register the specified type <c>T</c> with the engine. |
| | | 22 | | /// </summary> |
| | 2784 | 23 | | public static void RegisterType(this Engine engine, Type type) => engine.SetValue(type.Name, TypeReference.CreateTyp |
| | | 24 | | |
| | | 25 | | internal static void SyncVariablesContainer(this Engine engine, IOptions<JintOptions> options, string name, object? |
| | | 26 | | { |
| | 5 | 27 | | if (options.Value.DisableWrappers || options.Value.DisableVariableCopying) |
| | 0 | 28 | | return; |
| | | 29 | | |
| | | 30 | | // To ensure both variable accessor syntaxes work, we need to update the variables container in the engine as we |
| | 5 | 31 | | var variablesContainer = (IDictionary<string, object?>)engine.GetValue("variables").ToObject()!; |
| | 5 | 32 | | variablesContainer[name] = ObjectConverterHelper.ProcessVariableValue(engine, value); |
| | 5 | 33 | | engine.SetValue("variables", variablesContainer); |
| | 5 | 34 | | } |
| | | 35 | | } |