/// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                _lastException = null;

                if (_siteItems != null)
                {
                    _siteItems.Clear();
                    _siteItems = null;
                }

                if (_dispatch != null)
                {
                    ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                    _dispatch = null;
                }

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

                _activeScript = null;
            }
        }
 protected ActiveScriptJavascriptRuntimeBase(IActiveScript scriptEngine)
 {
     ScriptEngine = scriptEngine;
     ScriptEngine.SetScriptSite(this);
     JsParse = new ActiveScriptParseWrapper(ScriptEngine);
     JsParse.InitNew();
 }
Example #3
0
        /// <summary>
        /// Constructs an instance of the ActiveScript JavaScript engine
        /// </summary>
        /// <param name="clsid">CLSID of JavaScript engine</param>
        /// <param name="engineMode">JavaScript engine mode</param>
        /// <param name="lowerIeVersion">Lowest supported version of Internet Explorer</param>
        /// <param name="languageVersion">Version of script language</param>
        /// <param name="useEcmaScript5Polyfill">Flag for whether to use the ECMAScript 5 Polyfill</param>
        /// <param name="useJson2Library">Flag for whether to use the JSON2 library</param>
        protected ActiveScriptJsEngineBase(string clsid, JsEngineMode engineMode, string lowerIeVersion,
                                           ScriptLanguageVersion languageVersion, bool useEcmaScript5Polyfill, bool useJson2Library)
        {
            _engineMode      = engineMode;
            _engineModeName  = JsEngineModeHelpers.GetModeName(engineMode);
            _documentVersion = DateTime.UtcNow.ToString("o");

            _dispatcher.Invoke(() =>
            {
                _pActiveScript = IntPtr.Zero;

                try
                {
                    _pActiveScript = ComHelpers.CreateInstanceByClsid <IActiveScript>(clsid);
                    _activeScript  = (IActiveScript)Marshal.GetObjectForIUnknown(_pActiveScript);
                }
                catch (Exception e)
                {
                    throw new JsEngineLoadException(
                        string.Format(CommonStrings.Runtime_IeJsEngineNotLoaded,
                                      _engineModeName, lowerIeVersion, e.Message), _engineModeName);
                }

                if (languageVersion != ScriptLanguageVersion.None)
                {
                    var activeScriptProperty = _activeScript as IActiveScriptProperty;
                    if (activeScriptProperty != null)
                    {
                        object scriptLanguageVersion = (int)languageVersion;
                        uint result = activeScriptProperty.SetProperty((uint)ScriptProperty.InvokeVersioning,
                                                                       IntPtr.Zero, ref scriptLanguageVersion);
                        if (result != (uint)ScriptHResult.Ok)
                        {
                            throw new JsEngineLoadException(
                                string.Format(NetFrameworkStrings.Runtime_ActiveScriptLanguageVersionSelectionFailed, languageVersion));
                        }
                    }
                }

                _activeScriptParse = new ActiveScriptParseWrapper(_pActiveScript, _activeScript);
                _activeScriptParse.InitNew();

                _pActiveScriptGarbageCollector = ComHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(_pActiveScript);
                _activeScriptGarbageCollector  = _activeScript as IActiveScriptGarbageCollector;

                _activeScript.SetScriptSite(this);
                _activeScript.SetScriptState(ScriptState.Started);

                InitScriptDispatch();
            });

            LoadResources(useEcmaScript5Polyfill, useJson2Library);
        }
        /// <summary>
        /// Constructs instance of <see cref="ActiveScriptSiteWrapper"/>
        /// </summary>
        /// <param name="pActiveScript">Pointer to an instance of native JavaScript engine</param>
        /// <param name="activeScript">Instance of native JavaScript engine</param>
        /// <param name="documentVersion">Host-defined document version string</param>
        public ActiveScriptSiteWrapper(IntPtr pActiveScript, IActiveScript activeScript,
			string documentVersion)
        {
            _activeScript = activeScript;

            _activeScriptParse = new ActiveScriptParseWrapper(pActiveScript, _activeScript);
            _activeScriptParse.InitNew();

            _activeScript.SetScriptSite(this);
            _activeScript.SetScriptState(ScriptState.Started);

            InitScriptDispatch();

            DocumentVersion = documentVersion;
        }
        /// <summary>
        /// Constructs instance of <see cref="ActiveScriptSiteWrapper"/>
        /// </summary>
        /// <param name="pActiveScript">Pointer to an instance of native JavaScript engine</param>
        /// <param name="activeScript">Instance of native JavaScript engine</param>
        /// <param name="documentVersion">Host-defined document version string</param>
        public ActiveScriptSiteWrapper(IntPtr pActiveScript, IActiveScript activeScript,
                                       string documentVersion)
        {
            _activeScript = activeScript;

            _activeScriptParse = new ActiveScriptParseWrapper(pActiveScript, _activeScript);
            _activeScriptParse.InitNew();

            _activeScript.SetScriptSite(this);
            _activeScript.SetScriptState(ScriptState.Started);

            InitScriptDispatch();

            DocumentVersion = documentVersion;
        }
Example #6
0
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (_disposedFlag.Set())
            {
                _dispatcher.Invoke(() =>
                {
                    if (_dispatch != null)
                    {
                        ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                        _dispatch = null;
                    }

                    _activeScriptGarbageCollector = null;
                    ComHelpers.ReleaseAndEmpty(ref _pActiveScriptGarbageCollector);

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

                    if (_activeScript != null)
                    {
                        _activeScript.Close();
                        Marshal.FinalReleaseComObject(_activeScript);
                        _activeScript = null;
                    }

                    ComHelpers.ReleaseAndEmpty(ref _pActiveScript);
                });

                if (disposing)
                {
                    if (_hostItems != null)
                    {
                        _hostItems.Clear();
                    }

                    _lastException = null;
                }
            }
        }
        public void Initialize()
        {
            try {
                // Prefer Chakra
                _jsEngine = new ChakraJavaScriptEngine() as IActiveScript;
            } catch (Exception e) {
                // TODO: Make catch more specific
                _jsEngine = null;
            }

            if (_jsEngine == null)
            {
                // No need to catch here - engine of last resort
                _jsEngine = new JavaScriptEngine() as IActiveScript;
            }

            _jsEngine.SetScriptSite(this);
            _jsParse = new ActiveScriptParseWrapper(_jsEngine);
            _jsParse.InitNew();
        }
        public void Initialize()
        {
            try
            {
                // Prefer Chakra
                jsEngine = new ChakraJavaScriptEngine() as IActiveScript;
            }
            catch
            {
                jsEngine = null;
            }

            if (jsEngine == null)
            {
                // No need to catch here - engine of last resort
                jsEngine = new JavaScriptEngine() as IActiveScript;
            }

            jsEngine.SetScriptSite(this);
            jsParse = new ActiveScriptParseWrapper(jsEngine);
            jsParse.InitNew();
        }
        /// <summary>
        /// Destroys object
        /// </summary>
        /// <param name="disposing">Flag, allowing destruction of
        /// managed objects contained in fields of class</param>
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                _disposed = true;

                _lastException = null;

                if (_siteItems != null)
                {
                    _siteItems.Clear();
                    _siteItems = null;
                }

                if (_dispatch != null)
                {
                    ComHelpers.ReleaseComObject(ref _dispatch, !disposing);
                    _dispatch = null;
                }

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

                _activeScript = null;
            }
        }