/// <summary> /// Initializes a new instance of the <see cref="ActiveScriptEngine"/> class. /// </summary> /// <param name="scriptEngine"> The script engine. </param> /// <param name="language"> The scripting language. </param> private ActiveScriptEngine(object scriptEngine, ScriptLanguage language) { if (scriptEngine == null) throw new ArgumentNullException("scriptEngine"); this.language = language; this.engine = (IActiveScript)scriptEngine; this.engine.SetScriptSite(this); this.parser = (IActiveScriptParse)this.engine; this.parser.InitNew(); // Set properties. var activeScriptProperty = (IActiveScriptProperty)scriptEngine; // Indicate that we are not combining multiple script engines. object value = true; activeScriptProperty.SetProperty(SCRIPTPROP.ABBREVIATE_GLOBALNAME_RESOLUTION, IntPtr.Zero, ref value); // Upgrade the version of the script engine to 5.8 (IE 8). value = SCRIPTLANGUAGEVERSION.V5_8; 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() { 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(); } }
protected ActiveScriptJavascriptRuntimeBase(IActiveScript scriptEngine) { ScriptEngine = scriptEngine; ScriptEngine.SetScriptSite(this); JsParse = new ActiveScriptParseWrapper(ScriptEngine); 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; } }
/// <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(); } }
public void Dispose() { if (this.engine != null) { this.engine = null; } }
public static object CreateScriptObject(ScriptSiteBase scriptSite, string scriptText) { IActiveScript engine = (IActiveScript)engineCache[scriptSite]; IActiveScriptParse parser = (IActiveScriptParse)engine; if (engine == null) { engine = (IActiveScript) new JScriptEngine(); engine.SetScriptSite(scriptSite); foreach (string name in scriptSite.GetNamedItems()) { engine.AddNamedItem(name, ScriptItem.IsVisible); } parser = (IActiveScriptParse)engine; parser.InitNew(); engineCache.Add(scriptSite, engine); } EXCEPINFO ei; object result; IScript scriptObject; parser.ParseScriptText(scriptText, null, null, null, IntPtr.Zero, 1, ScriptText.None, out result, out ei); engine.GetScriptDispatch(null, out scriptObject); return(scriptObject); }
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 }
/// <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> /// Constructs instance of ActiveScriptSiteWrapper /// </summary> /// <param name="documentVersion">The host-defined document version string</param> public ActiveScriptSite(string documentVersion) { DocumentVersion = documentVersion; try { // Prefer Chakra _jsEngine = new ChakraJsEngine() as IActiveScript; } catch { _jsEngine = null; } if (_jsEngine == null) { // No need to catch here - engine of last resort _jsEngine = new JsEngine() as IActiveScript; } if (_jsEngine != null) { _jsEngine.SetScriptSite(this); _jsParser = new ActiveScriptParserWrapper(_jsEngine); _jsParser.InitNew(); } if (_jsEngine == null) { throw new JsEngineLoadException(Strings.Runtime_JsEngineNotLoaded); } }
public Engine(int pid, string version) { this.engine = this.CreateEngine(); this.scriptSite = new Site(); this.parser = new Parser(this.engine); this.engine.SetScriptSite(this.scriptSite); InformEngineOfNewObjects(pid, version); }
private void CreateScriptEngine() { if (this.FEngine != null) { return; } this.FEngine = (IActiveScript)Activator.CreateInstance(Type.GetTypeFromProgID(this.Language)); this.FParser = new ActiveScriptParseWrapper((object)this.FEngine); this.FEngine.SetScriptSite((IActiveScriptSite)this); this.FParser.InitNew(); }
/// <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); }
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; }
private void ScriptFunc() { _scriptEngineObject = new VBScriptEngine(); _scriptEngine = (IActiveScript)_scriptEngineObject; _scriptParser = new ActiveScriptParseWrapper(_scriptEngine); _scriptParser.InitNew(); _scriptEngine.SetScriptSite(this); _scriptEngine.SetScriptState(ScriptState.Started); _scriptEngine.SetScriptState(ScriptState.Connected); while (true) { if (_running == 0) { break; } string code = ""; lock (_runnables) { _runnables.ForEach(snippet => code += snippet + "\n"); _runnables.Clear(); } if (code.Trim().Length > 0) { try { /*_scriptEngine.GetScriptThreadState(SCRIPTTHREADID_BASE, out ScriptThreadState state); * Console.WriteLine(string.Format("Scipt thread state for thread '{0}' is {1}", _processThread.Name, state)); * _scriptEngine.GetScriptState(out ScriptState sciptState); * Console.WriteLine(string.Format("Scipt state for thread '{0}' is {1}", _processThread.Name, sciptState));*/ _scriptParser.ParseScriptText(code, null, null, null, IntPtr.Zero, 0, ScriptText.IsVisible, out object result, out EXCEPINFO ei); } catch (Exception e) { Console.WriteLine(string.Format("Exception while parsing following code for thread '{0}'\nException: {1}\nCode:\n{2}", _processThread.Name, e, code)); } } else if (_running == 2) { break; } Thread.Sleep(100); } _scriptEngine.Close(); Marshal.ReleaseComObject(_scriptEngine); Marshal.ReleaseComObject(_scriptEngineObject); _scriptParser.ReleaseComObject(); _scriptEngine = null; _scriptParser = null; }
/// <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; }
private static object JSonToObject(string json) { JScriptEngine engine = new JScriptEngine(); IActiveScript script = (IActiveScript)engine; MySite site = new MySite(); engine.SetScriptSite(site); IActiveScriptParse32 scriptParser = (IActiveScriptParse32)engine; scriptParser.InitNew(); engine.SetScriptState(ScriptState.SCRIPTSTATE_CONNECTED); // SCRIPTTEXT_ISEXPRESSION // If the distinction between a computational expression and a // statement is important but syntactically ambiguous in the // script language, this flag specifies that the scriptlet is // to be interpreted as an expression, rather than as a // statement or list of statements. By default, statements are // assumed unless the correct choice can be determined from // the syntax of the scriptlet text. const int SCRIPTTEXT_ISEXPRESSION = 0x00000020; // Tricky: http://msdn2.microsoft.com/en-us/library/system.runtime.interopservices.variantwrapper.aspx. object result = null; System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; Trace.WriteLine("Parsing JSON:"); if (json.Length < 256) { Trace.WriteLine(json); } else { Trace.WriteLine(json.Substring(0, 128) + "..." + json.Substring(json.Length - 128, 128)); } scriptParser.ParseScriptText(json, null, null, null, 0, 0, SCRIPTTEXT_ISEXPRESSION, ref result, out exceptionInfo); if (exceptionInfo.scode != 0) { throw new Exception(exceptionInfo.bstrDescription); } //engine.Close(); return(result); }
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 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; }
/// <summary> /// Determines if a script engine with the input name exists. /// </summary> /// <param name="language">The language.</param> /// <returns>true if the engine exists; false otherwise.</returns> public static Version GetVersion(string language) { if (language == null) { throw new ArgumentNullException("language"); } Type engine; Guid clsid; if (Guid.TryParse(language, out clsid)) { engine = Type.GetTypeFromCLSID(clsid, false); } else { engine = Type.GetTypeFromProgID(language, false); } if (engine == null) { return(null); } IActiveScript scriptEngine = Activator.CreateInstance(engine) as IActiveScript; if (scriptEngine == null) { return(null); } IActiveScriptProperty scriptProperty = scriptEngine as IActiveScriptProperty; if (scriptProperty == null) { return(new Version(1, 0, 0, 0)); } int major = GetProperty(scriptProperty, SCRIPTPROP_MAJORVERSION, 0); int minor = GetProperty(scriptProperty, SCRIPTPROP_MINORVERSION, 0); int revision = GetProperty(scriptProperty, SCRIPTPROP_BUILDNUMBER, 0); Version version = new Version(major, minor, Environment.OSVersion.Version.Build, revision); Marshal.ReleaseComObject(scriptProperty); Marshal.ReleaseComObject(scriptEngine); return(version); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting /// unmanaged resources. /// </summary> public void Dispose() { if (this.engine != null) { this.engine.Close(); } if (this.parser != null) { Marshal.ReleaseComObject(this.parser); } this.parser = null; if (this.engine != null) { Marshal.ReleaseComObject(this.engine); } this.engine = null; }
/// <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)); } } } }
void _Dispose(bool disposing) { if (null != _inner) { var host = Host; if (null != host) { if (!host.RemoveEngine(this)) { _inner.Close(); } } else { _inner.Close(); } _inner = null; } }
/// <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(); }
/// <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); } }
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> /// Initialises this script engine instance with the required internal components. /// </summary> /// <param name="activeScriptObject">The IActiveScript instance to initialise this script engine with.</param> private void Initialise(object activeScriptObject) { IActiveScript activeScriptInstance = activeScriptObject as IActiveScript; if (activeScriptInstance == null) { throw new InvalidActiveScriptClassException(); } this.parser = ActiveScriptParse.MakeActiveScriptParse(activeScriptInstance); this.parser.InitNew(); this.scriptSite = new ActiveScriptSite(this); activeScriptInstance.SetScriptSite(this.scriptSite); this.hostObjects = new Dictionary <string, object>(); this.scripts = new Dictionary <ulong, ScriptInfo>(); this.activeScript = activeScriptInstance; }
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; }
/// <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> public ActiveScriptSiteWrapper(IntPtr pActiveScript, IActiveScript activeScript) : this(pActiveScript, activeScript, DateTime.UtcNow.ToString("o")) { }
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); } } } }
public Parser(IActiveScript engine) { this.isParse32 = this.Is32BitEnvironment(); this.InitializeParsers(engine); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting /// unmanaged resources. /// </summary> public void Dispose() { if (this.engine != null) this.engine.Close(); if (this.parser != null) Marshal.ReleaseComObject(this.parser); this.parser = null; if (this.engine != null) Marshal.ReleaseComObject(this.engine); this.engine = null; }
public void Clone(out IActiveScript script) { Debug.WriteLine ("Clone()"); script = this; }