Skip to content

MSIE JavaScript Engine - .NET wrapper for working with the Internet Explorer's JavaScript engines (JsRT version of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript and Chakra Sample Hosts.

License

marcthomas/MsieJavaScriptEngine

 
 

Repository files navigation

MSIE JavaScript Engine for .NET

MSIE JS Engine Logo

This project is a .NET wrapper for working with the Internet Explorer's JavaScript engines (JsRT version of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript and Chakra Sample Hosts.

MSIE JavaScript Engine requires a installation of Internet Explorer on the machine and can work in 4 modes, that are defined in the MsieJavaScriptEngine.JsEngineMode enumeration:

  • Auto. Automatically selects the most modern JavaScript engine from available on the machine.
  • Classic. Classic MSIE JavaScript engine (supports ECMAScript 3 with possibility of using the ECMAScript 5 Polyfill and the JSON2 library). Requires Internet Explorer 6 or higher on the machine.
  • ChakraActiveScript. ActiveScript version of Chakra JavaScript engine (supports ECMAScript 5). Requires Internet Explorer 9 or higher on the machine.
  • ChakraJsRt. JsRT version of Chakra JavaScript engine (supports ECMAScript 5). Requires Internet Explorer 11 or higher on the machine. Detailed information about JsRT you can read in the Paul Vick's blog.

The supported .NET types are as follows:

  • MsieJavaScriptEngine.Undefined
  • System.Boolean
  • System.Int32
  • System.Double
  • System.String

Installation

This library can be installed through NuGet - http://nuget.org/packages/MsieJavaScriptEngine.

Usage

Consider a simple example of usage of the MSIE JavaScript Engine:

namespace MsieJavaScriptEngine.Example.Console
{
	using System;

	using MsieJavaScriptEngine;
	using MsieJavaScriptEngine.Helpers;

	class Program
	{
		static void Main(string[] args)
		{
			try
			{
				using (var jsEngine = new MsieJsEngine(engineMode: JsEngineMode.Auto, 
					useEcmaScript5Polyfill: false, useJson2Library: false))
				{
					const string expression = "7 * 8 - 20";
					var result = jsEngine.Evaluate<int>(expression);

					Console.WriteLine("{0} = {1}", expression, result);
				}
			}
			catch (JsEngineLoadException e)
			{
				Console.WriteLine("During loading of JavaScript engine an error occurred.");
				Console.WriteLine();
				Console.WriteLine(JsErrorHelpers.Format(e));
			}
			catch (JsRuntimeException e)
			{
				Console.WriteLine("During execution of JavaScript code an error occurred.");
				Console.WriteLine();
				Console.WriteLine(JsErrorHelpers.Format(e));
			}

			Console.ReadLine();
		}
	}
}

First we create an instance of the MsieJsEngine class and pass the following parameters to the constructor:

  1. engineMode - JavaScript engine mode;
  2. useEcmaScript5Polyfill - flag for whether to use the ECMAScript 5 Polyfill;
  3. useJson2Library - flag for whether to use the JSON2 library.

The values of constructor parameters in the above code correspond to the default values.

Then we evaluate a JavaScript expression by using of the Evaluate method and output its result to the console.

In addition, we provide handling of the following exception types: JsEngineLoadException and JsRuntimeException.

Release History

See the changelog.

License

Microsoft Public License (Ms-PL)

Credits

Who's Using MSIE JavaScript Engine

If you use the MSIE JavaScript Engine in some project, please send me a message so I can include it in this list:

About

MSIE JavaScript Engine - .NET wrapper for working with the Internet Explorer's JavaScript engines (JsRT version of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript and Chakra Sample Hosts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 90.6%
  • JavaScript 9.3%
  • Batchfile 0.1%