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

Sebastien Ros a43e256d98 Signing the assembly 11 years ago
.nuget 9b18dabfed Adding missing nuget.exe 11 years ago
Jint a43e256d98 Signing the assembly 11 years ago
Jint.Benchmark d2a5131df8 Enabling nuget package restore for CI 11 years ago
Jint.Repl 8dc63cd4c2 Fixing Repl 11 years ago
Jint.Tests 6660b6c8f6 Fixing unit tests 11 years ago
Jint.Tests.CommonScripts 4f405f7b02 Refactoring SunSpider tests 11 years ago
Jint.Tests.Ecma 0e3846aad4 Removing "Pass" category as all tests pass 11 years ago
Jint.Tests.Scaffolding b6d60818da Adding Ecma 262 tests 12 years ago
.gitignore 2dab8046d6 Scaffolding project vs. hand written classes 12 years ago
CREDITS.txt f53137698a Adding license information 11 years ago
Jint.sln 3c9bf7fc63 Moving SunSpider tests to its own assembly 11 years ago
Jint.sln.DotSettings 478662033e Refactoring Date to reflect specifications 11 years ago
LICENSE.txt f53137698a Adding license information 11 years ago
README.md 8012835585 Fixing sample 11 years ago

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) // define a new variable
    .Execute("x * x") // execute a statement
    .GetCompletionValue() // get the latest statement completion value
    .ToObject() // converts the value to .NET
    ;

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')
    ;

If you need to pass a JavaScript callback to the CLR, then it will be converted to a Delegate. You can also use it as a parameter of a CLR method from JavaScript.

var function = new Engine()
    .Execute("function add(a, b) { return this + a + b; }");
    .GetGlobalValue("add")
    .ToObject() as Delegate;

var result = function.DynamicInvoke(
    new JsValue("foo") /* thisArg */, 
    new JsValue[] { 1, "bar" } /* arguments */,
    ); // "foo1bar"

Roadmap

Features already implemented:

  • ECMAScript test suite (http://test262.ecmascript.org/)
  • 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
    • Function -> Delegate

Current tasks:

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