Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            SMRuntime = new SMRuntime();

            SMRuntime.Embed(typeof(Script));
            SMRuntime.Embed(typeof(DateTime));
            SMRuntime.Embed(typeof(Environment));
            SMRuntime.Embed(typeof(JSHttpRequest));
            SMRuntime.Embed(typeof(TestDelegate));

            //Assembly.

            SMRuntime.OnScriptError += new ScriptErrorHandler(
                (scr, report) =>
                {
                    Console.WriteLine("{0} in {1} on line {2}", report.Message, scr.Name, report.LineNumber);
                }
            );

            SMScript script = SMRuntime.InitScript("eval", typeof(Program));

            script.SetOperationTimeout(30000);

            while (true)
            {
                Console.Write("js> ");

                string text = Console.ReadLine();
                if (text.ToLower() == "exit") break;

                //testing thread-safety
                DoEval(new object[] { script, text });
                //ThreadPool.QueueUserWorkItem(new WaitCallback(DoEval), new object[] { script, text });
            }

            script.Dispose();
            SMRuntime.Dispose();
        }
 public SpiderMonkeyJavascriptRuntime()
 {
     LockTimeout         = TimeSpan.FromSeconds(10);
     ScriptEngineContext = new SMRuntime();
     ScriptEngine        = ScriptEngineContext.InitScript(ScriptName);
 }