StrictModeScope.cs 622 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. namespace Jint
  3. {
  4. public class StrictModeScope : IDisposable
  5. {
  6. private readonly bool _strict;
  7. [ThreadStatic]
  8. private static int _refCount;
  9. public StrictModeScope(bool strict = true)
  10. {
  11. _strict = strict;
  12. if (_strict)
  13. {
  14. _refCount++;
  15. }
  16. }
  17. public void Dispose()
  18. {
  19. if (_strict)
  20. {
  21. _refCount--;
  22. }
  23. }
  24. public static bool IsStrictModeCode
  25. {
  26. get { return _refCount > 0; }
  27. }
  28. }
  29. }