Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            // string lodash = File.ReadAllText(@"c:\lodash.js");
            using (JsEngine engine = new JsEngine())
            {
                //Stopwatch watch = new Stopwatch();
                //	watch.Start();
                JsScript script = engine.CompileScript("3+3", "<unnamed>");
                using (JsContext ctx = engine.CreateContext())
                {
                    ctx.Execute(script);
                }
            }

            debugtest dbg = new debugtest();

            //	Delegate.CreateDelegate()
            //Dictionary<string, object> values = new Dictionary<string, object>();

            //values["test"] = 333;
            while (true)
            {
                using (JsEngine js = new JsEngine(4, 32))
                {
                    using (JsContext context = js.CreateContext())
                    {
                        //context.SetVariable("dbg", dbg);
                        //object result = context.Execute("dbg.Write(dbg.valueOf());");
                        context.SetVariableFromAny("Debug", typeof(debugtest));

                        object result = context.Execute("Debug.BoolTest(3,4);");
                    }
                    GC.Collect();
                    js.DumpHeapStats();
                }
            }


            //context.SetVariable("values", values);
            //object result = context.Execute("dbg.runFunc(); values.test ? true : false;");



            //	object result =
            //	context.Execute("var obj = { test: 0 }; obj.ft = function (v) { dbg.Write(v); return 'from JS'; }; dbg.runFunc(obj.ft); dbg.write(obj.test);");

            //int a = 1;

            //	context.SetFunction("runfunc", new Func<int, bool>(Activate));
            //object result = context.Execute("runfunc(2);");
            //  }

            //		}
            //}

            /*using (JsEngine js = new JsEngine()) {
             *  using (JsContext context = js.CreateContext()) {
             *      using (JsScript script = js.CompileScript("3 * 4")) {
             *          object result = context.Execute(script, TimeSpan.FromHours(200));
             *          Console.WriteLine(result);
             *      }
             *  }
             * }*/

            //return;

            /*
             * using (JsEngine js = new JsEngine()) {
             *  using (JsContext context = js.CreateContext()) {
             *      for (int i = 0; i < 10; i++) {
             *          context.SetVariable("a", new Simple { N = i, S = (i * 10).ToString() });
             *          Console.WriteLine(context.Execute("a.N+' '+a.S"));
             *      }
             *      Console.WriteLine(context.Execute("a.N+' '+a.X"));
             *  }
             * }*/
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            // string lodash = File.ReadAllText(@"c:\lodash.js");
            using (JsEngine engine = new JsEngine())
            {
                //Stopwatch watch = new Stopwatch();
                //	watch.Start();
                JsScript script = engine.CompileScript("3+3");
                using (JsContext ctx = engine.CreateContext())
                {
                    ctx.Execute(script);
                }
            }

            debugtest dbg = new debugtest();

            //	Delegate.CreateDelegate()
            //Dictionary<string, object> values = new Dictionary<string, object>();

            //values["test"] = 333;
            while (true)
            {
                using (JsEngine js = new JsEngine(4, 32))
                {
                    using (JsContext context = js.CreateContext())
                    {
                        //context.SetVariable("dbg", dbg);
                        //object result = context.Execute("dbg.Write(dbg.valueOf());");
                        context.SetVariableFromAny("Debug", typeof(debugtest));

                        object result = context.Execute("Debug.BoolTest(3,4);");

                    }
                    GC.Collect();
                    js.DumpHeapStats();
                }
            }

            //context.SetVariable("values", values);
            //object result = context.Execute("dbg.runFunc(); values.test ? true : false;");

            //	object result =
            //	context.Execute("var obj = { test: 0 }; obj.ft = function (v) { dbg.Write(v); return 'from JS'; }; dbg.runFunc(obj.ft); dbg.write(obj.test);");

            //int a = 1;

            //	context.SetFunction("runfunc", new Func<int, bool>(Activate));
            //object result = context.Execute("runfunc(2);");
            //  }

            //		}
            //}
            /*using (JsEngine js = new JsEngine()) {
                using (JsContext context = js.CreateContext()) {
                    using (JsScript script = js.CompileScript("3 * 4")) {
                        object result = context.Execute(script, TimeSpan.FromHours(200));
                        Console.WriteLine(result);
                    }
                }
            }*/

            //return;
            /*
            using (JsEngine js = new JsEngine()) {
                using (JsContext context = js.CreateContext()) {
                    for (int i = 0; i < 10; i++) {
                        context.SetVariable("a", new Simple { N = i, S = (i * 10).ToString() });
                        Console.WriteLine(context.Execute("a.N+' '+a.S"));
                    }
                    Console.WriteLine(context.Execute("a.N+' '+a.X"));
                }
            }*/
        }