Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taritsyn/msiejavascriptengine
.NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy.
https://github.com/taritsyn/msiejavascriptengine
activescript chakra dotnet ecmascript edge javascript javascript-engine jsrt msie
Last synced: 5 days ago
JSON representation
.NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy.
- Host: GitHub
- URL: https://github.com/taritsyn/msiejavascriptengine
- Owner: Taritsyn
- License: apache-2.0
- Created: 2012-08-26T10:43:27.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-03-01T16:45:28.000Z (9 months ago)
- Last Synced: 2024-09-17T04:38:17.214Z (about 2 months ago)
- Topics: activescript, chakra, dotnet, ecmascript, edge, javascript, javascript-engine, jsrt, msie
- Language: C#
- Homepage:
- Size: 5.25 MB
- Stars: 105
- Watchers: 14
- Forks: 22
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
MSIE JavaScript Engine for .NET [![NuGet version](http://img.shields.io/nuget/v/MsieJavaScriptEngine.svg)](https://www.nuget.org/packages/MsieJavaScriptEngine/) [![Download count](https://img.shields.io/nuget/dt/MsieJavaScriptEngine.svg)](https://www.nuget.org/packages/MsieJavaScriptEngine/)
===============================![MSIE JS Engine Logo](http://i.imgur.com/T3K5q.png)
This project is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge Legacy (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine).
Project was based on the code of [SassAndCoffee.JavaScript](https://github.com/anaisbetts/SassAndCoffee), [Chakra Sample Hosts](https://github.com/panopticoncentral/chakra-host) and [jsrt-dotnet](https://github.com/robpaveza/jsrt-dotnet).MSIE JavaScript Engine requires a installation of Internet Explorer or Edge Legacy 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 Legacy on the machine.
* `ChakraEdgeJsRt`. “Edge” JsRT version of Chakra JavaScript engine (supports ECMAScript 5). Requires Microsoft Edge Legacy 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 - [https://www.nuget.org/packages/MsieJavaScriptEngine](https://www.nuget.org/packages/MsieJavaScriptEngine).## Usage
Consider a simple example of usage of the MSIE JavaScript Engine:```csharp
using System;using MsieJavaScriptEngine;
using MsieJavaScriptEngine.Helpers;namespace MsieJavaScriptEngine.Example.Console
{
class Program
{
static void Main(string[] args)
{
try
{
using (var jsEngine = new MsieJsEngine())
{
const string expression = "7 * 8 - 20";
var result = jsEngine.Evaluate(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.GenerateErrorDetails(e));
}
catch (JsScriptException e)
{
Console.WriteLine("During processing of JavaScript code an error occurred.");
Console.WriteLine();
Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(e));
}
catch (JsException e)
{
Console.WriteLine("During working of JavaScript engine an unknown error occurred.");
Console.WriteLine();
Console.WriteLine(JsErrorHelpers.GenerateErrorDetails(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
,JsScriptException
andJsException
.
In the MSIE JavaScript Engine, exceptions have the following hierarchy:*
JsException
*JsEngineException
*JsEngineLoadException
*JsFatalException
*JsScriptException
*JsCompilationException
*JsRuntimeException
*JsInterruptedException
*JsUsageException
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 theJsEngineSettings
class:
Property name
Data type
Default value
Description
AllowReflection
Boolean
false
Flag for whether to allow the usage of reflection API in the script code.
This affects
Object.GetType
,Exception.GetType
,Exception.TargetSite
andDelegate.Method
.
EnableDebugging
Boolean
false
Flag for whether to allow debugging in Visual Studio by adding thedebugger
statement to script code.
EngineMode
JsEngineMode
enumeration
Auto
JavaScript engine mode.
MaxStackSize
Int32
503 808
or1 007 616
Maximum stack size in bytes.
Set a
0
to use the default maximum stack size specified in the header for the executable.
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](CHANGELOG.md).## License
[Apache License Version 2.0](LICENSE.md)## Credits
* [SassAndCoffee.JavaScript](https://github.com/anaisbetts/SassAndCoffee) - [License: Microsoft Public License (Ms-PL)](https://github.com/anaisbetts/SassAndCoffee/blob/master/COPYING) Part of the code of this library served as the basis for the ActiveScript version of Chakra and Classic JavaScript Engine.
* [Chakra Sample Hosts](https://github.com/panopticoncentral/chakra-host) - [License: Apache License 2.0 (Apache)](https://github.com/panopticoncentral/chakra-host/blob/master/LICENSE) C# example from this project served as the basis for the JsRT versions of Chakra.
* [jsrt-dotnet](https://github.com/robpaveza/jsrt-dotnet) - [License: The MIT License (MIT)](https://github.com/robpaveza/jsrt-dotnet/blob/master/LICENSE) Part of the code of this library is used in the JsRT versions of Chakra.
* [ECMAScript 5 Polyfill](https://www.nuget.org/packages/ES5) and [MDN JavaScript Polyfills](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) - Adds support for many of the new functions in ECMAScript 5 to downlevel browsers.
* [Cross-Browser Split](https://blog.stevenlevithan.com/archives/cross-browser-split) - Adds ECMAScript compliant and uniform cross-browser split method.
* [JSON2 library](https://github.com/douglascrockford/JSON-js) - Adds support of the JSON object from ECMAScript 5 to downlevel browsers.
* [UglifyJS](https://github.com/mishoo/UglifyJS) - [License: BSD License (BSD)](https://github.com/mishoo/UglifyJS/blob/master/LICENSE) JS-files, that used MSIE JS Engine, minificated by using this tool.## 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:* [BitAdminCore.ALL](https://www.nuget.org/packages/BitAdminCore.ALL)
* [Chevron](https://github.com/simoncropparchived/Chevron) by Simon Cropp
* [JavaScript Engine Switcher](https://github.com/Taritsyn/JavaScriptEngineSwitcher) by Andrey Taritsyn
* [PowerShell.JS](https://github.com/klumsy/powershellJS) by Karl Prosser
* [SquishIt](https://github.com/jetheredge/SquishIt) by Justin Etheredge and Alex Ullrich
* [Strike](https://github.com/simoncropparchived/Strike) by Simon Cropp