Javascript newbie tries Jint

Jan 18, 2012 at 7:27 AM

I've been trying to use Javascript for the last few days (I am a C# developer) because a requirement was to use an existing Javascript library called citeproc.

This is the third Javascript app I've tried:
Using the built-in scripting in a WebBrowser was unreliable and just returned COM objects;
Then I found Jurassic which worked but took 15-20 seconds to compile the scripts;
Then I found Jint which seemed promising but I have found some strange issues:

1) Calling a non-existent function returned a JsRegExp object!
A little more investigation showed that Jint returns the last 'value' it encountered (which happened to be a global variable in the citeproc.js script). Surely CallFunction should throw an exception or return null for a non-existent function?

2) Jint.Native.JsException : Exception of type 'Jint.Native.JsException' was thrown.
Not very helpful! I had to break on this exception and use the GUI exception viewer to try to find out what the error is. "Function expected." was the answer but that still doesn't help me find the real issue.

3) I tried following the instructions on the Documentation page for Debugging. That didn't even compile - Location is not a property on DebugInformation! Commenting this out still didn't help me.

4) I though I would get the source code and step-through to find the problem. I updated the project to VS2010 and tried to compile. No good. Each project requires a different .NET version! I can understand using .NET 4.0 for the Tests but the main code is set for .NET 2.0 but the Antlr3 runtime requires .NET 3.5 and produced 1189 errors immediately so how the distributed binary DLL was compiled I don't know!

A few other comments:

- Whilst using the debugger (I'm going to be doing a lot of that!), I found that I had to go about 9 levels deep just to find out what value a property had. Suggest use of Debugger display values to eliminate some of that (or override ToString where applicable) esp. on ValueDescriptor.

- The indexer on JsObject requires a JsInstance object. It would be nice if certain items could be added directly. e.g. from C#  jsObj["name"] = "fred". Not sure if this is possible but implicit operators might help.


I really wanted to use a NET 2.0 compatible interpreter but I will try and recompile for 3.5 - at least to find out what problems exist in my scripts.