示例#1
0
        static void TestSunSpider()
        {
            var contents = File.ReadAllText(@"c:\projetos\breakaleg\sunspider\sunspider-test-contents.js");
            var prefix = File.ReadAllText(@"c:\projetos\breakaleg\sunspider\sunspider-test-prefix.js");
            var run = File.ReadAllText(@"c:\projetos\breakaleg\sunspider\sunspider-test-run.js");

            var c = new JSCompiler();

            var t = c.Parse(contents + prefix + run);
            var cx = new JSNames();
            t.Run(cx);

            var tc = cx.GetField("testContents");
            var ts = cx.GetField("tests");
            var ca = cx.GetField("categories");

            System.Console.Write(tc + " " + ts + " " + ca);
        }
示例#2
0
 dynamic Run(string code, string ret)
 {
     var p = new JSCompiler();
     var c = p.Parse(code);
     var ctx = new JSNames();
     ctx.Run(c);
     if (ret != null)
     {
         var a = ctx.GetField(ret);
         return a != null ? a.Scalar : null;
     }
     return null;
 }
示例#3
0
 public void TestMethod_SolveExternal()
 {
     var code = @"
         r=a+b*3;
         alert(r+1);
         x=Soma(4,5);
         ";
     dynamic foo = null;
     var ctx = new JSNames();
     ctx.SetMethod("alert", (s, a) => { foo = a[0].Scalar; return null; });
     ctx.SetField("a", new Instance(10));
     ctx.SetField("b", new Instance(30));
     ctx.SetMethod("Soma", (i, a) => a[0] + a[1]);
     var ret = JSCompiler.Run(code, "r", ctx);
     Assert.AreEqual(100, ret);
     Assert.AreEqual(101, foo);
     ret = JSCompiler.Run(code, "x", ctx);
     Assert.AreEqual(9, ret);
 }