Пример #1
0
        private void button10_Click(object sender, EventArgs e)
        {
            //very basic ***
            //-----------------
            //test tsc.js
            //this needs EspressoHostForTsc
            //-----------------
            string        esprima_code = File.ReadAllText("d:\\projects\\Espresso\\js_tools\\tsc\\tsc_espr.js");
            StringBuilder stbuilder    = new StringBuilder();

            stbuilder.Append(esprima_code);
            //-----------------

            int version = JsBridge.LibVersion;

#if DEBUG
            JsBridge.dbugTestCallbacks();
#endif
            using (JsEngine engine = new JsEngine())
                using (JsContext ctx = engine.CreateContext(new MyJsTypeDefinitionBuilder()))
                {
                    GC.Collect();
                    System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
                    stwatch.Reset();
                    stwatch.Start();

                    var my_expr_ext = new EspressoHostForTsc();
                    ctx.SetVariableAutoWrap("my_expr_ext", my_expr_ext);

                    string testsrc = @"(function(){
                       
                        // test1: general  compile through commamd line
                        // ts.executeCommandLine(['greeter.ts']);
                        //-------------------------------------------------
                        // test 2: generate ast 
                        var filename=""greeter.ts"";  //example only
                        //parse
                        const sourceFile = ts.createSourceFile(filename,
                        my_expr_ext.ReadFile(filename),2, false);
                        //send output as json to managed host
                        my_expr_ext.ConsoleLog(JSON.stringify( sourceFile));
                    })()";
                    stbuilder.Append(testsrc);
                    ctx.Execute(stbuilder.ToString());

                    stwatch.Stop();
                    Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString());
                }
        }
Пример #2
0
        private void button10_Click(object sender, EventArgs e)
        {
            //very basic ***
            //-----------------
            //test tsc.js
            //this needs EspressoHostForTsc
            //-----------------
            string esprima_code = File.ReadAllText("d:\\projects\\Espresso\\js_tools\\tsc\\tsc_espr.js");
            StringBuilder stbuilder = new StringBuilder();
            stbuilder.Append(esprima_code);
            //-----------------

            int version = JsBridge.LibVersion;
            JsBridge.dbugTestCallbacks();
            using (JsEngine engine = new JsEngine())
            using (JsContext ctx = engine.CreateContext(new MyJsTypeDefinitionBuilder()))
            {

                GC.Collect();
                System.Diagnostics.Stopwatch stwatch = new System.Diagnostics.Stopwatch();
                stwatch.Reset();
                stwatch.Start();

                var my_expr_ext = new EspressoHostForTsc();
                ctx.SetVariableAutoWrap("my_expr_ext", my_expr_ext);

                string testsrc = @"(function(){

                        // test1: general  compile through commamd line
                        // ts.executeCommandLine(['greeter.ts']);
                        //-------------------------------------------------
                        // test 2: generate ast
                        var filename=""greeter.ts"";  //example only
                        //parse
                        const sourceFile = ts.createSourceFile(filename,
                        my_expr_ext.ReadFile(filename),2, false);
                        //send output as json to managed host
                        my_expr_ext.ConsoleLog(JSON.stringify( sourceFile));
                    })()";
                stbuilder.Append(testsrc);
                ctx.Execute(stbuilder.ToString());

                stwatch.Stop();
                Console.WriteLine("met1 template:" + stwatch.ElapsedMilliseconds.ToString());
            }
        }