Ejemplo n.º 1
0
        public ActiveScriptWrapper32(string progID)
        {
            pActiveScript                 = RawCOMHelpers.CreateInstance <IActiveScript>(progID);
            pActiveScriptParse            = RawCOMHelpers.QueryInterface <IActiveScriptParse32>(pActiveScript);
            pActiveScriptDebug            = RawCOMHelpers.QueryInterface <IActiveScriptDebug32>(pActiveScript);
            pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript);
            pDebugStackFrameSniffer       = RawCOMHelpers.QueryInterface <IDebugStackFrameSnifferEx32>(pActiveScript);

            activeScript                 = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
            activeScriptParse            = (IActiveScriptParse32)activeScript;
            activeScriptDebug            = (IActiveScriptDebug32)activeScript;
            activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector;
            debugStackFrameSniffer       = (IDebugStackFrameSnifferEx32)activeScript;
        }
Ejemplo n.º 2
0
        public override void Close()
        {
            activeScript.Close();

            debugStackFrameSniffer       = null;
            activeScriptGarbageCollector = null;
            activeScriptDebug            = null;
            activeScriptParse            = null;
            activeScript = null;

            RawCOMHelpers.ReleaseAndEmpty(ref pDebugStackFrameSniffer);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptGarbageCollector);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptDebug);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptParse);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScript);
        }
Ejemplo n.º 3
0
        public override void Close()
        {
            debugStackFrameSniffer       = null;
            activeScriptGarbageCollector = null;
            activeScriptDebug            = null;
            activeScriptParse            = null;

            UnknownHelpers.ReleaseAndEmpty(ref pDebugStackFrameSniffer);
            UnknownHelpers.ReleaseAndEmpty(ref pActiveScriptGarbageCollector);
            UnknownHelpers.ReleaseAndEmpty(ref pActiveScriptDebug);
            UnknownHelpers.ReleaseAndEmpty(ref pActiveScriptParse);
            UnknownHelpers.ReleaseAndEmpty(ref pActiveScript);

            activeScript.Close();
            Marshal.FinalReleaseComObject(activeScript);
            activeScript = null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructs an instance of the Active Script wrapper
        /// </summary>
        /// <param name="clsid">CLSID of script engine</param>
        /// <param name="languageVersion">Version of script language</param>
        public ActiveScriptWrapper(string clsid, ScriptLanguageVersion languageVersion)
        {
            _is64Bit = Utils.Is64BitProcess();

            _pActiveScript = ComHelpers.CreateInstanceByClsid <IActiveScript>(clsid);
            if (_is64Bit)
            {
                _pActiveScriptParse64 = ComHelpers.QueryInterface <IActiveScriptParse64>(_pActiveScript);
                _pActiveScriptDebug64 = ComHelpers.QueryInterface <IActiveScriptDebug64>(_pActiveScript);
            }
            else
            {
                _pActiveScriptParse32 = ComHelpers.QueryInterface <IActiveScriptParse32>(_pActiveScript);
                _pActiveScriptDebug32 = ComHelpers.QueryInterface <IActiveScriptDebug32>(_pActiveScript);
            }
            _pActiveScriptGarbageCollector = ComHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(_pActiveScript);

            _activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(_pActiveScript);
            if (_is64Bit)
            {
                _activeScriptParse64 = (IActiveScriptParse64)_activeScript;
            }
            else
            {
                _activeScriptParse32 = (IActiveScriptParse32)_activeScript;
            }
            _activeScriptGarbageCollector = _activeScript as IActiveScriptGarbageCollector;

            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));
                    }
                }
            }
        }
Ejemplo n.º 5
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;
                }
            }
        }
Ejemplo n.º 6
0
        public ActiveScriptWrapper64(string progID, WindowsScriptEngineFlags flags)
        {
            // ReSharper disable SuspiciousTypeConversion.Global

            pActiveScript                 = RawCOMHelpers.CreateInstance <IActiveScript>(progID);
            pActiveScriptParse            = RawCOMHelpers.QueryInterface <IActiveScriptParse64>(pActiveScript);
            pActiveScriptDebug            = RawCOMHelpers.QueryInterface <IActiveScriptDebug64>(pActiveScript);
            pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript);
            pDebugStackFrameSniffer       = RawCOMHelpers.QueryInterfaceNoThrow <IDebugStackFrameSnifferEx64>(pActiveScript);

            activeScript                 = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
            activeScriptParse            = (IActiveScriptParse64)activeScript;
            activeScriptDebug            = (IActiveScriptDebug64)activeScript;
            activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector;
            debugStackFrameSniffer       = activeScript as IDebugStackFrameSnifferEx64;

            if (flags.HasFlag(WindowsScriptEngineFlags.EnableStandardsMode))
            {
                var activeScriptProperty = activeScript as IActiveScriptProperty;
                if (activeScriptProperty != null)
                {
                    object name;
                    activeScriptProperty.GetProperty(ScriptProp.Name, IntPtr.Zero, out name);
                    if (Equals(name, "JScript"))
                    {
                        object value = ScriptLanguageVersion.Standards;
                        activeScriptProperty.SetProperty(ScriptProp.InvokeVersioning, IntPtr.Zero, ref value);
                    }
                }

                if (!flags.HasFlag(WindowsScriptEngineFlags.DoNotEnableVTablePatching) && MiscHelpers.IsX86InstructionSet())
                {
                    HostItem.EnableVTablePatching = true;
                }
            }

            // ReSharper restore SuspiciousTypeConversion.Global
        }
Ejemplo n.º 7
0
        public ActiveScriptWrapper32(string progID, WindowsScriptEngineFlags flags)
        {
            // ReSharper disable SuspiciousTypeConversion.Global

            pActiveScript                 = ActivationHelpers.CreateInstance <IActiveScript>(progID);
            pActiveScriptParse            = UnknownHelpers.QueryInterface <IActiveScriptParse32>(pActiveScript);
            pActiveScriptDebug            = UnknownHelpers.QueryInterface <IActiveScriptDebug32>(pActiveScript);
            pActiveScriptGarbageCollector = UnknownHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript);
            pDebugStackFrameSniffer       = UnknownHelpers.QueryInterfaceNoThrow <IDebugStackFrameSnifferEx32>(pActiveScript);

            activeScript                 = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
            activeScriptParse            = (IActiveScriptParse32)activeScript;
            activeScriptDebug            = (IActiveScriptDebug32)activeScript;
            activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector;
            debugStackFrameSniffer       = activeScript as IDebugStackFrameSnifferEx32;

            if (flags.HasFlag(WindowsScriptEngineFlags.EnableStandardsMode))
            {
                if (activeScript is IActiveScriptProperty activeScriptProperty)
                {
                    activeScriptProperty.GetProperty(ScriptProp.Name, IntPtr.Zero, out var name);
                    if (Equals(name, "JScript"))
                    {
                        object value = ScriptLanguageVersion.Standards;
                        activeScriptProperty.SetProperty(ScriptProp.InvokeVersioning, IntPtr.Zero, ref value);
                    }
                }

                if (!flags.HasFlag(WindowsScriptEngineFlags.DoNotEnableVTablePatching) && MiscHelpers.ProcessorArchitectureIsIntel())
                {
                    HostItem.EnableVTablePatching = true;
                }
            }

            // ReSharper restore SuspiciousTypeConversion.Global
        }
Ejemplo n.º 8
0
        public override void Close()
        {
            activeScript.Close();

            debugStackFrameSniffer = null;
            activeScriptGarbageCollector = null;
            activeScriptDebug = null;
            activeScriptParse = null;
            activeScript = null;

            RawCOMHelpers.ReleaseAndEmpty(ref pDebugStackFrameSniffer);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptGarbageCollector);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptDebug);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScriptParse);
            RawCOMHelpers.ReleaseAndEmpty(ref pActiveScript);
        }
Ejemplo n.º 9
0
        public ActiveScriptWrapper64(string progID)
        {
            pActiveScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID);
            pActiveScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse64>(pActiveScript);
            pActiveScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug64>(pActiveScript);
            pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow<IActiveScriptGarbageCollector>(pActiveScript);
            pDebugStackFrameSniffer = RawCOMHelpers.QueryInterface<IDebugStackFrameSnifferEx64>(pActiveScript);

            activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
            activeScriptParse = (IActiveScriptParse64)activeScript;
            activeScriptDebug = (IActiveScriptDebug64)activeScript;
            activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector;
            debugStackFrameSniffer = (IDebugStackFrameSnifferEx64)activeScript;
        }
Ejemplo n.º 10
0
        public ActiveScriptWrapper64(string progID, WindowsScriptEngineFlags flags)
        {
            pActiveScript = RawCOMHelpers.CreateInstance<IActiveScript>(progID);
            pActiveScriptParse = RawCOMHelpers.QueryInterface<IActiveScriptParse64>(pActiveScript);
            pActiveScriptDebug = RawCOMHelpers.QueryInterface<IActiveScriptDebug64>(pActiveScript);
            pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow<IActiveScriptGarbageCollector>(pActiveScript);
            pDebugStackFrameSniffer = RawCOMHelpers.QueryInterface<IDebugStackFrameSnifferEx64>(pActiveScript);

            activeScript = (IActiveScript)Marshal.GetObjectForIUnknown(pActiveScript);
            activeScriptParse = (IActiveScriptParse64)activeScript;
            activeScriptDebug = (IActiveScriptDebug64)activeScript;
            activeScriptGarbageCollector = activeScript as IActiveScriptGarbageCollector;
            debugStackFrameSniffer = (IDebugStackFrameSnifferEx64)activeScript;

            if (flags.HasFlag(WindowsScriptEngineFlags.EnableStandardsMode))
            {
                var activeScriptProperty = activeScript as IActiveScriptProperty;
                if (activeScriptProperty != null)
                {
                    object name;
                    activeScriptProperty.GetProperty(ScriptProp.Name, IntPtr.Zero, out name);
                    if (Equals(name, "JScript"))
                    {
                        object value = ScriptLanguageVersion.Standards;
                        activeScriptProperty.SetProperty(ScriptProp.InvokeVersioning, IntPtr.Zero, ref value);
                    }
                }
            }
        }