-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathV8ScriptEngineFlags.cs
More file actions
179 lines (156 loc) · 9.19 KB
/
V8ScriptEngineFlags.cs
File metadata and controls
179 lines (156 loc) · 9.19 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Threading.Tasks;
namespace Microsoft.ClearScript.V8
{
/// <summary>
/// Defines options for initializing a new V8 JavaScript engine instance.
/// </summary>
[Flags]
public enum V8ScriptEngineFlags
{
// IMPORTANT: maintain bitwise equivalence with unmanaged enum V8Context::Flags
/// <summary>
/// Specifies that no options are selected.
/// </summary>
None = 0,
/// <summary>
/// Specifies that script debugging features are to be enabled.
/// </summary>
EnableDebugging = 0x00000001,
/// <summary>
/// Specifies that support for <c><see cref="HostItemFlags.GlobalMembers"/></c> behavior is to be
/// disabled. This option yields a significant performance benefit for global item access.
/// </summary>
DisableGlobalMembers = 0x00000002,
/// <summary>
/// Specifies that remote script debugging is to be enabled. This option is ignored if
/// <c><see cref="EnableDebugging"/></c> is not specified.
/// </summary>
EnableRemoteDebugging = 0x00000004,
/// <summary>
/// Specifies that the script engine is to wait for a debugger connection and schedule a
/// pause before executing the first line of application script code. This option is
/// ignored if <c><see cref="EnableDebugging"/></c> is not specified.
/// </summary>
AwaitDebuggerAndPauseOnStart = 0x00000008,
/// <summary>
/// Specifies that the script engine is to perform automatic conversion between
/// .NET <c><see cref="DateTime"/></c> objects and JavaScript
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date</see></c>
/// objects. This conversion is bidirectional and lossy. A <c>DateTime</c> object
/// constructed from a JavaScript <c>Date</c> object always represents a Coordinated
/// Universal Time (UTC) and has its <c><see cref="DateTime.Kind"/></c> property set to
/// <c><see cref="DateTimeKind.Utc"/></c>.
/// </summary>
EnableDateTimeConversion = 0x00000010,
/// <summary>
/// Specifies that
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import">dynamic module imports</see>
/// are to be enabled. This is an experimental feature and may be removed in a future release.
/// </summary>
EnableDynamicModuleImports = 0x00000020,
/// <summary>
/// Specifies that 64-bit integers with values greater than
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER">Number.MAX_SAFE_INTEGER</see></c>
/// or less than
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER">Number.MIN_SAFE_INTEGER</see></c>
/// are to be marshaled as
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt">BigInt</see></c>.
/// This option is ignored if <c><see cref="MarshalAllInt64AsBigInt"/></c> is specified.
/// </summary>
MarshalUnsafeInt64AsBigInt = 0x00000040,
/// <summary>
/// Equivalent to <c><see cref="MarshalUnsafeInt64AsBigInt"/></c>.
/// </summary>
[Obsolete("This option has been renamed to MarshalUnsafeInt64AsBigInt.")]
MarshalUnsafeLongAsBigInt = MarshalUnsafeInt64AsBigInt,
/// <summary>
/// Specifies that all 64-bit integers are to be marshaled as
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt">BigInt</see></c>.
/// </summary>
MarshalAllInt64AsBigInt = 0x00000080,
/// <summary>
/// Equivalent to <c><see cref="MarshalAllInt64AsBigInt"/></c>.
/// </summary>
[Obsolete("This option has been renamed to MarshalAllInt64AsBigInt.")]
MarshalAllLongAsBigInt = MarshalAllInt64AsBigInt,
/// <summary>
/// Specifies that the script engine is to perform automatic conversion between
/// .NET <c><see cref="Task"/></c> objects and JavaScript
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promises</see>.
/// This conversion is bidirectional and lossy. A <c>Task</c> object constructed from a
/// JavaScript promise always has a result type of <c><see cref="object"/></c>.
/// </summary>
EnableTaskPromiseConversion = 0x00000100,
/// <summary>
/// Specifies that the script engine is to perform automatic conversion from
/// .NET
/// <c><see href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask">ValueTask</see></c> and
/// <c><see href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask-1">ValueTask<TResult></see></c>
/// structures to JavaScript
/// <see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promises</see>.
/// This conversion is unidirectional and lossy. This option is ignored if
/// <c><see cref="EnableTaskPromiseConversion"/></c> is not specified.
/// </summary>
EnableValueTaskPromiseConversion = 0x00000200,
/// <summary>
/// Specifies that access to host object and class members is to be case-insensitive. This
/// option can introduce ambiguity if the host resource has distinct members whose names
/// differ only in case, so it should be used with caution.
/// </summary>
UseCaseInsensitiveMemberBinding = 0x00000400,
/// <summary>
/// Specifies that
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify">JSON.stringify</see></c>
/// enhancements are to be enabled. These enhancements add support for host objects via the
/// <see href="https://www.newtonsoft.com/json">Json.NET</see> library.
/// </summary>
EnableStringifyEnhancements = 0x00000800,
/// <summary>
/// Specifies that host exceptions are to be hidden from script code. If an exception
/// thrown by the host reaches the script engine, it is caught automatically, and an
/// <c><see href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</see></c>
/// object is thrown in its place. By default, ClearScript makes the managed exception
/// accessible to script code via the <c>Error</c> object's <c>hostException</c> property.
/// This option suppresses that behavior.
/// </summary>
HideHostExceptions = 0x00001000,
/// <summary>
/// Specifies that support for synchronization contexts is to be enabled for task-promise
/// interoperability. This option is ignored if
/// <c><see cref="EnableTaskPromiseConversion"/></c> is not specified.
/// </summary>
UseSynchronizationContexts = 0x00002000,
/// <summary>
/// Specifies that the
/// <c><see href="https://clearscript.clearfoundry.net/2024/03/21/performance-api.html">Performance</see></c>
/// object is to be added to the script engine's global namespace. This object provides a
/// set of low-level native facilities for performance-sensitive scripts.
/// </summary>
AddPerformanceObject = 0x00004000,
/// <summary>
/// Specifies that native timers are to be set to the highest available resolution while
/// the current <c><see cref="V8ScriptEngine"/></c> instance is active. This option is
/// ignored if <c><see cref="AddPerformanceObject"/></c> is not specified. It is only a
/// hint and may be ignored on some systems. On platforms that support it, this option can
/// degrade overall system performance or power efficiency, so caution is recommended.
/// </summary>
SetTimerResolution = 0x00008000,
/// <summary>
/// Specifies that the script engine is to perform automatic conversion between .NET and
/// JavaScript arrays. This conversion is bidirectional and lossy. A .NET array constructed
/// from a JavaScript array always has an element type of <c><see cref="object"/></c>,
/// making it impossible for script code to specify a strongly typed array as a .NET method
/// argument or property value. Excessive copying of array contents can also impact
/// application performance and/or memory consumption. Caution is recommended.
/// </summary>
EnableArrayConversion = 0x00010000
}
internal static class V8ScriptEngineFlagsHelpers
{
public static bool HasAllFlags(this V8ScriptEngineFlags value, V8ScriptEngineFlags flags) => (value & flags) == flags;
public static bool HasAnyFlag(this V8ScriptEngineFlags value, V8ScriptEngineFlags flags) => (value & flags) != 0;
}
}