Skip to content

Commit 76d63c1

Browse files
committed
Updated per ClearScript to obsolete an obsoleted property and updated XML documentation in a few places to make more descriptive.
1 parent 7f54e0e commit 76d63c1

8 files changed

Lines changed: 200 additions & 13 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Along those lines, ClearScript.Manager does the following to make certain things
3030
- Allow easy management of the memory usage of each instance of the V8 Runtime and sets the limits to a much lower threshold than the default V8 settings.
3131

3232
## Configuration Parameters
33+
These settings can be set manually or added to the AppSettings of your application config file.
3334

3435
//V8 Max Executable Size in bytes:
3536
int MaxExecutableBytes { get; }
@@ -42,13 +43,13 @@ Along those lines, ClearScript.Manager does the following to make certain things
4243
4344
//Default script timeout in ms:
4445
int ScriptTimeoutMilliSeconds { get; }
46+
47+
//Max number of simultaneous V8 Runtimes:
48+
int RuntimeMaxCount { get; }
49+
50+
//Per Runtime, the maximum number of cached scripts:
51+
int ScriptCacheMaxCount { get; }
4552

46-
//Max number of simultaneous V8 Runtimes:
47-
int RuntimeMaxCount { get; }
48-
49-
//Per Runtime, the maximum number of cached scripts:
50-
int ScriptCacheMaxCount { get; }
51-
5253
//The default script cache expiration in seconds:
5354
int ScriptCacheExpirationSeconds { get; }
5455

src/ClearScript.Manager.Test/WhenExecutingBasicJavaScript.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.ClearScript;
22
using NUnit.Framework;
3+
using Should;
34

45
namespace ClearScript.Manager.Test
56
{

src/ClearScript.Manager/HostObject.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
namespace ClearScript.Manager
44
{
5+
/// <summary>
6+
/// A specific object instance to inject into the javascript to execute.
7+
/// </summary>
58
public class HostObject
69
{
10+
/// <summary>
11+
/// Name of the object used to access the object in the JavaScript.
12+
/// </summary>
713
public string Name { get; set; }
814

15+
/// <summary>
16+
/// HostItemFlags to apply to the HostType. Limits the scope of the type and which type members are available.
17+
/// See ClearScript documentation for more information.
18+
/// </summary>
919
public HostItemFlags Flags { get; set; }
1020

21+
/// <summary>
22+
/// The target object to inject into the JavaScript.
23+
/// </summary>
1124
public object Target { get; set; }
1225
}
1326
}

src/ClearScript.Manager/HostType.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,32 @@
33

44
namespace ClearScript.Manager
55
{
6+
/// <summary>
7+
/// A type to make available in JavaScript.
8+
/// </summary>
69
public class HostType
710
{
11+
/// <summary>
12+
/// Name of the type that is used to reference the type within the JavaScript.
13+
/// </summary>
814
public string Name { get; set; }
915

16+
/// <summary>
17+
/// HostItemFlags to apply to the HostType. Limits the scope of the type and which type members are available.
18+
/// See ClearScript documentation for more information.
19+
/// </summary>
1020
public HostItemFlags Flags { get; set; }
1121

22+
/// <summary>
23+
/// Host type collections provide convenient scriptable access to all the types defined in one or more host assemblies.
24+
/// They are hierarchical collections where leaf nodes represent types and parent nodes represent namespaces.
25+
/// See ClearScript documentation for more information.
26+
/// </summary>
1227
public HostTypeCollection HostTypeCollection { get; set; }
1328

29+
/// <summary>
30+
/// An individual type to make available to the script.
31+
/// </summary>
1432
public Type Type { get; set; }
1533
}
1634
}

src/ClearScript.Manager/ManagerPool.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,48 @@
33

44
namespace ClearScript.Manager
55
{
6+
/// <summary>
7+
/// Defines a pool from which Runtime Managers are requested.
8+
/// </summary>
69
public interface IManagerPool
710
{
11+
/// <summary>
12+
/// Gets a runtime from the pool. Blocks until a manager becomes available.
13+
/// </summary>
14+
/// <returns>The next available IRuntimeManager.</returns>
815
IRuntimeManager GetRuntime();
16+
17+
/// <summary>
18+
/// Returns a Runtime Manager to the pool.
19+
/// </summary>
20+
/// <param name="runtimeManager">The Runtime Manager to return to the pool.</param>
921
void ReturnToPool(IRuntimeManager runtimeManager);
1022
}
1123

24+
/// <summary>
25+
/// Defines a pool from which Runtime Managers are requested.
26+
/// </summary>
1227
public class ManagerPool : IManagerPool
1328
{
29+
/// <summary>
30+
/// Static reference to the current pool of Runtime Managers.
31+
/// </summary>
1432
public static IManagerPool CurrentPool;
1533

1634
private readonly object _addLock = new object();
35+
36+
/// <summary>
37+
/// Current count of Runtimes within the pool.
38+
/// </summary>
1739
public int RuntimeCurrentCount = 0;
1840

1941
private readonly BlockingCollection<IRuntimeManager> _availableRuntimes = new BlockingCollection<IRuntimeManager>();
2042
private readonly IManagerSettings _settings;
2143

44+
/// <summary>
45+
/// Creates a new Runtime Manager Pool.
46+
/// </summary>
47+
/// <param name="settings">Settings to apply to the Runtime Manager.</param>
2248
public ManagerPool(IManagerSettings settings)
2349
{
2450
if(settings == null)
@@ -27,6 +53,10 @@ public ManagerPool(IManagerSettings settings)
2753
_settings = settings;
2854
}
2955

56+
/// <summary>
57+
/// Initializes the CurrentPool with the provided settings.
58+
/// </summary>
59+
/// <param name="settings">Settings to apply.</param>
3060
public static void InitializeCurrentPool(IManagerSettings settings)
3161
{
3262
CurrentPool = new ManagerPool(settings);

src/ClearScript.Manager/ManagerScope.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22

33
namespace ClearScript.Manager
44
{
5+
/// <summary>
6+
/// Scope in which a Runtime Manager is requested from the pool and returned upon completion.
7+
/// </summary>
58
public class ManagerScope : IDisposable
69
{
710
private bool _disposed;
811

12+
/// <summary>
13+
/// Creates a new ManagerScope and requests a RuntimeManager.
14+
/// </summary>
915
public ManagerScope()
1016
{
1117
RuntimeManager = ManagerPool.CurrentPool.GetRuntime();
1218
}
1319

20+
/// <summary>
21+
/// Allows access to the allocated Runtime Manager from within this scope.
22+
/// </summary>
1423
public IRuntimeManager RuntimeManager { get; private set; }
1524

25+
/// <summary>
26+
/// Disposed the object and returns the Runtime Manager to the pool.
27+
/// </summary>
1628
public void Dispose()
1729
{
1830
if (!_disposed)

src/ClearScript.Manager/ManagerSettings.cs

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
using System.Configuration;
1+
using System;
2+
using System.Configuration;
23

34
namespace ClearScript.Manager
45
{
6+
/// <summary>
7+
/// Settings to apply to the RuntimeManager and to created runtimes.
8+
/// </summary>
59
public interface IManagerSettings
610
{
711
/// <summary>
812
/// V8 Max Executable Size in bytes.
913
/// </summary>
1014
int MaxExecutableBytes { get; }
1115

16+
/// <summary>
17+
/// V8 Max New Space in bytes.
18+
/// </summary>
19+
int MaxNewSpaceBytes { get; }
20+
1221
/// <summary>
1322
/// V8 Max Young Space in bytes.
1423
/// </summary>
24+
[Obsolete("Use MaxNewSpaceBytes instead.")]
1525
int MaxYoungSpaceBytes { get; }
1626

1727
/// <summary>
@@ -40,24 +50,57 @@ public interface IManagerSettings
4050
int ScriptCacheExpirationSeconds { get; }
4151
}
4252

53+
/// <summary>
54+
/// Settings to apply to the RuntimeManager and to created runtimes.
55+
/// </summary>
4356
public class ManagerSettings : IManagerSettings
4457
{
58+
/// <summary>
59+
/// Default MaxExecutableBytes if not present in settings.
60+
/// </summary>
4561
public const int DefaultMaxExecutableBytes = 8 * 1024 * 1024;
46-
public const int DefaultMaxYoungSpaceBytes = 16 * 1024 * 1024;
62+
/// <summary>
63+
/// Default MaxNewSpaceBytes if not present in settings.
64+
/// </summary>
65+
public const int DefaultMaxNewSpaceBytes = 16 * 1024 * 1024;
66+
/// <summary>
67+
/// Default tMaxOldSpaceBytes if not present in settings.
68+
/// </summary>
4769
public const int DefaultMaxOldSpaceBytes = 16 * 1024 * 1024;
70+
/// <summary>
71+
/// Default ScriptTimeoutMilliSeconds if not present in settings.
72+
/// </summary>
4873
public const int DefaultScriptTimeoutMilliSeconds = 60000;
74+
/// <summary>
75+
/// Default RuntimeMaxCount if not present in settings.
76+
/// </summary>
4977
public const int DefaultRuntimeMaxCount = 8;
78+
/// <summary>
79+
/// Default ScriptCacheMaxCount if not present in settings.
80+
/// </summary>
5081
public const int DefaultScriptCacheMaxCount = 1000;
82+
/// <summary>
83+
/// Default ScriptCacheExpirationSeconds if not present in settings.
84+
/// </summary>
5185
public const int DefaultScriptCacheExpirationSeconds = 600;
5286

5387
public int MaxExecutableBytes
5488
{
5589
get { return SettingToInt("MaxExecutableBytes", DefaultMaxExecutableBytes); }
5690
}
5791

92+
public int MaxNewSpaceBytes
93+
{
94+
get
95+
{
96+
return SettingToInt("MaxNewSpaceBytes", SettingToInt("MaxYoungSpaceBytes", DefaultMaxNewSpaceBytes));
97+
}
98+
}
99+
100+
[Obsolete("Use MaxNewSpaceBytes instead.")]
58101
public int MaxYoungSpaceBytes
59102
{
60-
get { return SettingToInt("MaxYoungSpaceBytes", DefaultMaxYoungSpaceBytes); }
103+
get { return MaxNewSpaceBytes; }
61104
}
62105

63106
public int MaxOldSpaceBytes
@@ -86,6 +129,12 @@ public int ScriptCacheExpirationSeconds
86129
}
87130

88131

132+
/// <summary>
133+
/// Parses the setting and converts it to an int or sets the default value if the setting is not present.
134+
/// </summary>
135+
/// <param name="settingName">Name of the setting to check.</param>
136+
/// <param name="defaultValue">Default value if setting is not present.</param>
137+
/// <returns>Setting or default value.</returns>
89138
public static int SettingToInt(string settingName, int defaultValue)
90139
{
91140
int? setting = null;
@@ -107,11 +156,14 @@ public static int SettingToInt(string settingName, int defaultValue)
107156
/// </summary>
108157
public class ManualManagerSettings : IManagerSettings
109158
{
159+
/// <summary>
160+
/// Creates a ManualManagerSettings.
161+
/// </summary>
110162
public ManualManagerSettings()
111163
{
112164
MaxExecutableBytes = ManagerSettings.DefaultMaxExecutableBytes;
113-
MaxYoungSpaceBytes = ManagerSettings.DefaultMaxOldSpaceBytes;
114-
MaxOldSpaceBytes = ManagerSettings.DefaultMaxYoungSpaceBytes;
165+
MaxNewSpaceBytes = ManagerSettings.DefaultMaxOldSpaceBytes;
166+
MaxOldSpaceBytes = ManagerSettings.DefaultMaxNewSpaceBytes;
115167
ScriptTimeoutMilliSeconds = ManagerSettings.DefaultScriptTimeoutMilliSeconds;
116168
RuntimeMaxCount = ManagerSettings.DefaultRuntimeMaxCount;
117169
ScriptCacheMaxCount = ManagerSettings.DefaultScriptCacheMaxCount;
@@ -120,7 +172,14 @@ public ManualManagerSettings()
120172

121173
public int MaxExecutableBytes { get; set; }
122174

123-
public int MaxYoungSpaceBytes { get; set; }
175+
public int MaxNewSpaceBytes { get; set; }
176+
177+
[Obsolete("Use MaxNewSpaceBytes instead.")]
178+
public int MaxYoungSpaceBytes
179+
{
180+
get { return MaxNewSpaceBytes; }
181+
set { MaxNewSpaceBytes = value; }
182+
}
124183

125184
public int MaxOldSpaceBytes { get; set; }
126185

0 commit comments

Comments
 (0)