Code Monkey home page Code Monkey logo

antiufo / msiejavascriptengine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taritsyn/msiejavascriptengine

0.0 3.0 0.0 4.43 MB

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

License: Microsoft Public License

Batchfile 0.48% PowerShell 0.31% Shell 0.26% C# 93.69% JavaScript 5.27%

msiejavascriptengine's Introduction

MSIE JavaScript Engine for .NET

MSIE JS Engine Logo

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

MSIE JavaScript Engine requires a installation of Internet Explorer or Edge on the machine and can work in 5 modes, that are defined in the 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. Not supported in version for .NET Core.
  • ChakraActiveScript. ActiveScript version of Chakra JavaScript engine (supports ECMAScript 5). Requires Internet Explorer 9 or higher on the machine. Not supported in version for .NET Core.
  • ChakraIeJsRt. “IE” JsRT version of Chakra JavaScript engine (supports ECMAScript 5). Requires Internet Explorer 11 or Microsoft Edge on the machine.
  • ChakraEdgeJsRt. “Edge” JsRT version of Chakra JavaScript engine (supports ECMAScript 5). Requires Microsoft Edge on the machine.

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())
				{
					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. 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.

Also, when you create an instance of the MsieJsEngine class, then you can pass the JavaScript engine settings via the constructor. Consider in detail properties of the JsEngineSettings class:

Property name Data type Default value Description
EnableDebugging Boolean false Flag for whether to allow debugging in Visual Studio by adding the debugger statement to script code (only works in the ChakraIeJsRt and ChakraEdgeJsRt modes).
EngineMode JsEngineMode enumeration Auto JavaScript engine mode.
UseEcmaScript5Polyfill Boolean false Flag for whether to use the ECMAScript 5 Polyfill.
UseJson2Library Boolean false Flag for whether to use the JSON2 library

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:

msiejavascriptengine's People

Contributors

alexcuse avatar taritsyn avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.