示例#1
0
        /// <summary>
        /// Constructs instance of MSIE JavaScript engine
        /// </summary>
        /// <param name="settings">JavaScript engine settings</param>
        /// <exception cref="MsieJavaScriptEngine.JsEngineLoadException">Failed to load a JavaScript engine.</exception>
        /// <exception cref="System.NotSupportedException">Selected mode of JavaScript engine is not supported.</exception>
        public MsieJsEngine(JsEngineSettings settings)
        {
            JsEngineMode engineMode          = settings.EngineMode;
            JsEngineMode processedEngineMode = engineMode;

            if (engineMode == JsEngineMode.Auto)
            {
                if (ChakraJsRtJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.ChakraJsRt;
                }
                else if (ChakraActiveScriptJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.ChakraActiveScript;
                }
                else if (ClassicActiveScriptJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.Classic;
                }
                else
                {
                    throw new JsEngineLoadException(Strings.Runtime_JsEnginesNotFound);
                }
            }

            switch (processedEngineMode)
            {
            case JsEngineMode.ChakraJsRt:
                _jsEngine = new ChakraJsRtJsEngine();
                break;

            case JsEngineMode.ChakraActiveScript:
                _jsEngine = new ChakraActiveScriptJsEngine();
                break;

            case JsEngineMode.Classic:
                _jsEngine = new ClassicActiveScriptJsEngine(settings.UseEcmaScript5Polyfill,
                                                            settings.UseJson2Library);
                break;

            default:
                throw new NotSupportedException(
                          string.Format(Strings.Runtime_JsEngineModeNotSupported, processedEngineMode));
            }
        }
示例#2
0
        /// <summary>
        /// Constructs instance of MSIE JavaScript engine
        /// </summary>
        /// <param name="settings">JavaScript engine settings</param>
        /// <exception cref="MsieJavaScriptEngine.JsEngineLoadException">Failed to load a JavaScript engine.</exception>
        /// <exception cref="System.NotSupportedException">Selected mode of JavaScript engine is not supported.</exception>
        public MsieJsEngine(JsEngineSettings settings)
        {
            JsEngineMode engineMode          = settings.EngineMode;
            JsEngineMode processedEngineMode = engineMode;

            if (engineMode == JsEngineMode.Auto)
            {
                if (ChakraEdgeJsRtJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.ChakraEdgeJsRt;
                }
                else if (ChakraIeJsRtJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.ChakraIeJsRt;
                }
#if !NETSTANDARD1_3
                else if (ChakraActiveScriptJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.ChakraActiveScript;
                }
                else if (ClassicActiveScriptJsEngine.IsSupported())
                {
                    processedEngineMode = JsEngineMode.Classic;
                }
#endif
                else
                {
                    throw new JsEngineLoadException(
#if NETSTANDARD1_3
                              NetCoreStrings.Runtime_JsEnginesNotFound
#else
                              NetFrameworkStrings.Runtime_JsEnginesNotFound
#endif
                              );
                }
            }

            lock (_creationSynchronizer)
            {
                JsEngineMode previousMode = _currentMode;

                switch (processedEngineMode)
                {
                case JsEngineMode.ChakraEdgeJsRt:
                    if (previousMode != JsEngineMode.ChakraIeJsRt &&
                        previousMode != JsEngineMode.ChakraActiveScript)
                    {
                        _jsEngine = new ChakraEdgeJsRtJsEngine(settings.EnableDebugging);
                    }
                    else if (previousMode == JsEngineMode.ChakraIeJsRt)
                    {
                        throw new JsEngineLoadException(
                                  string.Format(
                                      CommonStrings.Runtime_JsEnginesConflictInProcess,
                                      JsEngineModeHelpers.GetModeName(processedEngineMode),
                                      JsEngineModeHelpers.GetModeName(previousMode)
                                      )
                                  );
                    }
                    else if (previousMode == JsEngineMode.ChakraActiveScript)
                    {
                        throw new JsEngineLoadException(
                                  string.Format(
                                      CommonStrings.Runtime_JsEnginesConflictInProcess,
                                      JsEngineModeHelpers.GetModeName(processedEngineMode),
                                      JsEngineModeHelpers.GetModeName(previousMode)
                                      )
                                  );
                    }

                    break;

                case JsEngineMode.ChakraIeJsRt:
                    if (previousMode != JsEngineMode.ChakraEdgeJsRt)
                    {
                        _jsEngine = new ChakraIeJsRtJsEngine(settings.EnableDebugging);
                    }
                    else
                    {
                        throw new JsEngineLoadException(
                                  string.Format(
                                      CommonStrings.Runtime_JsEnginesConflictInProcess,
                                      JsEngineModeHelpers.GetModeName(processedEngineMode),
                                      JsEngineModeHelpers.GetModeName(previousMode)
                                      )
                                  );
                    }

                    break;

                case JsEngineMode.ChakraActiveScript:
#if !NETSTANDARD1_3
                    if (previousMode != JsEngineMode.ChakraEdgeJsRt)
                    {
                        _jsEngine = new ChakraActiveScriptJsEngine();
                    }
                    else
                    {
                        throw new JsEngineLoadException(
                                  string.Format(
                                      CommonStrings.Runtime_JsEnginesConflictInProcess,
                                      JsEngineModeHelpers.GetModeName(processedEngineMode),
                                      JsEngineModeHelpers.GetModeName(previousMode)
                                      )
                                  );
                    }

                    break;
#else
                    throw new NotSupportedException(
                              string.Format(NetCoreStrings.Runtime_JsEngineModeNotCompatibleWithNetCore, processedEngineMode));
#endif
                case JsEngineMode.Classic:
#if !NETSTANDARD1_3
                    _jsEngine = new ClassicActiveScriptJsEngine(settings.UseEcmaScript5Polyfill,
                                                                settings.UseJson2Library);

                    break;
#else
                    throw new NotSupportedException(
                              string.Format(NetCoreStrings.Runtime_JsEngineModeNotCompatibleWithNetCore, processedEngineMode));
#endif
                default:
                    throw new NotSupportedException(
                              string.Format(CommonStrings.Runtime_JsEngineModeNotSupported, processedEngineMode));
                }

                _currentMode = processedEngineMode;
            }
        }