static void ProcessScript(String sFunc, String sHdrFile, String sDtlFile) { String sFileResult = Path.GetFileNameWithoutExtension(sDtlFile) + "-result.js"; String sHdrScript = File.ReadAllText(sHdrFile); String sRScript = File.ReadAllText(sDtlFile); V8ScriptEngine v8 = new V8ScriptEngine(); V8Script myScript = v8.Compile(sHdrScript); v8.Execute(myScript); String sRegex = "(" + sFunc + @"\(\'0[xX][0-9A-Fa-f]+\'\))"; MatchCollection arMatches = Regex.Matches(sRScript, sRegex); int nI; String sMatchVal, sRes; for (nI = 0; nI < arMatches.Count; nI++) { sMatchVal = arMatches[nI].Value; Console.WriteLine("Processing " + sMatchVal + " ..."); sRes = v8.ExecuteCommand(sMatchVal); sRScript = sRScript.Replace(arMatches[nI].Value, "\"" + sRes + "\""); } v8.Dispose(); File.WriteAllText(sFileResult, sRScript); return; }
public void Dispose() { RaiseEventAsync("dispose").ContinueWith((task) => { engine.Dispose(); }); }
public void Dispose() { if (engin != null) { engin.Dispose(); } }
public void Evaluating4000Records_ExpectedTime_200ms() { // Arrange var engine = new V8ScriptEngine(); var exprected_time = TimeSpan.FromMilliseconds(200); var exprected_count = 4000; var actual_time = new TimeSpan(); var actual_results = new Stack <int>(4000); // Act try { actual_time = Estimator.Estimate(() => { for (int i = 0; i < 4000; i++) { actual_results.Push((int)engine.Evaluate("1+1")); } }); } finally { engine.Dispose(); } // Expect Assert.AreEqual(exprected_count, actual_results.Count); Assert.That(actual_time, Is.LessThanOrEqualTo(exprected_time)); }
public void Cleanup() { if (_scriptEngine != null) { _scriptEngine.Dispose(); _scriptEngine = null; } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { channels.Clear(); _engine.Dispose(); _engine = null; disposedValue = true; } }
public override void Dispose() { if (_disposedFlag.Set()) { if (_jsEngine != null) { _jsEngine.Dispose(); _jsEngine = null; } } }
public void Dispose() { if (executeScript != null) { executeScript.Dispose(); } if (scriptEngine != null) { scriptEngine.Dispose(); } }
public override void Dispose() { if (!_disposed) { _disposed = true; if (_jsEngine != null) { _jsEngine.Dispose(); _jsEngine = null; } } }
public void Dispose() { if (m_tcpClient != null) { m_tcpClient.Close(); } if (m_scriptEngine != null) { m_scriptEngine.Interrupt(); //m_scriptEngine.CollectGarbage(true); m_scriptEngine.Dispose(); m_scriptEngine = null; } }
static void Main(string[] args) { string s = string.Empty; try { string url = "https://zingnews.vn"; if (args.Length > 0) { url = args[0]; } //V8ScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging); V8ScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.DisableGlobalMembers); //engine.Execute(Script_Text); engine.AddCOMType("XMLHttpRequest", "MSXML2.XMLHTTP"); //object returnedVal = _v8Engine.Script.Execute(); //return returnedVal; //engine.AddCOMType("XMLHttpRequest", "MSXML2.XMLHTTP"); engine.Execute(@" function get(url) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, false); xhr.send(); if (xhr.status == 200) return xhr.responseText; return ''; } "); s = engine.Script.get(url); engine.Dispose(); } catch (Exception e) { s = "ERROR: " + e.Message; } Console.OutputEncoding = System.Text.Encoding.UTF8; Console.WriteLine(s); //Force garbage collection. GC.Collect(); // Wait for all finalizers to complete before continuing. GC.WaitForPendingFinalizers(); }
public void Evaluated_ExpectedResult_2() { // Arrange var engine = new V8ScriptEngine(); int actual = 0; int expected = 2; // Act try { actual = (int)engine.Evaluate("1+1"); } finally { engine.Dispose(); } // Expect Assert.AreEqual(expected, actual); }
static void Testing() { Console.WriteLine("Testing Here"); V8ScriptEngine v8 = new V8ScriptEngine(); String sScript = File.ReadAllText("header.js"); String sRScript = File.ReadAllText("detail.js"); String sFunc = "_0xfec0"; //Console.WriteLine(sScript); V8Script myScript = v8.Compile(sScript); v8.Execute(myScript); //find certain pattern in the String sTest = v8.ExecuteCommand("_0xfec0('0x0')"); Console.WriteLine("OK " + sTest); sTest = v8.ExecuteCommand("_0xfec0('0x1')"); Console.WriteLine("OK " + sTest); sTest = v8.ExecuteCommand("_0xfec0('0x2')"); Console.WriteLine("OK " + sTest); v8.Dispose(); }
public void Dispose() { if (m_debuggerClient != null) { m_debuggerClient.ExceptionEvent -= debuggerClient_ExceptionEvent; m_debuggerClient.BreakpointEvent -= m_debuggerClient_BreakpointEvent; m_debuggerClient = null; } if (m_debuggerConnection != null) { m_debuggerConnection.Close(); m_debuggerConnection.Dispose(); m_debuggerConnection = null; } if (m_scriptEngine != null) { m_scriptEngine.Interrupt(); m_scriptEngine.Dispose(); m_scriptEngine = null; } }
public void Dispose() { _engine.Dispose(); }
public void Dispose() { _context.Dispose(); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); _engine?.Dispose(); }
public void V8ScriptEngine_General_Precompiled_Dual() { engine.Dispose(); using (var runtime = new V8Runtime()) { using (var script = runtime.Compile(generalScript)) { engine = runtime.CreateScriptEngine(); using (var console = new StringWriter()) { var clr = new HostTypeCollection(type => type != typeof(Console), "mscorlib", "System", "System.Core"); clr.GetNamespaceNode("System").SetPropertyNoCheck("Console", console); engine.AddHostObject("host", new ExtendedHostFunctions()); engine.AddHostObject("clr", clr); engine.Evaluate(script); Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n")); console.GetStringBuilder().Clear(); Assert.AreEqual(string.Empty, console.ToString()); engine.Evaluate(script); Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n")); } engine.Dispose(); engine = runtime.CreateScriptEngine(); using (var console = new StringWriter()) { var clr = new HostTypeCollection(type => type != typeof(Console), "mscorlib", "System", "System.Core"); clr.GetNamespaceNode("System").SetPropertyNoCheck("Console", console); engine.AddHostObject("host", new ExtendedHostFunctions()); engine.AddHostObject("clr", clr); engine.Evaluate(script); Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n")); console.GetStringBuilder().Clear(); Assert.AreEqual(string.Empty, console.ToString()); engine.Evaluate(script); Assert.AreEqual(MiscHelpers.FormatCode(generalScriptOutput), console.ToString().Replace("\r\n", "\n")); } } } }
public void Dispose() { runtime?.Dispose(); }
internal void Close() { engine.Dispose(); sw.Stop(); Console.WriteLine("Engine {4}#{0,-3} Thread {3,-3} disposed.", SerialNumber, 0, 0, Thread.CurrentThread.ManagedThreadId, PoolName); }
private async Task Navigate(Uri uri) { controlsGrid.IsEnabled = false; try { string url = uri.ToString(); urlBar.Text = url; if (engine != null) { engine.Interrupt(); engine.Dispose(); } engine = new V8ScriptEngine(); engine.AddHostObject("window", this); engine.AddHostType(typeof(MessageBox)); engine.AddHostType(typeof(Console)); foreach (var t in availableTypesLazy.Value) { engine.AddHostType(t); } ParserContext parserContext = new ParserContext(); parserContext.XmlnsDictionary["s"] = "clr-namespace:DynamicWPF.Scripting;assembly=DynamicWPF"; try { var resp = await client.GetAsync(uri); uri = resp.RequestMessage.RequestUri; url = uri.ToString(); urlBar.Text = url; parserContext.BaseUri = new Uri(url.Remove(url.LastIndexOf('/') + 1)); Page obj = null; if (resp.IsSuccessStatusCode) { try { obj = (Page)XamlReader.Load(await resp.Content.ReadAsStreamAsync(), parserContext); } catch { Process.Start(url); } } else { try { obj = (Page)XamlReader.Load(await resp.Content.ReadAsStreamAsync(), parserContext); } catch { resp.EnsureSuccessStatusCode(); } } if (obj != null) { contentFrame.Navigate(obj); foreach (var link in (obj.Content as DependencyObject).FindVisualChildren <Hyperlink>()) { link.RequestNavigate += async(o, ev) => { ev.Handled = true; var u = (o as Hyperlink).NavigateUri; await Navigate(u.IsAbsoluteUri?u : new Uri(parserContext.BaseUri, u)); }; } engine.AddHostObject("content", obj); foreach (var s in ScriptManager.GetScripts(obj)) { try { var str = await client.GetStringAsync(s.Source.IsAbsoluteUri?s.Source : new Uri(parserContext.BaseUri, s.Source)); engine.Execute(str); } catch { } } } } catch (Exception ex) { contentFrame.Navigate(new ErrorPage(ex)); } } finally { controlsGrid.IsEnabled = true; } }
public void TestCleanup() { engine.Dispose(); BaseTestCleanup(); }
public void Dispose() { engine?.Dispose(); }
public void Dispose() { v8ScriptEngine?.Dispose(); }
public void Restart() { // Find available port _engineDebugPort = -1; for (var p = DebugPortStart; p <= DebugPortEnd; p++) { if (Proxy.IsPortAvailable(p)) { _engineDebugPort = p; break; } } // Dispose old engine if (_engine != null) { _engine.Dispose(); } // Clear queues _callbacks = new ConcurrentQueue <Callback>(); _timeouts = new List <TimeOut>(); _requests = new ConcurrentQueue <Request>(); // Clear XDoc callback API.XDoc.ResetHooks(); if (_engineDebugPort != -1) { // Enable debugging on port "port" _engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging, _engineDebugPort); } else { // Create engine without debugging because no port is open // (this should never happen since there are a lot of ports in the range) _engine = new V8ScriptEngine(); } // Clear the list of required files _required.Clear(); // Define the NetJS API AddHostType(typeof(API.HTTP)); AddHostType(typeof(API.SQLAPI)); AddHostType(typeof(API.IO)); AddHostType(typeof(API.Log)); AddHostType(typeof(API.Application)); AddHostType(typeof(API.Session)); AddHostType(typeof(API.XDoc)); AddHostType(typeof(API.Base64)); AddHostType(typeof(API.Buffer)); AddHostType(typeof(API.Windows)); AddHostType(typeof(API.DLL)); AddHostType(typeof(API.XML)); AddHostType(typeof(API.MongoDBAPI)); AddHostFunctions(typeof(API.Functions)); // Initialize the tool functions Tool.Init(_engine); // Call the after start callback _afterStart(this); }
public void Dispose() { V8.Dispose(); }
public void AutoClose() { lScriptEngine.Dispose(); }