Beispiel #1
0
        /// <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 CustomCancellationConstraint(_cancellationTokenSource.Token);

            JintSettings jintSettings = settings ?? new JintSettings();

            try
            {
                _jsEngine = new OriginalEngine(options => {
                    options
                    .AllowDebuggerStatement(jintSettings.AllowDebuggerStatement)
                    .Constraint(_cancellationConstraint)
                    .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());
                });
            }
            catch (Exception e)
            {
                throw JsErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true);
            }
        }
Beispiel #2
0
        public override void Dispose()
        {
            if (_disposedFlag.Set())
            {
                lock (_executionSynchronizer)
                {
                    _jsEngine = null;
                    _cancellationConstraint = null;

                    if (_cancellationTokenSource != null)
                    {
                        _cancellationTokenSource.Dispose();
                        _cancellationTokenSource = null;
                    }
                }
            }
        }