当前位置: 首页>>代码示例>>C#>>正文


C# JintEngine.Run方法代码示例

本文整理汇总了C#中JintEngine.Run方法的典型用法代码示例。如果您正苦于以下问题:C# JintEngine.Run方法的具体用法?C# JintEngine.Run怎么用?C# JintEngine.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JintEngine的用法示例。


在下文中一共展示了JintEngine.Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {

            var assembly = Assembly.Load("Jint.Tests");
            Stopwatch sw = new Stopwatch();

            // string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-debug.js")).ReadToEnd();
            JintEngine jint = new JintEngine()
                // .SetDebugMode(true)
                .DisableSecurity()
                .SetFunction("print", new Action<string>(Console.WriteLine))
                .SetFunction("write", new Action<string>(t => Console.WriteLine(t)))
                .SetFunction("stop", new Action(delegate() { Console.WriteLine(); }));
            sw.Reset();
            sw.Start();

            try
            {
                Console.WriteLine(jint.Run("2+3"));
                Console.WriteLine("after0");
                Console.WriteLine(jint.Run(")(---"));
                Console.WriteLine("after1");
                Console.WriteLine(jint.Run("FOOBAR"));
                Console.WriteLine("after2");

            }
            catch (JintException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
        }
开发者ID:arelee,项目名称:ravendb,代码行数:33,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            var assembly = Assembly.Load("Jint.Tests");
            Stopwatch sw = new Stopwatch();

            string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-format.js")).ReadToEnd();
            JintEngine jint = new JintEngine()
                // .SetDebugMode(true)
                .DisableSecurity()
                .SetFunction("print", new Action<string>(Console.WriteLine))
                .SetFunction("stop", new Action( delegate() { Console.WriteLine(); }));
            sw.Reset();
            sw.Start();

            jint.Run(script);
            try
            {
                var result = jint.Run("CoffeeScript.compile('number = 42', {bare: true})");
            }
            catch (JintException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
        }
开发者ID:cosh,项目名称:Jint,代码行数:26,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {

            Stopwatch sw = new Stopwatch();

            // string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-debug.js")).ReadToEnd();
            JintEngine jint = new JintEngine()
                // .SetDebugMode(true)
                .DisableSecurity()
                .SetFunction("print", new Action<string>(Console.WriteLine))
                .SetFunction("write", new Action<string>(t => Console.WriteLine(t)))
                .SetFunction("stop", new Action(delegate() { Console.WriteLine(); }));
            sw.Reset();
	        jint.SetMaxRecursions(50);
	        jint.SetMaxSteps(10*1000);

			sw.Start();
			try
			{
				Console.WriteLine(
					jint.Run(File.ReadAllText(@"C:\Work\ravendb-1.2\SharedLibs\Sources\jint-22024d8a6e7a\Jint.Play\test.js")));
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}
	        finally 
	        {
				Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
			}

        }
开发者ID:karlgrz,项目名称:ravendb,代码行数:32,代码来源:Program.cs

示例4: ExecuteSunSpiderScript

        private static void ExecuteSunSpiderScript(string scriptName)
        {
            const string prefix = "Jint.Tests.SunSpider.";
            var script = prefix + scriptName;

            var assembly = Assembly.GetExecutingAssembly();
            var program = new StreamReader(assembly.GetManifestResourceStream(script)).ReadToEnd();

            var jint = new JintEngine(Options.Ecmascript5); // The SunSpider scripts doesn't work with strict mode
            var sw = new Stopwatch();
            sw.Start();

            jint.Run(program);

            Console.WriteLine(sw.Elapsed);
        }
开发者ID:925coder,项目名称:ravendb,代码行数:16,代码来源:SunSpider.cs

示例5: Main

        static void Main(string[] args)
        {

            Stopwatch sw = new Stopwatch();

            // string script = new StreamReader(assembly.GetManifestResourceStream("Jint.Tests.Parse.coffeescript-debug.js")).ReadToEnd();
            JintEngine jint = new JintEngine()
                // .SetDebugMode(true)
                .DisableSecurity()
                .SetFunction("print", new Action<string>(Console.WriteLine))
                .SetFunction("write", new Action<string>(t => Console.WriteLine(t)))
                .SetFunction("stop", new Action(delegate() { Console.WriteLine(); }));
            sw.Reset();
            sw.Start();

            Console.WriteLine(jint.Run("Math.floor(1.5)"));
           

            Console.WriteLine("{0}ms", sw.ElapsedMilliseconds);
        }
开发者ID:remcoros,项目名称:ravendb,代码行数:20,代码来源:Program.cs

示例6: Test

        protected object Test(Options options, string script, Action<JintEngine> action)
        {
            var jint = new JintEngine(options)
                .AllowClr()
                .SetFunction("assert", new Action<object, object>(Assert.AreEqual))
                .SetFunction("fail", new Action<string>(Assert.Fail))
                .SetFunction("istrue", new Action<bool>(Assert.IsTrue))
                .SetFunction("isfalse", new Action<bool>(Assert.IsFalse))
                .SetFunction("print", new Action<string>(Console.WriteLine))
                .SetFunction("alert", new Action<string>(Console.WriteLine))
                .SetFunction("loadAssembly", new Action<string>(assemblyName => Assembly.Load(assemblyName)))
                .DisableSecurity();

            action(jint);

            var sw = new Stopwatch();
            sw.Start();

            var result = jint.Run(script);

            Console.WriteLine(sw.Elapsed);

            return result;
        }
开发者ID:arelee,项目名称:ravendb,代码行数:24,代码来源:Fixtures.cs

示例7: ShouldHandleClrArrays

        public void ShouldHandleClrArrays() {
            var values = new int[] { 2, 3, 4, 5, 6, 7 };
            var jint = new JintEngine()
            .SetDebugMode(true)
            .SetParameter("a", values)
            .AllowClr();

            Assert.AreEqual(3, jint.Run("a[1];"));
            jint.Run("a[1] = 4");
            Assert.AreEqual(4, jint.Run("a[1];"));
            Assert.AreEqual(4, values[1]);

        }
开发者ID:arelee,项目名称:ravendb,代码行数:13,代码来源:Fixtures.cs

示例8: ShouldNotAccessClr

 public void ShouldNotAccessClr() {
     const string script = @"
         var sb = new System.Text.StringBuilder();
         sb.Append('hi, mom');
         sb.Append(3);	
         sb.Append(true);
         return sb.ToString();
         ";
     var engine = new JintEngine();
     Assert.AreEqual("hi, mom3True", engine.Run(script));
 }
开发者ID:arelee,项目名称:ravendb,代码行数:11,代码来源:Fixtures.cs

示例9: SecurityExceptionsShouldNotBeCaught

 public void SecurityExceptionsShouldNotBeCaught() {
     const string script = @"
         try {
             var sb = new System.Text.StringBuilder();
             fail('should not have reached this code');
         } 
         catch (e) {
             fail('should not have reached this code');
         }                
     ";
     var engine = new JintEngine();
     engine.Run(script);
 }
开发者ID:arelee,项目名称:ravendb,代码行数:13,代码来源:Fixtures.cs

示例10: ShouldThrowErrorWhenAssigningUndeclaredVariableInStrictMode

        public void ShouldThrowErrorWhenAssigningUndeclaredVariableInStrictMode() {
            var engine = new JintEngine(Options.Ecmascript5 | Options.Strict)
                .SetFunction("assert", new Action<object, object>(Assert.AreEqual));
            var x = engine.Run(@"
                try {
                    x = 1;
                    return x;
                } catch(e) {
                    return 'error';
                }
            ");

            Assert.AreEqual("error", x);
        }
开发者ID:arelee,项目名称:ravendb,代码行数:14,代码来源:Fixtures.cs

示例11: ShouldReturnDelegateForFunctions

 public void ShouldReturnDelegateForFunctions() {
     const string script = "var ccat=function (arg1,arg2){ return arg1+' '+arg2; }";
     JintEngine engine = new JintEngine().SetFunction("print", new Action<string>(Console.WriteLine));
     engine.Run(script);
     Assert.AreEqual("Nicolas Penin", engine.CallFunction("ccat", "Nicolas", "Penin"));
 }
开发者ID:arelee,项目名称:ravendb,代码行数:6,代码来源:Fixtures.cs

示例12: ShouldHandleArrayIndexOf

        public void ShouldHandleArrayIndexOf()
        {

            var jint = new JintEngine()
            .SetDebugMode(true)
            .SetFunction("assert", new Action<object, object>(Assert.AreEqual))
            .SetFunction("print", new Action<string>(System.Console.WriteLine));

            jint.Run(@"
                var days = ['mon', 'tue', 'wed'];
                assert(1, days.indexOf('tue'));            
            ");
        }
开发者ID:925coder,项目名称:ravendb,代码行数:13,代码来源:Fixtures.cs

示例13: ObjectShouldBePassedToDelegates

        public void ObjectShouldBePassedToDelegates() {
            var engine = new JintEngine();
            engine.SetFunction("render", new Action<object>(s => Console.WriteLine(s)));

            const string script =
                @"
                var contact = {
                    'Name': 'John Doe',
                    'PhoneNumbers': [ 
                    {
                       'Location': 'Home',
                       'Number': '555-555-1234'
                    },
                    {
                        'Location': 'Work',
                        'Number': '555-555-9999 Ext. 123'
                    }
                    ]
                };

                render(contact.Name);
                render(contact.toString());
                render(contact);
            ";

            engine.Run(script);
        }
开发者ID:arelee,项目名称:ravendb,代码行数:27,代码来源:Fixtures.cs

示例14: ShouldRunInRun

        public void ShouldRunInRun() {
            var filename = Path.GetTempFileName();
            File.WriteAllText(filename, "a='bar'");

            var engine = new JintEngine().AddPermission(new FileIOPermission(PermissionState.Unrestricted));
            engine.AllowClr();
            engine.SetFunction("load", new Action<string>(delegate(string fileName) { using (var reader = File.OpenText(fileName)) { engine.Run(reader); } }));
            engine.SetFunction("print", new Action<string>(Console.WriteLine));
            engine.Run("var a='foo'; load('" + JintEngine.EscapteStringLiteral(filename) + "'); print(a);");

            File.Delete(filename);
        }
开发者ID:arelee,项目名称:ravendb,代码行数:12,代码来源:Fixtures.cs

示例15: ClrNullShouldBeConverted

        public void ClrNullShouldBeConverted() {

            var jint = new JintEngine()
            .SetDebugMode(true)
            .SetFunction("assert", new Action<object, object>(Assert.AreEqual))
            .SetFunction("print", new Action<string>(System.Console.WriteLine))
            .SetParameter("foo", null);

            // strict equlity ecma 262.3 11.9.6 x === y: If type of (x) is null return true.
            jint.Run(@"
                assert(true, foo == null);
                assert(true, foo === null);
            ");
        }
开发者ID:arelee,项目名称:ravendb,代码行数:14,代码来源:Fixtures.cs


注:本文中的JintEngine.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。