-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathJintSettings.cs
More file actions
202 lines (182 loc) · 4.56 KB
/
JintSettings.cs
File metadata and controls
202 lines (182 loc) · 4.56 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System;
using OriginalDebuggerEventHandler = Jint.Runtime.Debugger.DebugHandler.DebugEventHandler;
namespace JavaScriptEngineSwitcher.Jint
{
/// <summary>
/// Settings of the Jint JS engine
/// </summary>
public sealed class JintSettings
{
/// <summary>
/// Gets or sets a flag for whether to allow the usage of reflection API in the script code
/// </summary>
/// <remarks>
/// This affects <see cref="Object.GetType"/>, <c>Exception.GetType</c>,
/// <c>Exception.TargetSite</c> and <c>Delegate.Method</c>.
/// </remarks>
public bool AllowReflection
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to allow the <c>debugger</c> statement
/// to be called in a script
/// </summary>
[Obsolete("Use a `DebuggerStatementHandlingMode` property")]
public bool AllowDebuggerStatement
{
get { return DebuggerStatementHandlingMode == JsDebuggerStatementHandlingMode.Clr; }
set { DebuggerStatementHandlingMode = value ? JsDebuggerStatementHandlingMode.Clr : JsDebuggerStatementHandlingMode.Ignore; }
}
/// <summary>
/// Gets or sets a debugger break callback
/// </summary>
public OriginalDebuggerEventHandler DebuggerBreakCallback
{
get;
set;
}
/// <summary>
/// Gets or sets a handling mode for script <c>debugger</c> statements
/// </summary>
public JsDebuggerStatementHandlingMode DebuggerStatementHandlingMode
{
get;
set;
}
/// <summary>
/// Gets or sets a debugger step callback
/// </summary>
public OriginalDebuggerEventHandler DebuggerStepCallback
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to disable calls of <c>eval</c> function with custom code
/// and <c>Function</c> constructors taking function code as string
/// </summary>
public bool DisableEval
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to enable debug mode
/// </summary>
public bool EnableDebugging
{
get;
set;
}
/// <summary>
/// Gets or sets a local time zone for the <c>Date</c> objects in the script
/// </summary>
public TimeZoneInfo LocalTimeZone
{
get;
set;
}
/// <summary>
/// Gets or sets a maximum size for JavaScript array
/// </summary>
public uint MaxArraySize
{
get;
set;
}
/// <summary>
/// Gets or sets a maximum depth allowed when parsing JSON data using the <c>JSON.parse</c> static method
/// </summary>
public int MaxJsonParseDepth
{
get;
set;
}
/// <summary>
/// Gets or sets a maximum allowed depth of recursion:
/// <c>-1</c> - recursion without limits;
/// <c>N</c> - one scope function can be called no more than <c>N</c> times.
/// </summary>
public int MaxRecursionDepth
{
get;
set;
}
/// <summary>
/// Gets or sets a maximum number of statements
/// </summary>
public int MaxStatements
{
get;
set;
}
/// <summary>
/// Gets or sets a current memory limit for a engine in bytes
/// </summary>
public long MemoryLimit
{
get;
set;
}
/// <summary>
/// Gets or sets a timeout interval for regular expressions
/// </summary>
/// <remarks>
/// If the value of this property is <c>null</c>, then the value of regular expression
/// timeout interval are taken from the <see cref="TimeoutInterval"/> property.
/// </remarks>
public TimeSpan? RegexTimeoutInterval
{
get;
set;
}
/// <summary>
/// Gets or sets a flag for whether to allow run the script in strict mode
/// </summary>
public bool StrictMode
{
get;
set;
}
/// <summary>
/// Gets or sets a number of milliseconds to wait before the script execution times out
/// </summary>
[Obsolete("Use a `TimeoutInterval` property")]
public int Timeout
{
get { return TimeoutInterval.Milliseconds; }
set { TimeoutInterval = TimeSpan.FromMilliseconds(value); }
}
/// <summary>
/// Gets or sets a interval to wait before the script execution times out
/// </summary>
public TimeSpan TimeoutInterval
{
get;
set;
}
/// <summary>
/// Constructs an instance of the Jint settings
/// </summary>
public JintSettings()
{
AllowReflection = false;
DebuggerBreakCallback = null;
DebuggerStatementHandlingMode = JsDebuggerStatementHandlingMode.Ignore;
DebuggerStepCallback = null;
DisableEval = false;
EnableDebugging = false;
LocalTimeZone = TimeZoneInfo.Local;
MaxArraySize = uint.MaxValue;
MaxJsonParseDepth = 64;
MaxRecursionDepth = -1;
MaxStatements = 0;
MemoryLimit = 0;
RegexTimeoutInterval = null;
StrictMode = false;
TimeoutInterval = TimeSpan.Zero;
}
}
}