Skip to content
Taritsyn edited this page Mar 7, 2024 · 6 revisions

JavaScriptEngineSwitcher.Msie contains a MsieJsEngine adapter (wrapper for the MSIE JavaScript Engine for .NET).

For correct working of the MSIE JavaScript Engine it is recommended to install Internet Explorer 9+ or Microsoft Edge Legacy on the machine.

Engine settings

You can specify a settings of JS engine during its registration:

engineSwitcher.EngineFactories
    .AddMsie(new MsieSettings
    {
        EngineMode = JsEngineMode.ChakraIeJsRt
    })
    ;

If you manually create an instance of JS engine, then you can pass settings via the constructor:

IJsEngine engine = new MsieJsEngine(
    new MsieSettings
    {
        EngineMode = JsEngineMode.ChakraIeJsRt
    }
);

Consider in detail properties of the MsieSettings 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 and Delegate.Method.

EnableDebugging Boolean false Flag for whether to allow debugging in Visual Studio by adding the debugger statement to script code.
EngineMode JsEngineMode enumeration Auto JS engine mode. Can take the following values:
  • 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.
MaxStackSize Int32 503 808 or 1 007 616

Maximum stack size in bytes.

Set a 0 to use the default maximum stack size specified in the header for the executable.

Not supported in version for .NET Core 1.X.

UseEcmaScript5Polyfill Boolean false Flag for whether to use the ECMAScript 5 Polyfill.
UseJson2Library Boolean false Flag for whether to use the JSON2 library

Debugging

MSIE JavaScript Engine for .NET has support of the debugging in Visual Studio 2010-2012. In addition, debuggable script must contain a debugger statement (see MSDN for more details).

Here are steps, that you need to do for start of debugging:

  1. Switch the solution in debug mode.

  2. Set the EnableDebugging property of the MsieSettings class to true.

  3. Add the debugger statements in debuggable script code.

  4. Click on the Start button.

  5. In opened the Visual Studio Just-In-Time Debugger window select the New instance of Microsoft Visual Studio 2012 item:

    “Visual Studio Just-In-Time Debugger” window

  6. In the Visual Studio debugger window open the script block(s) and set breakpoint(s):

    Setting of breakpoint in the script blocks

  7. Return to the main Visual Studio window and click on the Continue button.

    MSIE script debugging in Visual Studio 2012