forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChakraCoreSettings.cs
More file actions
152 lines (135 loc) · 3.46 KB
/
ChakraCoreSettings.cs
File metadata and controls
152 lines (135 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using JavaScriptEngineSwitcher.Core.Utilities;
using JavaScriptEngineSwitcher.ChakraCore.Resources;
namespace JavaScriptEngineSwitcher.ChakraCore
{
/// <summary>
/// Settings of the ChakraCore JS engine
/// </summary>
public sealed class ChakraCoreSettings
{
#if !NETSTANDARD1_3
/// <summary>
/// The stack size is sufficient to run the code of modern JavaScript libraries in 32-bit process
/// </summary>
const int STACK_SIZE_32 = 492 * 1024; // like 32-bit Node.js
/// <summary>
/// The stack size is sufficient to run the code of modern JavaScript libraries in 64-bit process
/// </summary>
const int STACK_SIZE_64 = 984 * 1024; // like 64-bit Node.js
/// <summary>
/// The maximum stack size in bytes
/// </summary>
private int _maxStackSize;
#endif
/// <summary>
/// Gets or sets a flag for whether to disable any background work (such as garbage collection)
/// on background threads
/// </summary>
public bool DisableBackgroundWork
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to disable calls of <code>eval</code> function
/// </summary>
public bool DisableEval
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to disable executable page allocation
/// </summary>
/// <remarks>
/// <para>
/// This also implies that Native Code generation will be turned off.
/// </para>
/// <para>
/// 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.
/// </para>
/// </remarks>
public bool DisableExecutablePageAllocation
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to disable Failfast fatal error on OOM
/// </summary>
public bool DisableFatalOnOOM
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to disable native code generation
/// </summary>
public bool DisableNativeCodeGeneration
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to enable all experimental features
/// </summary>
public bool EnableExperimentalFeatures
{
get;
set;
}
#if !NETSTANDARD1_3
/// <summary>
/// Gets or sets a maximum stack size in bytes
/// </summary>
/// <remarks>
/// <para>Set a <code>0</code> to use the default maximum stack size specified in the header
/// for the executable.
/// </para>
/// </remarks>
public int MaxStackSize
{
get { return _maxStackSize; }
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(
nameof(value),
Strings.Engine_MaxStackSizeMustBeNonNegative
);
}
_maxStackSize = value;
}
}
#endif
/// <summary>
/// Gets or sets a current memory limit for a runtime in bytes
/// </summary>
public UIntPtr MemoryLimit
{
get;
set;
}
/// <summary>
/// Constructs an instance of the ChakraCore settings
/// </summary>
public ChakraCoreSettings()
{
bool is64BitProcess = Utils.Is64BitProcess();
DisableBackgroundWork = false;
DisableEval = false;
DisableExecutablePageAllocation = false;
DisableFatalOnOOM = true;
DisableNativeCodeGeneration = false;
EnableExperimentalFeatures = false;
#if !NETSTANDARD1_3
MaxStackSize = is64BitProcess ? STACK_SIZE_64 : STACK_SIZE_32;
#endif
MemoryLimit = is64BitProcess ? new UIntPtr(ulong.MaxValue) : new UIntPtr(uint.MaxValue);
}
}
}