6
6
using System . Linq ;
7
7
using System . Threading ;
8
8
using JavaScriptEngineSwitcher . Core ;
9
+ using JavaScriptEngineSwitcher . Msie ;
9
10
using JavaScriptEngineSwitcher . V8 ;
10
11
using JSPool ;
11
12
using React . Exceptions ;
@@ -72,7 +73,7 @@ IFileSystem fileSystem
72
73
{
73
74
_config = config ;
74
75
_fileSystem = fileSystem ;
75
- _factory = GetFactory ( availableFactories ) ;
76
+ _factory = GetFactory ( availableFactories , config . AllowMsieEngine ) ;
76
77
if ( _config . ReuseJavaScriptEngines )
77
78
{
78
79
_pool = CreatePool ( ) ;
@@ -197,7 +198,7 @@ public virtual void ReturnEngineToPool(IJsEngine engine)
197
198
/// The first functioning JavaScript engine with the lowest priority will be used.
198
199
/// </summary>
199
200
/// <returns>Function to create JavaScript engine</returns>
200
- private static Func < IJsEngine > GetFactory ( IEnumerable < Registration > availableFactories )
201
+ private static Func < IJsEngine > GetFactory ( IEnumerable < Registration > availableFactories , bool allowMsie )
201
202
{
202
203
var availableEngineFactories = availableFactories
203
204
. OrderBy ( x => x . Priority )
@@ -208,8 +209,7 @@ private static Func<IJsEngine> GetFactory(IEnumerable<Registration> availableFac
208
209
try
209
210
{
210
211
engine = engineFactory ( ) ;
211
- // Perform a sanity test to ensure this engine is usable
212
- if ( engine . Evaluate < int > ( "1 + 1" ) == 2 )
212
+ if ( EngineIsUsable ( engine , allowMsie ) )
213
213
{
214
214
// Success! Use this one.
215
215
return engineFactory ;
@@ -246,6 +246,20 @@ private static Func<IJsEngine> GetFactory(IEnumerable<Registration> availableFac
246
246
throw new ReactEngineNotFoundException ( ) ;
247
247
}
248
248
249
+ /// <summary>
250
+ /// Performs a sanity check to ensure the specified engine type is usable.
251
+ /// </summary>
252
+ /// <param name="engine">Engine to test</param>
253
+ /// <param name="allowMsie">Whether the MSIE engine can be used</param>
254
+ /// <returns></returns>
255
+ private static bool EngineIsUsable ( IJsEngine engine , bool allowMsie )
256
+ {
257
+ // Perform a sanity test to ensure this engine is usable
258
+ var isUsable = engine . Evaluate < int > ( "1 + 1" ) == 2 ;
259
+ var isMsie = engine is MsieJsEngine ;
260
+ return isUsable && ( ! isMsie || allowMsie ) ;
261
+ }
262
+
249
263
/// <summary>
250
264
/// Clean up all engines
251
265
/// </summary>
0 commit comments