1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- namespace Jint
- {
- public class EvalCodeScope : IDisposable
- {
- private readonly bool _eval;
- private readonly bool _force;
- private readonly int _forcedRefCount;
- [ThreadStatic]
- private static int _refCount;
- public EvalCodeScope(bool eval = true, bool force = false)
- {
- _eval = eval;
- _force = force;
- if (_force)
- {
- _forcedRefCount = _refCount;
- _refCount = 0;
- }
- if (_eval)
- {
- _refCount++;
- }
- }
- public void Dispose()
- {
- if (_eval)
- {
- _refCount--;
- }
- if (_force)
- {
- _refCount = _forcedRefCount;
- }
- }
- public static bool IsEvalCode
- {
- get { return _refCount > 0; }
- }
- public static int RefCount
- {
- get
- {
- return _refCount;
- }
- set
- {
- _refCount = value;
- }
- }
- }
- }
|