Compiling CoffeeScript

May 13, 2011 at 3:10 AM

Hi,

I was trying to use JINT to run  CoffeeScript compiler.

The code is:

Console.WriteLine(ctx.Run(CoffeeScript.Code)); // content of coffee-script.js
Console.WriteLine(ctx.Run("return CoffeeScript.run('1+2');"));

The last line fails with the exception below. I suppose there is something to do with scoping or similar as the tokenize method is defined in the coffee-script.js file.

Jint.JintException was unhandled
  Message=Method isn't defined: tokenize
Line: 8 Char: 161101
No source code available.
  Source=Jint
  StackTrace:
       at Jint.JintEngine.Run(Program program, Boolean unwrap) in Jint\JintEngine.cs:line 252
       at Jint.JintEngine.Run(String script, Boolean unwrap) in Jint\JintEngine.cs:line 199
       at Jint.JintEngine.Run(String script) in Jint\JintEngine.cs:line 130
       at PropConnect.Coffee.Program.Main(String[] args) in Program.cs:line 16
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: Jint.Native.JsException
       Message=Exception of type 'Jint.Native.JsException' was thrown.
       Source=Jint
       StackTrace:
            at Jint.ExecutionVisitor.Visit(ThrowStatement statement) in Jint\ExecutionVisitor.cs:line 553
            at Jint.Expressions.ThrowStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\ThrowStatement.cs:line 16
            at Jint.ExecutionVisitor.Visit(BlockStatement statement) in Jint\ExecutionVisitor.cs:line 287
            at Jint.Expressions.BlockStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\BlockStatement.cs:line 16
            at Jint.ExecutionVisitor.Visit(TryStatement statement) in Jint\ExecutionVisitor.cs:line 578
            at Jint.Expressions.TryStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\TryStatement.cs:line 17
            at Jint.ExecutionVisitor.Visit(BlockStatement statement) in Jint\ExecutionVisitor.cs:line 287
            at Jint.Expressions.BlockStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\BlockStatement.cs:line 16
            at Jint.ExecutionVisitor.CallFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters) in Jint\ExecutionVisitor.cs:line 1417
            at Jint.Native.JsFunction.Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters) in Jint\Native\JsFunction.cs:line 94
            at Jint.ExecutionVisitor.ExecuteFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters, Type[] genericParameters) in Jint\ExecutionVisitor.cs:line 1389
            at Jint.ExecutionVisitor.Visit(MethodCall methodCall) in Jint\ExecutionVisitor.cs:line 1314
            at Jint.Expressions.MethodCall.Accept(IStatementVisitor visitor) in Jint\Expressions\MethodCall.cs:line 22
            at Jint.ExecutionVisitor.Visit(MemberExpression expression) in Jint\ExecutionVisitor.cs:line 1199
            at Jint.Expressions.MemberExpression.Accept(IStatementVisitor visitor) in Jint\Expressions\MemberExpression.cs:line 21
            at Jint.ExecutionVisitor.Visit(MethodCall methodCall) in Jint\ExecutionVisitor.cs:line 1282
            at Jint.Expressions.MethodCall.Accept(IStatementVisitor visitor) in Jint\Expressions\MethodCall.cs:line 22
            at Jint.ExecutionVisitor.Visit(MemberExpression expression) in Jint\ExecutionVisitor.cs:line 1199
            at Jint.Expressions.MemberExpression.Accept(IStatementVisitor visitor) in Jint\Expressions\MemberExpression.cs:line 21
            at Jint.ExecutionVisitor.Visit(MemberExpression expression) in Jint\ExecutionVisitor.cs:line 1196
            at Jint.Expressions.MemberExpression.Accept(IStatementVisitor visitor) in Jint\Expressions\MemberExpression.cs:line 21
            at Jint.ExecutionVisitor.Visit(ReturnStatement statement) in Jint\ExecutionVisitor.cs:line 500
            at Jint.Expressions.ReturnStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\ReturnStatement.cs:line 19
            at Jint.ExecutionVisitor.Visit(BlockStatement statement) in Jint\ExecutionVisitor.cs:line 287
            at Jint.Expressions.BlockStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\BlockStatement.cs:line 16
            at Jint.ExecutionVisitor.CallFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters) in Jint\ExecutionVisitor.cs:line 1417
            at Jint.Native.JsFunction.Execute(IJintVisitor visitor, JsDictionaryObject that, JsInstance[] parameters) in Jint\Native\JsFunction.cs:line 94
            at Jint.ExecutionVisitor.ExecuteFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters, Type[] genericParameters) in Jint\ExecutionVisitor.cs:line 1389
            at Jint.ExecutionVisitor.Visit(MethodCall methodCall) in Jint\ExecutionVisitor.cs:line 1314
            at Jint.Expressions.MethodCall.Accept(IStatementVisitor visitor) in Jint\Expressions\MethodCall.cs:line 22
            at Jint.ExecutionVisitor.Visit(MemberExpression expression) in Jint\ExecutionVisitor.cs:line 1199
            at Jint.Expressions.MemberExpression.Accept(IStatementVisitor visitor) in Jint\Expressions\MemberExpression.cs:line 21
            at Jint.ExecutionVisitor.Visit(ReturnStatement statement) in Jint\ExecutionVisitor.cs:line 500
            at Jint.Expressions.ReturnStatement.Accept(IStatementVisitor visitor) in Jint\Expressions\ReturnStatement.cs:line 19
            at Jint.ExecutionVisitor.Visit(Program program) in Jint\ExecutionVisitor.cs:line 149
            at Jint.JintEngine.Run(Program program, Boolean unwrap) in Jint\JintEngine.cs:line 225

Some guidance would be appreciated.

 

 

Thanks,
Dima.

Jun 24, 2011 at 5:52 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.