Settings of the Jint JS engine
コード例 #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);
            }
        }
コード例 #2
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 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)
                    .MaxArraySize(jintSettings.MaxArraySize)
                    .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.DebugHandler.Break += _debuggerBreakCallback;
                }
                if (_debuggerStepCallback != null)
                {
                    _jsEngine.DebugHandler.Step += _debuggerStepCallback;
                }
            }
            catch (Exception e)
            {
                throw JsErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true);
            }
        }
		/// <summary>
		/// Adds a instance of <see cref="JintJsEngineFactory"/> to
		/// the specified <see cref="JsEngineFactoryCollection" />
		/// </summary>
		/// <param name="source">Instance of <see cref="JsEngineFactoryCollection" /></param>
		/// <param name="settings">Settings of the Jint JS engine</param>
		/// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
		public static JsEngineFactoryCollection AddJint(this JsEngineFactoryCollection source, JintSettings settings)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}

			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}

			source.Add(new JintJsEngineFactory(settings));

			return source;
		}
		/// <summary>
		/// Adds a instance of <see cref="JintJsEngineFactory"/> to
		/// the specified <see cref="JsEngineFactoryCollection" />
		/// </summary>
		/// <param name="source">Instance of <see cref="JsEngineFactoryCollection" /></param>
		/// <param name="configure">The delegate to configure the provided <see cref="JintSettings"/></param>
		/// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
		public static JsEngineFactoryCollection AddJint(this JsEngineFactoryCollection source,
			Action<JintSettings> configure)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}

			if (configure == null)
			{
				throw new ArgumentNullException("configure");
			}

			var settings = new JintSettings();
			configure(settings);

			return source.AddJint(settings);
		}
        /// <summary>
        /// Adds a instance of <see cref="JintJsEngineFactory"/> to
        /// the specified <see cref="JsEngineFactoryCollection" />
        /// </summary>
        /// <param name="source">Instance of <see cref="JsEngineFactoryCollection" /></param>
        /// <param name="configure">The delegate to configure the provided <see cref="JintSettings"/></param>
        /// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
        public static JsEngineFactoryCollection AddJint(this JsEngineFactoryCollection source,
                                                        Action <JintSettings> configure)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (configure == null)
            {
                throw new ArgumentNullException("configure");
            }

            var settings = new JintSettings();

            configure(settings);

            return(source.AddJint(settings));
        }
コード例 #6
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)
        {
            JintSettings jintSettings = settings ?? new JintSettings();

            try
            {
                _jsEngine = new OriginalEngine(c => c
                                               .AllowDebuggerStatement(jintSettings.AllowDebuggerStatement)
                                               .DebugMode(jintSettings.EnableDebugging)
                                               .LimitRecursion(jintSettings.MaxRecursionDepth)
                                               .LocalTimeZone(jintSettings.LocalTimeZone ?? TimeZoneInfo.Local)
                                               .MaxStatements(jintSettings.MaxStatements)
                                               .Strict(jintSettings.StrictMode)
                                               .TimeoutInterval(jintSettings.TimeoutInterval)
                                               );
            }
            catch (Exception e)
            {
                throw JsErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true);
            }
        }
コード例 #7
0
        /// <summary>
        /// Constructs a instance of adapter for the Jint JS engine
        /// </summary>
        /// <param name="settings">Settings of the Jint JS engine</param>
        public JintJsEngine(JintSettings settings)
        {
            JintSettings jintSettings = settings ?? new JintSettings();

            try
            {
                _jsEngine = new OriginalJsEngine(c => c
                                                 .AllowDebuggerStatement(jintSettings.AllowDebuggerStatement)
                                                 .DebugMode(jintSettings.EnableDebugging)
                                                 .LimitRecursion(jintSettings.MaxRecursionDepth)
                                                 .MaxStatements(jintSettings.MaxStatements)
                                                 .Strict(jintSettings.StrictMode)
                                                 .TimeoutInterval(TimeSpan.FromMilliseconds(jintSettings.Timeout))
                                                 );
            }
            catch (Exception e)
            {
                throw new JsEngineLoadException(
                          string.Format(CoreStrings.Runtime_JsEngineNotLoaded,
                                        EngineName, e.Message), EngineName, EngineVersion, e);
            }
        }
コード例 #8
0
 /// <summary>
 /// Constructs an instance of the Jint JS engine factory
 /// </summary>
 /// <param name="settings">Settings of the Jint JS engine</param>
 public JintJsEngineFactory(JintSettings settings)
 {
     _settings = settings;
 }
        /// <summary>
        /// Adds a instance of <see cref="JintJsEngineFactory"/> to
        /// the specified <see cref="JsEngineFactoryCollection" />
        /// </summary>
        /// <param name="source">Instance of <see cref="JsEngineFactoryCollection" /></param>
        /// <param name="settings">Settings of the Jint JS engine</param>
        /// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
        public static JsEngineFactoryCollection AddJint(this JsEngineFactoryCollection source, JintSettings settings)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            source.Add(new JintJsEngineFactory(settings));

            return(source);
        }
コード例 #10
0
		/// <summary>
		/// Constructs an instance of the Jint JS engine factory
		/// </summary>
		/// <param name="settings">Settings of the Jint JS engine</param>
		public JintJsEngineFactory(JintSettings settings)
		{
			_settings = settings;
		}