| | | 1 | | using Elsa.Expressions.Models; |
| | | 2 | | using Elsa.Mediator.Contracts; |
| | | 3 | | using Jint; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Expressions.JavaScript.Notifications; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// This notification is published every time a JavaScript expression is about to be evaluated. |
| | | 9 | | /// It gives subscribers a chance to configure the <see cref="Engine"/> with additional functions and variables. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="Engine">The engine the expression will be evaluated on.</param> |
| | | 12 | | /// <param name="Context">The context the expression is evaluated in.</param> |
| | | 13 | | /// <param name="Expression">The expression that is about to be evaluated.</param> |
| | | 14 | | /// <param name="ReferencedGlobals"> |
| | | 15 | | /// The identifiers the expression references without declaring them, as reported by the parser. A handler that |
| | | 16 | | /// would otherwise install a global speculatively can register only the names in this set: an identifier the |
| | | 17 | | /// expression never mentions cannot be read from it. |
| | | 18 | | /// <para> |
| | | 19 | | /// Four cases are not answerable from the set and must be treated as "register everything": |
| | | 20 | | /// <see cref="Jint.ReferencedGlobals.HasDirectEvalCall"/>, because evaluated code can reference anything; the |
| | | 21 | | /// identifiers <c>eval</c> and <c>Function</c> appearing in the set, which is how indirect <c>eval</c> and the |
| | | 22 | | /// <c>Function</c> constructor are signalled (neither is reported as a direct <c>eval</c> call); and |
| | | 23 | | /// <c>globalThis</c>, because a global can be reached through it without its name appearing as an identifier. |
| | | 24 | | /// </para> |
| | | 25 | | /// <para> |
| | | 26 | | /// Also note that only free identifiers are reported, so the member names in <c>variables.Foo</c> are not: the |
| | | 27 | | /// set says whether <c>variables</c> is referenced, not which of its properties. |
| | | 28 | | /// </para> |
| | | 29 | | /// <see langword="null"/> when the expression was prepared without collecting them. |
| | | 30 | | /// </param> |
| | 2613 | 31 | | public record EvaluatingJavaScript(Engine Engine, ExpressionExecutionContext Context, string Expression, ReferencedGloba |