Javascript Interpreter for C# (no dependencies)
#scripting #script-engine

Sébastien Ros 72f5e15e18 Update README.md %!s(int64=11) %!d(string=hai) anos
.nuget 9b18dabfed Adding missing nuget.exe %!s(int64=11) %!d(string=hai) anos
Jint 16f5df6e55 Implementing String.prototype.substr %!s(int64=11) %!d(string=hai) anos
Jint.Benchmark d2a5131df8 Enabling nuget package restore for CI %!s(int64=11) %!d(string=hai) anos
Jint.Repl 886f59c3a3 Displaying error message in Repl %!s(int64=11) %!d(string=hai) anos
Jint.Tests 6d0b917dba Adding ability to convert ObjectInstance into object %!s(int64=11) %!d(string=hai) anos
Jint.Tests.CommonScripts 4f405f7b02 Refactoring SunSpider tests %!s(int64=11) %!d(string=hai) anos
Jint.Tests.Ecma 285a7cbc84 Fixing RegExp unit tests %!s(int64=11) %!d(string=hai) anos
Jint.Tests.Scaffolding b6d60818da Adding Ecma 262 tests %!s(int64=12) %!d(string=hai) anos
.gitignore 2dab8046d6 Scaffolding project vs. hand written classes %!s(int64=12) %!d(string=hai) anos
CREDITS.txt f53137698a Adding license information %!s(int64=11) %!d(string=hai) anos
Jint.sln 3c9bf7fc63 Moving SunSpider tests to its own assembly %!s(int64=11) %!d(string=hai) anos
Jint.sln.DotSettings 478662033e Refactoring Date to reflect specifications %!s(int64=11) %!d(string=hai) anos
LICENSE.txt f53137698a Adding license information %!s(int64=11) %!d(string=hai) anos
README.md 72f5e15e18 Update README.md %!s(int64=11) %!d(string=hai) anos

README.md

Build status

Jint

Jint is a Javascript interpreter for .NET. Jint doesn't compile Javascript to .NET bytecode and in this sense might be best suited for projects requiring to run relatively small scripts faster, or which need to run on different platforms.

Objectives

Example

This example defines a new value named log pointing to Console.WriteLine, then executes a script calling log('Hello World!').

var engine = new Engine()
    .SetValue("log", new Action<object>(Console.WriteLine))
    ;

engine.Execute(@"
  function hello() { 
    log("Hello World");
  };

  hello();
");

Here, the variable x is set to 3 and x * x is executed in JavaScript. The result is returned to .NET directly, in this case as a double value 9.

var square = new Engine()
    .SetValue("x", 3)
    .Execute("x * x")
    .ToObject()
    ;

You can also directly pass POCOs or anonymous objects and use them from JavaScript. In this example for instance a new Person instance is manipulated from JavaScript.

var p = new Person {
    Name = "Mickey Mouse"
};

var engine = new Engine()
    .SetValue("p", p)
    .Execute("p.Name === 'Mickey Mouse')
    ;

Roadmap

Features already implemented:

  • Most of the ECMAScript test suite (http://test262.ecmascript.org/) is passing
  • Manipulate CLR objects from JavaScript, including:
    • Single values
    • Objects
    • Properties
    • Methods
    • Delegates
    • Anonymous objects
  • Convert JavaScript values to CLR objects
    • Primitive values
    • Object -> expando objects (IDictionary<string, object> and dynamic)
    • Array -> object[]
    • Date -> DateTime
    • number -> double
    • string -> string
    • boolean -> bool
    • Regex -> RegExp

Current tasks:

  • Fix remaining SunSpider scripts
    • crypto-aes
    • string-tagcloud
    • string-unpack-code
    • 3d-raytrace