/// <summary> /// Destroys object /// </summary> public void Dispose() { if (_disposedFlag.Set()) { _activeScriptGarbageCollector = null; if (_is64Bit) { _activeScriptParse64 = null; } else { _activeScriptParse32 = null; } ComHelpers.ReleaseAndEmpty(ref _pActiveScriptGarbageCollector); if (_is64Bit) { ComHelpers.ReleaseAndEmpty(ref _pActiveScriptDebug64); ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse64); } else { ComHelpers.ReleaseAndEmpty(ref _pActiveScriptDebug32); ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse32); } ComHelpers.ReleaseAndEmpty(ref _pActiveScript); if (_activeScript != null) { _activeScript.Close(); Marshal.FinalReleaseComObject(_activeScript); _activeScript = null; } } }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param> public ScriptEngine(string language) { if (language == null) { throw new ArgumentNullException("language"); } Type engine = Type.GetTypeFromProgID(language, true); _engine = Activator.CreateInstance(engine) as IActiveScript; if (_engine == null) { throw new ArgumentException(language + " is not an Windows Script Engine", "language"); } _site = new ScriptSite(); _engine.SetScriptSite(_site); // support 32-bit & 64-bit process if (IntPtr.Size == 4) { _parse32 = _engine as IActiveScriptParse32; _parse32.InitNew(); } else { _parse64 = _engine as IActiveScriptParse64; _parse64.InitNew(); } }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param> public ScriptEngine() { var guid = new System.Guid("{16d51579-a30b-4c8b-a276-0ff4dc41e755}"); // Chakra IE9/IE10 JS Engine Type t = Type.GetTypeFromCLSID(guid, true); _engine = Activator.CreateInstance(t) as IActiveScript; if (_engine == null) { throw new Exception("Unable to initialize the Chakra engine."); } _site = new ScriptSite(); _engine.SetScriptSite(_site); if (IntPtr.Size == 4) { _parse32 = _engine as IActiveScriptParse32; _parse32.InitNew(); } else { _parse64 = _engine as IActiveScriptParse64; _parse64.InitNew(); } }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> public ScriptEngine() { try { _engine = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("{16d51579-a30b-4c8b-a276-0ff4dc41e755}"), true)) as IActiveScript; } catch { _engine = Activator.CreateInstance(Type.GetTypeFromProgID("javascript", true)) as IActiveScript; } Site = new ScriptSite(); _engine.SetScriptSite(Site); // support 32-bit & 64-bit process if (IntPtr.Size == 4) { _parse32 = (IActiveScriptParse32)_engine; _parse32.InitNew(); } else { _parse64 = (IActiveScriptParse64)_engine; _parse64.InitNew(); } }
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.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); } } } // ReSharper restore SuspiciousTypeConversion.Global }
public ActiveScriptParse(IActiveScriptParse64 activeScriptParse) { if (activeScriptParse == null) { throw new ArgumentNullException("activeScriptParse"); } this.activeScriptParse64 = activeScriptParse; this.is64Bit = true; }
internal ActiveScriptParseWrapper(object comObject) { if (IntPtr.Size == 4) { asp32 = (IActiveScriptParse32)comObject; } else { asp64 = (IActiveScriptParse64)comObject; } }
public static object CreateScriptObject(ScriptSiteBase scriptSite, string scriptText) { IActiveScript engine = (IActiveScript)engineCache[scriptSite]; IActiveScriptParse32 parser32 = null; IActiveScriptParse64 parser64 = null; if (IntPtr.Size == 4) { parser32 = (IActiveScriptParse32)engine; } else { parser64 = (IActiveScriptParse64)engine; } if (engine == null) { engine = (IActiveScript) new JScriptEngine(); engine.SetScriptSite(scriptSite); foreach (string name in scriptSite.GetNamedItems()) { engine.AddNamedItem(name, ScriptItem.IsVisible); } if (IntPtr.Size == 4) { parser32 = (IActiveScriptParse32)engine; parser32.InitNew(); } else { parser64 = (IActiveScriptParse64)engine; parser64.InitNew(); } engineCache.Add(scriptSite, engine); } EXCEPINFO ei; object result; IScript scriptObject; if (IntPtr.Size == 4) { parser32.ParseScriptText(scriptText, null, null, null, IntPtr.Zero, 1, ScriptText.None, out result, out ei); } else { parser64.ParseScriptText(scriptText, null, null, null, IntPtr.Zero, 1, ScriptText.None, out result, out ei); } engine.GetScriptDispatch(null, out scriptObject); return(scriptObject); }
internal void InitializeParsers(IActiveScript engine) { if (this.isParse32) { this.parse32 = (IActiveScriptParse32)engine; this.parse32.InitNew(); } else { this.parse64 = (IActiveScriptParse64)engine; this.parse64.InitNew(); } }
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; }
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); }
/// <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()) { if (_is64Bit) { _activeScriptParse64 = null; ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse64); } else { _activeScriptParse32 = null; ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse32); } } }
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; }
public static ActiveScriptParse MakeActiveScriptParse(object activeScriptParse) { IActiveScriptParse64 parser64 = activeScriptParse as IActiveScriptParse64; if (parser64 != null) { return(new ActiveScriptParse(parser64)); } IActiveScriptParse32 parser32 = activeScriptParse as IActiveScriptParse32; if (parser32 != null) { return(new ActiveScriptParse(parser32)); } throw new ArgumentException("Unable to get parser interface", "activeScriptParse"); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (_parse32 != null) { Marshal.ReleaseComObject(_parse32); _parse32 = null; } if (_parse64 != null) { Marshal.ReleaseComObject(_parse64); _parse64 = null; } if (_engine != null) { Marshal.ReleaseComObject(_engine); _engine = null; } }
/// <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)); } } } }
/// <summary> /// Constructs instance of the <see cref="ActiveScriptParseWrapper"/> class /// </summary> /// <param name="pActiveScript">Pointer to an instance of native JavaScript engine</param> /// <param name="activeScript">Instance of native JavaScript engine. /// Must implement IActiveScriptParse32 or IActiveScriptParse64.</param> public ActiveScriptParseWrapper(IntPtr pActiveScript, IActiveScript activeScript) { _is64Bit = Environment.Is64BitProcess; if (_is64Bit) { _pActiveScriptParse64 = ComHelpers.QueryInterface<IActiveScriptParse64>(pActiveScript); _activeScriptParse64 = activeScript as IActiveScriptParse64; } else { _pActiveScriptParse32 = ComHelpers.QueryInterface<IActiveScriptParse32>(pActiveScript); _activeScriptParse32 = activeScript as IActiveScriptParse32; } if (_activeScriptParse64 == null && _activeScriptParse32 == null) { throw new NotSupportedException(Strings.Runtime_InvalidParserImplementationError); } }
/// <summary> /// Constructs instance of the <see cref="ActiveScriptParseWrapper"/> class /// </summary> /// <param name="pActiveScript">Pointer to an instance of native JavaScript engine</param> /// <param name="activeScript">Instance of native JavaScript engine. /// Must implement IActiveScriptParse32 or IActiveScriptParse64.</param> public ActiveScriptParseWrapper(IntPtr pActiveScript, IActiveScript activeScript) { _is64Bit = Utils.Is64BitProcess(); if (_is64Bit) { _pActiveScriptParse64 = ComHelpers.QueryInterface <IActiveScriptParse64>(pActiveScript); _activeScriptParse64 = activeScript as IActiveScriptParse64; } else { _pActiveScriptParse32 = ComHelpers.QueryInterface <IActiveScriptParse32>(pActiveScript); _activeScriptParse32 = activeScript as IActiveScriptParse32; } if (_activeScriptParse64 == null && _activeScriptParse32 == null) { throw new NotSupportedException(NetFrameworkStrings.Runtime_InvalidParserImplementationError); } }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param> public ScriptEngine(string language) { if (language == null) { throw new ArgumentNullException(nameof(language)); } Type engine; Guid clsid; if (Guid.TryParse(language, out clsid)) { engine = Type.GetTypeFromCLSID(clsid, true); } else { engine = Type.GetTypeFromProgID(language, true); } _engine = Activator.CreateInstance(engine) as IActiveScript; if (_engine == null) { throw new ArgumentException(language + " is not an Windows Script Engine", nameof(language)); } Site = new ScriptSite(); _engine.SetScriptSite(Site); // support 32-bit & 64-bit process if (IntPtr.Size == 4) { _parse32 = (IActiveScriptParse32)_engine; _parse32.InitNew(); } else { _parse64 = (IActiveScriptParse64)_engine; _parse64.InitNew(); } }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param> public ScriptEngine(string language) { if (language == null) { throw new ArgumentNullException("language"); } // support CLSID format (for chakra support that doesn't have a name on its own) Type engine; Guid clsid; if (Guid.TryParse(language, out clsid)) { engine = Type.GetTypeFromCLSID(clsid, true); } else { engine = Type.GetTypeFromProgID(language, true); } _engine = Activator.CreateInstance(engine) as IActiveScript; if (_engine == null) { throw new ArgumentException(language + " is not an Windows Script Engine", "language"); } _site = new ScriptSite(); _engine.SetScriptSite(_site); // support 32-bit & 64-bit process if (IntPtr.Size == 4) { _parse32 = _engine as IActiveScriptParse32; _parse32.InitNew(); } else { _parse64 = _engine as IActiveScriptParse64; _parse64.InitNew(); } }
public ActiveScriptWrapper64(string progID, WindowsScriptEngineFlags flags) { // ReSharper disable SuspiciousTypeConversion.Global pActiveScript = ActivationHelpers.CreateInstance <IActiveScript>(progID); pActiveScriptParse = UnknownHelpers.QueryInterface <IActiveScriptParse64>(pActiveScript); pActiveScriptDebug = UnknownHelpers.QueryInterface <IActiveScriptDebug64>(pActiveScript); pActiveScriptGarbageCollector = UnknownHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript); pDebugStackFrameSniffer = UnknownHelpers.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)) { 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.IsX86InstructionSet()) { HostItem.EnableVTablePatching = true; } } // ReSharper restore SuspiciousTypeConversion.Global }
protected virtual void Dispose(bool disposing) { if (disposing) { } if (_parse32 != null) { Marshal.ReleaseComObject(_parse32); _parse32 = null; } if (_parse64 != null) { Marshal.ReleaseComObject(_parse64); _parse64 = null; } if (_engine != null) { Marshal.ReleaseComObject(_engine); _engine = null; } }
/// <summary> /// Initializes a new instance of the <see cref="ScriptEngine"/> class. /// </summary> /// <param name="language">The scripting language. Standard Windows Script engines names are 'jscript' or 'vbscript'.</param> public ScriptEngine(string language) { if (language == null) throw new ArgumentNullException("language"); Type engine = Type.GetTypeFromProgID(language, true); this.engine = Activator.CreateInstance(engine) as IActiveScript; if (this.engine == null) throw new ArgumentException(language + " is not an Windows Script Engine", "language"); Site = new ScriptSite(); this.engine.SetScriptSite(Site); // support 32-bit & 64-bit process if (IntPtr.Size == 4) { parse32 = this.engine as IActiveScriptParse32; parse32.InitNew(); } else { parse64 = this.engine as IActiveScriptParse64; parse64.InitNew(); } }
void IDisposable.Dispose() { if (parse32 != null) { Marshal.ReleaseComObject(parse32); parse32 = null; } if (parse64 != null) { Marshal.ReleaseComObject(parse64); parse64 = null; } if (engine != null) { Marshal.ReleaseComObject(engine); engine = null; } }
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; }
internal ActiveScriptParseWrapper(object comObject) { if (IntPtr.Size == 4) { asp32 = (IActiveScriptParse32) comObject; } else { asp64 = (IActiveScriptParse64) comObject; } }
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); } } } }
/// <summary> /// Initializes a new instance of the <see cref="ActiveScriptParseWrapper"/> class. /// </summary> /// <param name="parser">The parser. Must implement IActiveScriptParse32 or IActiveScriptParse64.</param> public ActiveScriptParseWrapper(object parser) { _parse32 = parser as IActiveScriptParse32; _parse64 = parser as IActiveScriptParse64; }
/// <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; if (_is64Bit) { _activeScriptParse64 = null; ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse64); } else { _activeScriptParse32 = null; ComHelpers.ReleaseAndEmpty(ref _pActiveScriptParse32); } } }