Settings of the ChakraCore JS engine
		/// <summary>
		/// Adds a instance of <see cref="ChakraCoreJsEngineFactory"/> to
		/// the specified <see cref="JsEngineFactoryCollection" />
		/// </summary>
		/// <param name="source">Instance of <see cref="JsEngineFactoryCollection" /></param>
		/// <param name="settings">Settings of the ChakraCore JS engine</param>
		/// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
		public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source, ChakraCoreSettings settings)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}

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

			source.Add(new ChakraCoreJsEngineFactory(settings));

			return source;
		}
		/// <summary>
		/// Adds a instance of <see cref="ChakraCoreJsEngineFactory"/> 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="ChakraCoreSettings"/></param>
		/// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
		public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source,
			Action<ChakraCoreSettings> configure)
		{
			if (source == null)
			{
				throw new ArgumentNullException("source");
			}

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

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

			return source.AddChakraCore(settings);
		}
        /// <summary>
        /// Adds a instance of <see cref="ChakraCoreJsEngineFactory"/> 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="ChakraCoreSettings"/></param>
        /// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
        public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source,
                                                              Action <ChakraCoreSettings> configure)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

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

            var settings = new ChakraCoreSettings();

            configure(settings);

            return(source.AddChakraCore(settings));
        }
Exemple #4
0
        /// <summary>
        /// Constructs an instance of adapter for the ChakraCore JS engine
        /// </summary>
        /// <param name="settings">Settings of the ChakraCore JS engine</param>
        public ChakraCoreJsEngine(ChakraCoreSettings settings)
        {
            ChakraCoreSettings chakraCoreSettings = settings ?? new ChakraCoreSettings();

            JsRuntimeAttributes attributes = JsRuntimeAttributes.None;

            if (chakraCoreSettings.DisableBackgroundWork)
            {
                attributes |= JsRuntimeAttributes.DisableBackgroundWork;
            }
            if (chakraCoreSettings.DisableNativeCodeGeneration)
            {
                attributes |= JsRuntimeAttributes.DisableNativeCodeGeneration;
            }
            if (chakraCoreSettings.DisableEval)
            {
                attributes |= JsRuntimeAttributes.DisableEval;
            }
            if (chakraCoreSettings.EnableExperimentalFeatures)
            {
                attributes |= JsRuntimeAttributes.EnableExperimentalFeatures;
            }

            _externalObjectFinalizeCallback = ExternalObjectFinalizeCallback;

            _dispatcher.Invoke(() =>
            {
                try
                {
                    _jsRuntime = JsRuntime.Create(attributes, null);
                    _jsContext = _jsRuntime.CreateContext();
                    _jsContext.AddRef();
                }
                catch (Exception e)
                {
                    throw new JsEngineLoadException(
                        string.Format(CoreStrings.Runtime_JsEngineNotLoaded,
                                      EngineName, e.Message), EngineName, EngineVersion, e);
                }
            });
        }
Exemple #5
0
        /// <summary>
        /// Constructs an instance of adapter for the ChakraCore JS engine
        /// </summary>
        /// <param name="settings">Settings of the ChakraCore JS engine</param>
        public ChakraCoreJsEngine(ChakraCoreSettings settings)
        {
#if NETFULL
            Initialize();
#endif
            ChakraCoreSettings chakraCoreSettings = settings ?? new ChakraCoreSettings();

            JsRuntimeAttributes attributes = JsRuntimeAttributes.AllowScriptInterrupt;
            if (chakraCoreSettings.DisableBackgroundWork)
            {
                attributes |= JsRuntimeAttributes.DisableBackgroundWork;
            }
            if (chakraCoreSettings.DisableEval)
            {
                attributes |= JsRuntimeAttributes.DisableEval;
            }
            if (chakraCoreSettings.DisableExecutablePageAllocation)
            {
                attributes |= JsRuntimeAttributes.DisableExecutablePageAllocation;
            }
            if (chakraCoreSettings.DisableFatalOnOOM)
            {
                attributes |= JsRuntimeAttributes.DisableFatalOnOOM;
            }
            if (chakraCoreSettings.DisableNativeCodeGeneration)
            {
                attributes |= JsRuntimeAttributes.DisableNativeCodeGeneration;
            }
            if (chakraCoreSettings.EnableExperimentalFeatures)
            {
                attributes |= JsRuntimeAttributes.EnableExperimentalFeatures;
            }

#if NETSTANDARD1_3
            _dispatcher = new ScriptDispatcher();
#else
            _dispatcher = new ScriptDispatcher(chakraCoreSettings.MaxStackSize);
#endif
            _promiseContinuationCallback = PromiseContinuationCallback;

            try
            {
                _dispatcher.Invoke(() =>
                {
                    _jsRuntime             = JsRuntime.Create(attributes, null);
                    _jsRuntime.MemoryLimit = settings.MemoryLimit;

                    _jsContext = _jsRuntime.CreateContext();
                    if (_jsContext.IsValid)
                    {
                        _jsContext.AddRef();
                    }
                });
            }
            catch (DllNotFoundException e)
            {
                throw WrapDllNotFoundException(e);
            }
            catch (Exception e)
            {
                throw CoreErrorHelpers.WrapEngineLoadException(e, EngineName, EngineVersion, true);
            }
            finally
            {
                if (!_jsContext.IsValid)
                {
                    Dispose();
                }
            }
        }
 /// <summary>
 /// Constructs an instance of the ChakraCore JS engine factory
 /// </summary>
 /// <param name="settings">Settings of the ChakraCore JS engine</param>
 public ChakraCoreJsEngineFactory(ChakraCoreSettings settings)
 {
     _settings = settings;
 }
        /// <summary>
        /// Adds a instance of <see cref="ChakraCoreJsEngineFactory"/> to
        /// the specified <see cref="JsEngineFactoryCollection" />
        /// </summary>
        /// <param name="source">Instance of <see cref="JsEngineFactoryCollection" /></param>
        /// <param name="settings">Settings of the ChakraCore JS engine</param>
        /// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
        public static JsEngineFactoryCollection AddChakraCore(this JsEngineFactoryCollection source, ChakraCoreSettings settings)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

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

            source.Add(new ChakraCoreJsEngineFactory(settings));

            return(source);
        }
		/// <summary>
		/// Constructs an instance of the ChakraCore JS engine factory
		/// </summary>
		/// <param name="settings">Settings of the ChakraCore JS engine</param>
		public ChakraCoreJsEngineFactory(ChakraCoreSettings settings)
		{
			_settings = settings;
		}