EvaluationContext.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Runtime.CompilerServices;
  2. using Esprima.Ast;
  3. namespace Jint.Runtime.Interpreter;
  4. /// <summary>
  5. /// Per Engine.Evaluate() call context.
  6. /// </summary>
  7. internal sealed class EvaluationContext
  8. {
  9. private readonly bool _shouldRunBeforeExecuteStatementChecks;
  10. public EvaluationContext(Engine engine, in Completion? resumedCompletion = null)
  11. {
  12. Engine = engine;
  13. ResumedCompletion = resumedCompletion ?? default; // TODO later
  14. OperatorOverloadingAllowed = engine.Options.Interop.AllowOperatorOverloading;
  15. _shouldRunBeforeExecuteStatementChecks = engine._constraints.Length > 0 || engine._isDebugMode;
  16. }
  17. public readonly Engine Engine;
  18. public readonly Completion ResumedCompletion;
  19. public bool DebugMode => Engine._isDebugMode;
  20. public SyntaxElement LastSyntaxElement = null!;
  21. public readonly bool OperatorOverloadingAllowed;
  22. // completion record information
  23. public string? Target;
  24. public CompletionType Completion;
  25. public void RunBeforeExecuteStatementChecks(Statement statement)
  26. {
  27. if (_shouldRunBeforeExecuteStatementChecks)
  28. {
  29. Engine.RunBeforeExecuteStatementChecks(statement);
  30. }
  31. }
  32. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  33. public void PrepareFor(Node node)
  34. {
  35. LastSyntaxElement = node;
  36. Target = null;
  37. Completion = CompletionType.Normal;
  38. }
  39. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  40. public bool IsAbrupt() => Completion != CompletionType.Normal;
  41. }