internal void InitializeParsers(IActiveScript engine) { if (this.isParse32) { this.parse32 = (IActiveScriptParse32)engine; this.parse32.InitNew(); } else { this.parse64 = (IActiveScriptParse64)engine; this.parse64.InitNew(); } }
/// <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> /// 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> /// 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(); } }
/// <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(); } }
public ActiveScriptWrapper32(string progID, WindowsScriptEngineFlags flags) { // ReSharper disable SuspiciousTypeConversion.Global pActiveScript = RawCOMHelpers.CreateInstance <IActiveScript>(progID); pActiveScriptParse = RawCOMHelpers.QueryInterface <IActiveScriptParse32>(pActiveScript); pActiveScriptDebug = RawCOMHelpers.QueryInterface <IActiveScriptDebug32>(pActiveScript); pActiveScriptGarbageCollector = RawCOMHelpers.QueryInterfaceNoThrow <IActiveScriptGarbageCollector>(pActiveScript); pDebugStackFrameSniffer = RawCOMHelpers.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)) { 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 }
/// <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(); } }
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; } }
public ActiveScriptWrapper32(string progID, WindowsScriptEngineFlags flags) { 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; 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="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 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); }
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; }
/// <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> /// 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(); } }
internal ActiveScriptParseWrapper(object comObject) { if (IntPtr.Size == 4) { asp32 = (IActiveScriptParse32) comObject; } else { asp64 = (IActiveScriptParse64) comObject; } }
/// <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); } } }