static IEJavaScriptEngine CreateEngine()
 {
     var engine = new IEJavaScriptEngine();
     engine.LoadLibrary(Properties.Resources.coffeescript);
     engine.LoadLibrary("function compile(c) { return CoffeeScript.compile(c); }");
     return engine;
 }
Пример #2
0
        static IEJavaScriptEngine CreateEngine()
        {
            var engine = new IEJavaScriptEngine();

            engine.LoadLibrary(Properties.Resources.coffeescript);
            engine.LoadLibrary("function compile(c) { return CoffeeScript.compile(c); }");
            return(engine);
        }
Пример #3
0
 public void GivenCoffeeScriptCompilerLoaded_WhenCompileCalled_ThenJavaScriptReturned()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.LoadLibrary(Properties.Resources.coffeescript);
         engine.LoadLibrary("function compile(code) { return CoffeeScript.compile(code); }");
         var js = engine.CallFunction<string>("compile", "x = 1");
         js.ShouldEqual("(function() {\n  var x;\n  x = 1;\n}).call(this);\n");
     }
 }
Пример #4
0
 public void GivenCoffeeScriptCompilerLoaded_WhenCompileCalled_ThenJavaScriptReturned()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.Initialize();
         engine.LoadLibrary(Properties.Resources.coffeescript);
         engine.LoadLibrary("function compile(code) { return CoffeeScript.compile(code); }");
         var js = engine.CallFunction <string>("compile", "x = 1");
         js.ShouldEqual("(function() {\n  var x;\n\n  x = 1;\n\n}).call(this);\n");
     }
 }
Пример #5
0
 public void GivenCoffeeScriptCompilerLoaded_WhenCompileInvalidCoffeeScript_ThenExceptionThrown()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.LoadLibrary(Properties.Resources.coffeescript);
         engine.LoadLibrary("function compile(code) { return CoffeeScript.compile(code); }");
         var exception = Assert.Throws<ActiveScriptException>(
             () => engine.CallFunction<string>("compile", "x = [1..")
         );
         exception.Message.ShouldEqual("unclosed [ on line 1");
     }
 }
        IEJavaScriptEngine CreateEngine()
        {
            var engine = new IEJavaScriptEngine();
            engine.Initialize();
            engine.LoadLibrary(Properties.Resources.coffeescript);
            engine.LoadLibrary(
                @"function compile(c) {
    try {
        return { output: CoffeeScript.compile(c), error: '' };
    } catch (e) {
        return { error: e.message };
    }
}");
            return engine;
        }
Пример #7
0
            IEJavaScriptEngine CreateEngine()
            {
                var engine = new IEJavaScriptEngine();

                engine.Initialize();
                engine.LoadLibrary(Properties.Resources.coffeescript);
                engine.LoadLibrary(@"function compile(c) {
    try {
        return { output: CoffeeScript.compile(c), error: '' };
    } catch (e) {
        return { error: e.message };
    }
}");
                return(engine);
            }
Пример #8
0
 public void GivenLibraryLoaded_WhenCallFunctionPassingInArgument_ThenResultReturned()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.LoadLibrary("function test(input) { return input * 2; }");
         var result = engine.CallFunction<int>("test", 10);
         result.ShouldEqual(20);
     }
 }
Пример #9
0
 public void GivenScriptThatThrows_WhenExecuted_ThenExceptionThrown()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.LoadLibrary("function fail() { return this.x.y; }");
         Assert.Throws<ActiveScriptException>(
             () => engine.CallFunction<object>("fail")
         );
     }
 }
Пример #10
0
 public void GivenGlobalAddedToEngine_WhenScriptUsesGlobalFunction_ThenResultReturned()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.AddGlobalValue("Test", new GlobalData());
         engine.LoadLibrary("function go() { return Test.hello('John'); }");
         var result = engine.CallFunction<string>("go");
         result.ShouldEqual("Hello, John");
     }
 }
Пример #11
0
 public void GivenSyntaxError_WhenLoadLibrary_ThenExceptionThrown()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.Initialize();
         Assert.Throws<ActiveScriptException>(
             () => engine.LoadLibrary("var !x = 1;")
         );
     }
 }
Пример #12
0
 public void GivenGlobalAddedToEngine_WhenScriptUsesGlobalFunctionWithCallback_ThenCallbackInvoked()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.AddGlobalValue("Test", new GlobalData());
         engine.LoadLibrary(@"
     function go() {
     var result;
     Test.process(function(x) {
     result = x;
     });
     return result;
     }");
         var result = engine.CallFunction<string>("go");
         result.ShouldEqual("done");
     }
 }
Пример #13
0
 public void GivenGlobalAddedToEngine_WhenScriptUsesGlobalFunctionWithCallback_ThenCallbackInvoked()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.Initialize();
         engine.AddGlobalValue("Test", new GlobalData());
         engine.LoadLibrary(@"
     function go() {
     var result;
     Test.process(function(x) {
     result = x;
     });
     return result;
     }");
         // TODO: Someone smarter can figure out how to make this test pass in FX35. (kamranayub)
     #if NET40
         var result = engine.CallFunction<string>("go");
         result.ShouldEqual("done");
     #endif
     }
 }