11using System ;
22using System . Collections . Generic ;
3+ using System . Runtime . CompilerServices ;
34#if NET45 || NETSTANDARD
45using System . Runtime . ExceptionServices ;
56#endif
6- using System . Runtime . CompilerServices ;
77using System . Threading ;
88
9+ #if NET40
910using MsieJavaScriptEngine . Extensions ;
11+ #endif
1012using MsieJavaScriptEngine . Utilities ;
1113
1214namespace MsieJavaScriptEngine
1315{
1416 /// <summary>
15- /// Provides services for managing the queue of script tasks on the thread with increased stack size
17+ /// Provides services for managing the queue of script tasks on the thread with modified stack size
1618 /// </summary>
1719 internal sealed class ScriptDispatcher : IDisposable
1820 {
19- #if ! NETSTANDARD1_3
2021 /// <summary>
21- /// The stack size is sufficient to run the code of modern JS libraries in 32-bit process
22- /// </summary>
23- const int STACK_SIZE_32 = 492 * 1024 ; // like 32-bit Node.js
24-
25- /// <summary>
26- /// The stack size is sufficient to run the code of modern JS libraries in 64-bit process
27- /// </summary>
28- const int STACK_SIZE_64 = 984 * 1024 ; // like 64-bit Node.js
29-
30- #endif
31- /// <summary>
32- /// The thread with increased stack size
22+ /// The thread with modified stack size
3323 /// </summary>
3424 private Thread _thread ;
3525
@@ -54,17 +44,22 @@ internal sealed class ScriptDispatcher : IDisposable
5444 private InterlockedStatedFlag _disposedFlag = new InterlockedStatedFlag ( ) ;
5545
5646
47+ #if NETSTANDARD1_3
5748 /// <summary>
5849 /// Constructs an instance of script dispatcher
5950 /// </summary>
6051 public ScriptDispatcher ( )
6152 {
62- #if NETSTANDARD1_3
6353 _thread = new Thread ( StartThread )
6454#else
65- int sufficientStackSize = Utils. Is64BitProcess ( ) ? STACK_SIZE_64 : STACK_SIZE_32 ;
66-
67- _thread = new Thread ( StartThread , sufficientStackSize )
55+ /// <summary>
56+ /// Constructs an instance of script dispatcher
57+ /// </summary>
58+ /// <param name="maxStackSize">The maximum stack size, in bytes, to be used by the thread,
59+ /// or 0 to use the default maximum stack size specified in the header for the executable.</param>
60+ public ScriptDispatcher ( int maxStackSize )
61+ {
62+ _thread = new Thread ( StartThread , maxStackSize )
6863#endif
6964 {
7065 IsBackground = true
@@ -83,7 +78,7 @@ private void VerifyNotDisposed()
8378 }
8479
8580 /// <summary>
86- /// Starts a thread with increased stack size.
81+ /// Starts a thread with modified stack size.
8782 /// Loops forever, processing script tasks from the queue.
8883 /// </summary>
8984 private void StartThread ( )
@@ -139,7 +134,7 @@ private void EnqueueTask(ScriptTask task)
139134 }
140135
141136 /// <summary>
142- /// Runs a specified delegate on the thread with increased stack size,
137+ /// Runs a specified delegate on the thread with modified stack size,
143138 /// and returns its result as an <see cref="System.Object"/>.
144139 /// Blocks until the invocation of delegate is completed.
145140 /// </summary>
@@ -174,7 +169,7 @@ private object InnnerInvoke(Func<object> del)
174169 }
175170
176171 /// <summary>
177- /// Runs a specified delegate on the thread with increased stack size,
172+ /// Runs a specified delegate on the thread with modified stack size,
178173 /// and returns its result as an <typeparamref name="T" />.
179174 /// Blocks until the invocation of delegate is completed.
180175 /// </summary>
@@ -195,7 +190,7 @@ public T Invoke<T>(Func<T> func)
195190 }
196191
197192 /// <summary>
198- /// Runs a specified delegate on the thread with increased stack size.
193+ /// Runs a specified delegate on the thread with modified stack size.
199194 /// Blocks until the invocation of delegate is completed.
200195 /// </summary>
201196 /// <param name="action">Delegate to invocation</param>
0 commit comments