|
|
|
|
Jint - Javascript Interpreter for .NET - Home 参考:http://jint.codeplex.com/
Jint - Javascript Interpreter for .NET
Project DescriptionJint is a script engine based on the Javascript language. Using Jint, developers can provide fully scriptable applications, execute .NET code without compiling, or create external configuration logic, using the most used script language. Jint aims at providing every JavaScript functionalities to .NET applications, and bindings to .NET languages can be done in both sides. Jint scripts can use any .NET object from your application, and use every part of the .NET base class library.
Differences with other script enginesJint is different as it doesn't use CodeDomProvider technique which is using compilation under the hood and thus leads to memory leaks as the compiled assemblies can't be unloaded. Moreover, using this technique prevents using dynamically types variables the way JavaScript does, allowing more flexibility in your scripts. On the opposite, Jint embeds it's own parsing logic, and really interprets the scripts. Jint uses the famous ANTLR (http://www.antlr.org) library for this purpose. As it uses Javascript as its language you don't have to learn a new language, it has proven to be very powerful for scripting purposes, and you can use several text editors for syntax checking.
Usage scenarios
- Create applications users can automate by providing a programmable interface. A good example is what VBA is for Microsoft Office applications
- Enhance configurability to change your application's behavior and logic without compiling or deploying binaries
- Evaluate dynamic code or expressions
Sample usageHere is a sample in C#, but any .NET language can use Jint. Jint is able to handle all advanced JavaScript techniques decribed on this MSDN article: http://msdn.microsoft.com/en-us/magazine/cc163419.aspx. It currently implements all concepts defined in ECMAScript version 3.0.
script= @"
function square(x) {
return x * x;
};
return square(number);
";
var result = new JintEngine()
.SetParameter("number", 3)
.Run(script));
Assert.AreEqual(9, result);
You can also check the actual implemented test suite for more samples.
Implemented artifacts
- Standard Javascript elements:
- Objects and methods
- Loops (do, while, for)
- Code blocks and scopes
- Conditional statements (if, switch/case)
- Json
- Property indexers
- Dynamic properties
- Javascript native classes (Math, String, Object, Number)
- Regular expressions
- Functions (declarations plus anonymous functions)
- Prototypes and constructors
- .NET bindings
- External objects and values
- External functions to enhance the script resources
- Return value to .NET code
- Out of the box Jint Shell application
- Use Jint on the command line
DeploymentJint is deployed as a part of your application and fits inside a single assembly. Nothing as to be installed on the client machine.
Roadmap
- 0.8 - All javascript languages artifacts as of ECMAScript 3.0
- 0.9 - Beta phase - All javascript core methods are implemented (Math, slice, ...)
- 1.0 - Positive feedback from Beta
- 1.1 - ECMAScript 5.0 elements
|
|
|
|