static void Main(string[] args) { dynamic jsContext = new DynamicJavascriptContext(new Jurassic.ScriptEngine()); jsContext.message = "Hello World !"; jsContext.number = 1; jsContext.array = jsContext.Array(1, 2 , 3); jsContext.instance = jsContext.Object( new { b = 2 } ); jsContext.instance2 = jsContext.Object( new { a = 1, b = 2 } ); string script = @" number = 123; instance['a'] = 1; instance['Date'] = new Date(); instance2['a'] = 123; console.log('Hello log, Date:'+instance['Date']); console.log('array.length:'+array.length); array.push(4); for(var i=0; i<array.length; i++) console.log(array[i]); "; jsContext.Run(script); Console.WriteLine("number: " + jsContext.number ); Console.WriteLine("instance: " + jsContext.instance ); Console.WriteLine("instance.a: " + jsContext.instance.a ); Console.WriteLine("instance.b: " + jsContext.instance.b ); Console.WriteLine("instance.Date: " + jsContext.instance.Date); Console.WriteLine("instance2.a: " + jsContext.instance2.a ); Console.WriteLine("array:" + jsContext.array.Length ); Console.WriteLine("array[3]:" + jsContext.array[3] ); FunctionCall(); Console.ReadLine(); }
public void NestedObjects_NestedInputObject_Output() { dynamic jsContext = new DynamicJavascriptContext(new Noesis.Javascript.JavascriptContext()); jsContext.i = jsContext.Object( new { a = jsContext.Object( new { LastName="Torres", Age=46 } ), b = jsContext.Object( new Person("Ferry", 47) ), } ); string script = @" var p1 = { Name : i.a.LastName, Age : i.a.Age } var p2 = { Name : i.b.LastName, Age : i.b.Age } "; jsContext.Run(script); Assert.AreEqual("Torres", jsContext.p1.Name); Assert.AreEqual("Torres", jsContext.p1["Name"]); Assert.AreEqual("Torres", jsContext["p1"]["Name"]); Assert.AreEqual(46 , jsContext.p1.Age); Assert.AreEqual(46 , jsContext.p1["Age"]); Assert.AreEqual(46 , jsContext["p1"]["Age"]); Assert.AreEqual("Ferry" , jsContext.p2.Name); Assert.AreEqual("Ferry" , jsContext.p2["Name"]); Assert.AreEqual("Ferry" , jsContext["p2"]["Name"]); Assert.AreEqual(47 , jsContext.p2.Age); Assert.AreEqual(47 , jsContext.p2["Age"]); Assert.AreEqual(47 , jsContext["p2"]["Age"]); }