Skip to content

Commit 6fb1aa4

Browse files
committed
README.md: added information about the engine modes, supported .NET types and simple example of usage
1 parent eab287f commit 6fb1aa4

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,79 @@ MSIE JavaScript Engine for .NET
66
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).
77
Project was based on the code of [SassAndCoffee.JavaScript](http://github.com/paulcbetts/SassAndCoffee) and [Chakra Sample Hosts](http://github.com/panopticoncentral/chakra-host).
88

9+
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:
10+
11+
* `Auto`. Automatically selects the most modern JavaScript engine from available on the machine.
12+
* `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.
13+
* `ChakraActiveScript`. ActiveScript version of Chakra JavaScript engine (supports ECMAScript 3 with possibility of using the ECMAScript 5 Polyfill and the JSON2 library). Requires Internet Explorer 9 or higher on the machine.
14+
* `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](http://www.panopticoncentral.net/category/javascript/).
15+
16+
The supported .NET types are as follows:
17+
18+
* `MsieJavaScriptEngine.Undefined`
19+
* `System.Boolean`
20+
* `System.Int32`
21+
* `System.Double`
22+
* `System.String`
23+
924
## Installation
1025
This library can be installed through NuGet - [http://nuget.org/packages/MsieJavaScriptEngine](http://nuget.org/packages/MsieJavaScriptEngine).
1126

27+
## Usage
28+
Consider a simple example of usage of the MSIE JavaScript Engine:
29+
30+
namespace MsieJavaScriptEngine.Example.Console
31+
{
32+
using System;
33+
34+
using MsieJavaScriptEngine;
35+
using MsieJavaScriptEngine.Helpers;
36+
37+
class Program
38+
{
39+
static void Main(string[] args)
40+
{
41+
try
42+
{
43+
using (var jsEngine = new MsieJsEngine(engineMode: JsEngineMode.Auto,
44+
useEcmaScript5Polyfill: false, useJson2Library: false))
45+
{
46+
const string expression = "7 * 8 - 20";
47+
var result = jsEngine.Evaluate<int>(expression);
48+
49+
Console.WriteLine("{0} = {1}", expression, result);
50+
}
51+
}
52+
catch (JsEngineLoadException e)
53+
{
54+
Console.WriteLine("During loading of JavaScript engine an error occurred.");
55+
Console.WriteLine();
56+
Console.WriteLine(JsErrorHelpers.Format(e));
57+
}
58+
catch (JsRuntimeException e)
59+
{
60+
Console.WriteLine("During execution of JavaScript code an error occurred.");
61+
Console.WriteLine();
62+
Console.WriteLine(JsErrorHelpers.Format(e));
63+
}
64+
65+
Console.ReadLine();
66+
}
67+
}
68+
}
69+
70+
First we create an instance of the `MsieJsEngine` class and pass the following parameters to the constructor:
71+
72+
1. `engineMode` - JavaScript engine mode;
73+
2. `useEcmaScript5Polyfill` - flag for whether to use the ECMAScript 5 Polyfill;
74+
3. `useJson2Library` - flag for whether to use the [JSON2](http://github.com/douglascrockford/JSON-js) library.
75+
76+
The values of constructor parameters in the above code correspond to the default values.
77+
78+
Then we evaluate a JavaScript expression by using of the `Evaluate` method and output its result to the console.
79+
80+
In addition, we provide handling of the following exception types: `JsEngineLoadException` and `JsRuntimeException`.
81+
1282
## Release History
1383
See the [changelog](CHANGELOG.md).
1484

0 commit comments

Comments
 (0)