Skip to content

Commit faeb5f0

Browse files
committed
In JavaScriptEngineSwitcher.ChakraCore in configuration settings of the ChakraCore JS engine was added two new properties - MemoryLimit and DisableFatalOnOOM (default false)
1 parent bc5cd32 commit faeb5f0

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

NuGet/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ This package does not contain the native implementations of ChakraCore. Therefor
2222
<summary>JavaScriptEngineSwitcher.ChakraCore contains adapter `ChakraCoreJsEngine` (wrapper for the ChakraCore).</summary>
2323
<releaseNotes>1. ChakraCore was updated to version 1.8.1;
2424
2. JavaScriptEngineSwitcher.ChakraCore.Native.debian-x64 package has been replaced by the JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 package;
25-
3. Prevented an occurrence of the “Host may not have set any promise continuation callback. Promises may not be executed.” error.</releaseNotes>
25+
3. Prevented an occurrence of the “Host may not have set any promise continuation callback. Promises may not be executed.” error;
26+
4. In configuration settings of the ChakraCore JS engine was added two new properties - `MemoryLimit` and `DisableFatalOnOOM` (default `false`).</releaseNotes>
2627
<copyright>Copyright (c) 2013-2018 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2728
<language>en-US</language>
2829
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript ChakraCore</tags>

NuGet/JavaScriptEngineSwitcher.ChakraCore/readme.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
2. JavaScriptEngineSwitcher.ChakraCore.Native.debian-x64 package has been
3535
replaced by the JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 package;
3636
3. Prevented an occurrence of the “Host may not have set any promise
37-
continuation callback. Promises may not be executed.” error.
37+
continuation callback. Promises may not be executed.” error;
38+
4. In configuration settings of the ChakraCore JS engine was added two new
39+
properties - `MemoryLimit` and `DisableFatalOnOOM` (default `false`).
3840

3941
=============
4042
DOCUMENTATION

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreJsEngine.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,17 @@ public ChakraCoreJsEngine(ChakraCoreSettings settings)
136136
{
137137
attributes |= JsRuntimeAttributes.DisableBackgroundWork;
138138
}
139+
if (chakraCoreSettings.DisableEval)
140+
{
141+
attributes |= JsRuntimeAttributes.DisableEval;
142+
}
139143
if (chakraCoreSettings.DisableNativeCodeGeneration)
140144
{
141145
attributes |= JsRuntimeAttributes.DisableNativeCodeGeneration;
142146
}
143-
if (chakraCoreSettings.DisableEval)
147+
if (chakraCoreSettings.DisableFatalOnOOM)
144148
{
145-
attributes |= JsRuntimeAttributes.DisableEval;
149+
attributes |= JsRuntimeAttributes.DisableFatalOnOOM;
146150
}
147151
if (chakraCoreSettings.EnableExperimentalFeatures)
148152
{
@@ -157,6 +161,8 @@ public ChakraCoreJsEngine(ChakraCoreSettings settings)
157161
try
158162
{
159163
_jsRuntime = JsRuntime.Create(attributes, null);
164+
_jsRuntime.MemoryLimit = settings.MemoryLimit;
165+
160166
_jsContext = _jsRuntime.CreateContext();
161167
_jsContext.AddRef();
162168
}

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreSettings.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
namespace JavaScriptEngineSwitcher.ChakraCore
1+
using System;
2+
3+
using JavaScriptEngineSwitcher.Core.Utilities;
4+
5+
namespace JavaScriptEngineSwitcher.ChakraCore
26
{
37
/// <summary>
48
/// Settings of the ChakraCore JS engine
@@ -15,6 +19,15 @@ public bool DisableBackgroundWork
1519
set;
1620
}
1721

22+
/// <summary>
23+
/// Gets or sets a flag for whether to disable calls of <code>eval</code> function
24+
/// </summary>
25+
public bool DisableEval
26+
{
27+
get;
28+
set;
29+
}
30+
1831
/// <summary>
1932
/// Gets or sets a flag for whether to disable native code generation
2033
/// </summary>
@@ -25,9 +38,9 @@ public bool DisableNativeCodeGeneration
2538
}
2639

2740
/// <summary>
28-
/// Gets or sets a flag for whether to disable calls of <code>eval</code> function
41+
/// Gets or sets a flag for whether to disable Failfast fatal error on OOM
2942
/// </summary>
30-
public bool DisableEval
43+
public bool DisableFatalOnOOM
3144
{
3245
get;
3346
set;
@@ -42,16 +55,28 @@ public bool EnableExperimentalFeatures
4255
set;
4356
}
4457

58+
/// <summary>
59+
/// Gets or sets a current memory limit for a runtime in bytes
60+
/// </summary>
61+
public UIntPtr MemoryLimit
62+
{
63+
get;
64+
set;
65+
}
66+
4567

4668
/// <summary>
47-
/// Constructs instance of the ChakraCore settings
69+
/// Constructs an instance of the ChakraCore settings
4870
/// </summary>
4971
public ChakraCoreSettings()
5072
{
5173
DisableBackgroundWork = false;
52-
DisableNativeCodeGeneration = false;
5374
DisableEval = false;
75+
DisableNativeCodeGeneration = false;
76+
DisableFatalOnOOM = false;
5477
EnableExperimentalFeatures = false;
78+
MemoryLimit = Utils.Is64BitProcess() ?
79+
new UIntPtr(ulong.MaxValue) : new UIntPtr(uint.MaxValue);
5580
}
5681
}
5782
}

0 commit comments

Comments
 (0)