EvaluationContext.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Esprima.Ast;
  2. namespace Jint.Runtime.Interpreter;
  3. /// <summary>
  4. /// Per Engine.Evaluate() call context.
  5. /// </summary>
  6. internal sealed class EvaluationContext
  7. {
  8. private readonly bool _shouldRunBeforeExecuteStatementChecks;
  9. public EvaluationContext(Engine engine, in Completion? resumedCompletion = null)
  10. {
  11. Engine = engine;
  12. ResumedCompletion = resumedCompletion ?? default; // TODO later
  13. OperatorOverloadingAllowed = engine.Options.Interop.AllowOperatorOverloading;
  14. _shouldRunBeforeExecuteStatementChecks = engine._constraints.Length > 0 || engine._isDebugMode;
  15. }
  16. public readonly Engine Engine;
  17. public readonly Completion ResumedCompletion;
  18. public bool DebugMode => Engine._isDebugMode;
  19. public SyntaxElement LastSyntaxElement = null!;
  20. public readonly bool OperatorOverloadingAllowed;
  21. public void RunBeforeExecuteStatementChecks(Statement statement)
  22. {
  23. if (_shouldRunBeforeExecuteStatementChecks)
  24. {
  25. Engine.RunBeforeExecuteStatementChecks(statement);
  26. }
  27. }
  28. }