ChakraCore

Taritsyn edited this page Jan 11, 2019 · 6 revisions

JavaScriptEngineSwitcher.ChakraCore contains adapter ChakraCoreJsEngine (wrapper for the ChakraCore version 1.11.5). Project was based on the code of Chakra-Samples and jsrt-dotnet.

This package does not contain the native implementations of ChakraCore. Therefore, you need to choose and install the most appropriate package(s) for your platform. The following packages are available:

* - Requires the Microsoft Visual C++ Redistributable for Visual Studio 2017.

If you need support for other operating systems, then you can build the ChakraCore assembly by using following instructions from official repository. Only instead of the latest version of ChakraCore's source code, you need to use a version, that is supported by the JavaScriptEngineSwitcher.ChakraCore.

Mono support

JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 and JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 packages do not support installation under Mono, but you can to install the native assemblies manually.

Linux

First you need to get the libChakraCore.so assembly file. You have 3 ways to do this:

  1. Download a assembly file from official repository.
  2. Download a assembly file from the JavaScript Engine Switcher's project repository.
  3. Extract a assembly file from the JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 package. The libChakraCore.so file is located in the runtimes/linux-x64/native/ directory of NuGet package.
  4. Build a assembly file from the source code.

Afterwards open a terminal window and change directory to the directory where the libChakraCore.so file is located. Next, enter the following command:

sudo cp libChakraCore.so /usr/local/lib/
sudo ldconfig

OS X

First you need to get the libChakraCore.dylib assembly file. You have 3 ways to do this:

  1. Download a assembly file from official repository.
  2. Download a assembly file from the JavaScript Engine Switcher's project repository.
  3. Extract a assembly file from the JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 package. The libChakraCore.dylib file is located in the runtimes/osx-x64/native/ directory of NuGet package.
  4. Build a assembly file from the source code.

Afterwards open a terminal window and change directory to the directory where the libChakraCore.dylib file is located. Next, enter the following command:

mkdir -p /usr/local/lib/ && cp libChakraCore.dylib "$_"

Engine settings

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

engineSwitcher.EngineFactories
	.AddChakraCore(new ChakraCoreSettings
	{
		DisableEval = true,
		EnableExperimentalFeatures = true
	})
	;

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

IJsEngine engine = new ChakraCoreJsEngine(
	new ChakraCoreSettings
	{
		DisableEval = true,
		EnableExperimentalFeatures = true
	}
);

Consider in detail properties of the ChakraCoreSettings class:

Property name Data type Default value Description
DisableBackgroundWork Boolean false Flag for whether to disable any background work (such as garbage collection).
DisableEval Boolean false Flag for whether to disable calls of eval function.
DisableExecutablePage­Allocation Boolean false

Flag for whether to disable executable page allocation.

This also implies that Native Code generation will be turned off.

Note that this will break JavaScript stack decoding in tools like WPA since they rely on allocation of unique thunks to interpret each function and allocation of those thunks will be disabled as well.

DisableFatalOnOOM Boolean false Flag for whether to disable Failfast fatal error on OOM.
DisableNativeCodeGeneration Boolean false Flag for whether to disable native code generation.
EnableExperimentalFeatures Boolean false Flag for whether to enable all experimental features.
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.

MemoryLimit UIntPtr new UIntPtr(uint.MaxValue) or new UIntPtr(ulong.MaxValue) Current memory limit for a runtime in bytes. By default, no limit.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.