Skip to content

Commit 9ad5881

Browse files
committed
In configuration settings of the V8 JS engine was added two new properties: AddPerformanceObject (default false) and SetTimerResolution (default false)
1 parent 2257a59 commit 9ad5881

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

src/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<PackageIconFullPath>../../Icons/JavaScriptEngineSwitcher_V8_Logo128x128.png</PackageIconFullPath>
2222
<Description>JavaScriptEngineSwitcher.V8 contains a `V8JsEngine` adapter (wrapper for the Microsoft ClearScript.V8).</Description>
2323
<PackageTags>$(PackageCommonTags);V8;ClearScript</PackageTags>
24-
<PackageReleaseNotes>Microsoft ClearScript.V8 was updated to version 7.4.5.</PackageReleaseNotes>
24+
<PackageReleaseNotes>1. Microsoft ClearScript.V8 was updated to version 7.4.5;
25+
2. In configuration settings of the V8 JS engine was added two new properties: `AddPerformanceObject` (default `false`) and `SetTimerResolution` (default `false`).</PackageReleaseNotes>
2526
</PropertyGroup>
2627

2728
<ItemGroup>

src/JavaScriptEngineSwitcher.V8/V8JsEngine.cs

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public V8JsEngine(V8Settings settings)
107107
};
108108

109109
OriginalEngineFlags flags = OriginalEngineFlags.None;
110+
if (v8Settings.AddPerformanceObject)
111+
{
112+
flags |= OriginalEngineFlags.AddPerformanceObject;
113+
}
110114
if (v8Settings.AwaitDebuggerAndPauseOnStart)
111115
{
112116
flags |= OriginalEngineFlags.AwaitDebuggerAndPauseOnStart;
@@ -123,6 +127,10 @@ public V8JsEngine(V8Settings settings)
123127
{
124128
flags |= OriginalEngineFlags.DisableGlobalMembers;
125129
}
130+
if (v8Settings.SetTimerResolution)
131+
{
132+
flags |= OriginalEngineFlags.SetTimerResolution;
133+
}
126134

127135
int debugPort = v8Settings.DebugPort;
128136

src/JavaScriptEngineSwitcher.V8/V8Settings.cs

+31
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ namespace JavaScriptEngineSwitcher.V8
77
/// </summary>
88
public sealed class V8Settings
99
{
10+
/// <summary>
11+
/// Gets or sets a flag for whether to add the
12+
/// <c><see href="https://microsoft.github.io/ClearScript/2024/03/21/performance-api.html">Performance</see></c>
13+
/// object to the script engine's global namespace
14+
/// </summary>
15+
/// <remarks>
16+
/// This object provides a set of low-level native facilities for performance-sensitive scripts.
17+
/// </remarks>
18+
public bool AddPerformanceObject
19+
{
20+
get;
21+
set;
22+
}
23+
1024
/// <summary>
1125
/// Gets or sets a flag for whether to allow the usage of reflection API in the script code
1226
/// </summary>
@@ -217,12 +231,28 @@ public UIntPtr MaxStackUsage
217231
set;
218232
}
219233

234+
/// <summary>
235+
/// Gets or sets a flag for whether to set native timers to the highest available resolution
236+
/// while the current script engine's instance is active
237+
/// </summary>
238+
/// <remarks>
239+
/// This property is ignored if <c><see cref="AddPerformanceObject"/></c> property is <c>false</c>.
240+
/// It is only a hint and may be ignored on some systems. On platforms that support it, this
241+
/// property can degrade overall system performance or power efficiency, so caution is recommended.
242+
/// </remarks>
243+
public bool SetTimerResolution
244+
{
245+
get;
246+
set;
247+
}
248+
220249

221250
/// <summary>
222251
/// Constructs an instance of the V8 settings
223252
/// </summary>
224253
public V8Settings()
225254
{
255+
AddPerformanceObject = false;
226256
AllowReflection = false;
227257
AwaitDebuggerAndPauseOnStart = false;
228258
DebugPort = 9222;
@@ -237,6 +267,7 @@ public V8Settings()
237267
MaxNewSpaceSize = 0;
238268
MaxOldSpaceSize = 0;
239269
MaxStackUsage = UIntPtr.Zero;
270+
SetTimerResolution = false;
240271
}
241272
}
242273
}

src/JavaScriptEngineSwitcher.V8/readme.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
=============
3232
RELEASE NOTES
3333
=============
34-
Microsoft ClearScript.V8 was updated to version 7.4.5.
34+
1. Microsoft ClearScript.V8 was updated to version 7.4.5;
35+
2. In configuration settings of the V8 JS engine was added two new properties:
36+
`AddPerformanceObject` (default `false`) and `SetTimerResolution` (default
37+
`false`).
3538

3639
=============
3740
DOCUMENTATION

0 commit comments

Comments
 (0)