public void DiffKeysWithArrays() { using (var engine = new JavascriptEngine()) { engine.Execute("var a = {};"); var startObj = engine.ExecuteAndReturn("a"); engine.Execute("var a = {};"); engine.Execute("a.users = []"); var endObj = engine.ExecuteAndReturn("a"); // Added var diff = new ObjectDiff(); diff.Diff(startObj, endObj, "a"); Assert.AreEqual(1, diff.Added.Count); Assert.AreEqual("a.users", diff.Added.Keys.First(), "It actually equals " + diff.Added.Keys.First()); var val = JsonConvert.SerializeObject(diff.Added.First().Value); Assert.AreEqual("[]", val); } using (var engine = new JavascriptEngine()) { engine.Execute("var a = {};"); engine.Execute("a.users = []"); var startObj = engine.ExecuteAndReturn("a"); engine.Execute("var a = {};"); engine.Execute("a.users = []"); engine.Execute("a.users[1] = 12"); var endObj = engine.ExecuteAndReturn("a"); // Added var diff = new ObjectDiff(); diff.Diff(startObj, endObj, "a"); Assert.AreEqual(2, diff.Added.Count); Assert.True(diff.Added.ContainsKey("a.users[0]")); Assert.True(diff.Added.ContainsKey("a.users[1]")); // Deleted diff = new ObjectDiff(); diff.Diff(endObj, startObj, "a"); Assert.AreEqual(2, diff.Deleted.Count); Assert.True(diff.Deleted.Contains("a.users[0]")); Assert.True(diff.Deleted.Contains("a.users[1]")); // Modified engine.Execute("var a = {};"); engine.Execute("a.users = []"); engine.Execute("a.users[1] = 14"); var changedObj = engine.ExecuteAndReturn("a"); diff = new ObjectDiff(); diff.Diff(endObj, changedObj, "a"); Assert.AreEqual(1, diff.Modified.Count); Assert.AreEqual("a.users[1]", diff.Modified.Keys.First(), "It actually equals " + diff.Modified.Keys.First()); } }
private void InitializeJS() { this.AssertRunningOnThisThread(); Javascript = new JavascriptEngine(); Javascript.Script.console = new { log = new Action <object>(ScriptLog) }; O = new OClass(this); #pragma warning disable CC0021 // Use nameof Javascript.AddObject("O", O); #pragma warning restore CC0021 // Use nameof O.Init(); if (Resources != null) { Javascript.Execute(Resources.ReadEntryPoint()); } ((ManualResetEvent)EngineInitialized).Set(); }
public virtual object Evaluate(string script) { script = StringHelper.ExtractExpression(script); return(engine.Execute(script, scope)); }
public Task Execute(string script) { return(_javascriptEngine.Execute(script)); }