MaxStatements.cs 622 B

12345678910111213141516171819202122232425262728
  1. using Jint.Runtime;
  2. namespace Jint.Constraints
  3. {
  4. internal sealed class MaxStatements : IConstraint
  5. {
  6. private readonly int _maxStatements;
  7. private int _statementsCount;
  8. public MaxStatements(int maxStatements)
  9. {
  10. _maxStatements = maxStatements;
  11. }
  12. public void Check()
  13. {
  14. if (_maxStatements > 0 && _statementsCount++ > _maxStatements)
  15. {
  16. ExceptionHelper.ThrowStatementsCountOverflowException();
  17. }
  18. }
  19. public void Reset()
  20. {
  21. _statementsCount = 0;
  22. }
  23. }
  24. }