-
Notifications
You must be signed in to change notification settings - Fork 49
ChakraCore
JavaScriptEngineSwitcher.ChakraCore contains a ChakraCoreJsEngine
adapter (wrapper for the ChakraCore version of August 1, 2024.
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:
- JavaScriptEngineSwitcher.ChakraCore.Native.win-x86 contains the native assembly for Windows (x86).
- JavaScriptEngineSwitcher.ChakraCore.Native.win-x64 contains the native assembly for Windows (x64).
- JavaScriptEngineSwitcher.ChakraCore.Native.win-arm contains the native assembly for Windows (ARM). Only compatible with .NET Core and .NET Framework 4.5.
- JavaScriptEngineSwitcher.ChakraCore.Native.win-arm64 contains the native assembly for Windows (ARM64). Only compatible with .NET Core and .NET Framework 4.5.
- JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 contains the native assembly for Linux (x64). Only compatible with .NET Core.
- JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 contains the native assembly for OS X (x64). Only compatible with .NET Core.
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.
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.
First you need to get the libChakraCore.so
assembly file. You have 3 ways to do this:
- Download a assembly file from official repository.
- Download a assembly file from the JavaScript Engine Switcher's project repository.
- Extract a assembly file from the JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 package. The
libChakraCore.so
file is located in theruntimes/linux-x64/native/
directory of NuGet package. - 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
First you need to get the libChakraCore.dylib
assembly file. You have 3 ways to do this:
- Download a assembly file from official repository.
- Download a assembly file from the JavaScript Engine Switcher's project repository.
- Extract a assembly file from the JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64 package. The
libChakraCore.dylib
file is located in theruntimes/osx-x64/native/
directory of NuGet package. - 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 "$_"
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 |
---|---|---|---|
AllowReflection |
Boolean |
false |
Flag for whether to allow the usage of reflection API in the script code. This affects |
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 with custom code and Function constructors taking function code as string. |
DisableExecutablePageAllocation |
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 |
true |
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 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. |
- Registration of JS engines
- Creating instances of JS engines
- JS engines
- Upgrade guides
- Additional reading and resources