Inheritance: IActiveScriptSite, IDisposable
        private void InnerDispose()
        {
            if (!_disposed)
            {
                _disposed = true;

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

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

                ComHelpers.ReleaseAndEmpty(ref _pActiveScript);
            }
        }
        /// <summary>
        /// Constructs instance of the ActiveScript JavaScript engine
        /// </summary>
        /// <param name="clsid">CLSID of JavaScript engine</param>
        /// <param name="engineModeName">Name of JavaScript engine mode</param>
        /// <param name="lowerIeVersion">Lowest supported version of Internet Explorer</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, string engineModeName, string lowerIeVersion,
                                           bool useEcmaScript5Polyfill, bool useJson2Library)
        {
            _engineModeName = engineModeName;
            _lowerIeVersion = lowerIeVersion;

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

            _activeScriptSite = new ActiveScriptSiteWrapper(_pActiveScript, _activeScript);

            LoadResources(useEcmaScript5Polyfill, useJson2Library);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs instance of the ActiveScript JavaScript engine
        /// </summary>
        /// <param name="clsid">CLSID of JavaScript engine</param>
        /// <param name="engineModeName">Name of 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, string engineModeName, string lowerIeVersion,
                                           ScriptLanguageVersion languageVersion, bool useEcmaScript5Polyfill, bool useJson2Library)
        {
            _engineModeName = engineModeName;
            _pActiveScript  = IntPtr.Zero;

            try
            {
                _pActiveScript = ComHelpers.CreateInstanceByClsid <IActiveScript>(clsid);
                _activeScript  = (IActiveScript)Marshal.GetObjectForIUnknown(_pActiveScript);
            }
            catch (Exception e)
            {
                throw new JsEngineLoadException(
                          string.Format(Strings.Runtime_JsEngineNotLoaded,
                                        _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(Strings.Runtime_ActiveScriptLanguageVersionSelectionFailed, languageVersion));
                    }
                }
            }

            _activeScriptSite = new ActiveScriptSiteWrapper(_pActiveScript, _activeScript);

            LoadResources(useEcmaScript5Polyfill, useJson2Library);
        }