public override void Dispose() { if (_disposedFlag.Set()) { lock (_executionSynchronizer) { if (_debuggerStepCallback != null) { _jsEngine.Step -= _debuggerStepCallback; _debuggerStepCallback = null; } if (_debuggerBreakCallback != null) { _jsEngine.Break -= _debuggerBreakCallback; _debuggerBreakCallback = null; } _jsEngine = null; _cancellationConstraint = null; if (_cancellationTokenSource != null) { _cancellationTokenSource.Dispose(); _cancellationTokenSource = null; } } } }
/// <summary> /// Constructs an instance of adapter for the Jint JS engine /// </summary> /// <param name="settings">Settings of the Jint JS engine</param> public JintJsEngine(JintSettings settings) { _cancellationTokenSource = new CancellationTokenSource(); _cancellationConstraint = new OriginalCancellationConstraint(_cancellationTokenSource.Token); JintSettings jintSettings = settings ?? new JintSettings(); _debuggerBreakCallback = jintSettings.DebuggerBreakCallback; _debuggerStepCallback = jintSettings.DebuggerStepCallback; var debuggerStatementHandlingMode = Utils.GetEnumFromOtherEnum <JsDebuggerStatementHandlingMode, OriginalDebuggerStatementHandlingMode>( jintSettings.DebuggerStatementHandlingMode); try { _jsEngine = new OriginalEngine(options => { options .WithoutConstraint(c => c is OriginalCancellationConstraint) .Constraint(_cancellationConstraint) .DebuggerStatementHandling(debuggerStatementHandlingMode) .DebugMode(jintSettings.EnableDebugging) .LimitMemory(jintSettings.MemoryLimit) .LimitRecursion(jintSettings.MaxRecursionDepth) .LocalTimeZone(jintSettings.LocalTimeZone ?? TimeZoneInfo.Local) .MaxStatements(jintSettings.MaxStatements) .Strict(jintSettings.StrictMode) .TimeoutInterval(jintSettings.TimeoutInterval) ; if (jintSettings.RegexTimeoutInterval.HasValue) { options.RegexTimeoutInterval(jintSettings.RegexTimeoutInterval.Value); } options.AddObjectConverter(new UndefinedConverter()); }); if (_debuggerBreakCallback != null) { _jsEngine.Break += _debuggerBreakCallback; } if (_debuggerStepCallback != null) { _jsEngine.Step += _debuggerStepCallback; } } catch (Exception e) { throw JsErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true); } }