Skip to content

Commit 6f26ae9

Browse files
committed
Add option to blacklist MSIE engine.
1 parent 5b5a512 commit 6f26ae9

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/React.Core/IReactSiteConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,15 @@ public interface IReactSiteConfiguration
9999
/// Defaults to <c>25</c>.
100100
/// </summary>
101101
IReactSiteConfiguration SetMaxEngines(int? maxEngines);
102+
103+
/// <summary>
104+
/// Gets or sets whether the MSIE engine should be used if V8 is unavailable.
105+
/// </summary>
106+
bool AllowMsieEngine { get; set; }
107+
/// <summary>
108+
/// Sets whether the MSIE engine should be used if V8 is unavailable.
109+
/// </summary>
110+
/// <returns></returns>
111+
IReactSiteConfiguration SetAllowMsieEngine(bool allowMsieEngine);
102112
}
103113
}

src/React.Core/JavaScriptEngineFactory.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Threading;
88
using JavaScriptEngineSwitcher.Core;
9+
using JavaScriptEngineSwitcher.Msie;
910
using JavaScriptEngineSwitcher.V8;
1011
using JSPool;
1112
using React.Exceptions;
@@ -72,7 +73,7 @@ IFileSystem fileSystem
7273
{
7374
_config = config;
7475
_fileSystem = fileSystem;
75-
_factory = GetFactory(availableFactories);
76+
_factory = GetFactory(availableFactories, config.AllowMsieEngine);
7677
if (_config.ReuseJavaScriptEngines)
7778
{
7879
_pool = CreatePool();
@@ -197,7 +198,7 @@ public virtual void ReturnEngineToPool(IJsEngine engine)
197198
/// The first functioning JavaScript engine with the lowest priority will be used.
198199
/// </summary>
199200
/// <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)
201202
{
202203
var availableEngineFactories = availableFactories
203204
.OrderBy(x => x.Priority)
@@ -208,8 +209,7 @@ private static Func<IJsEngine> GetFactory(IEnumerable<Registration> availableFac
208209
try
209210
{
210211
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))
213213
{
214214
// Success! Use this one.
215215
return engineFactory;
@@ -246,6 +246,20 @@ private static Func<IJsEngine> GetFactory(IEnumerable<Registration> availableFac
246246
throw new ReactEngineNotFoundException();
247247
}
248248

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+
249263
/// <summary>
250264
/// Clean up all engines
251265
/// </summary>

src/React.Core/ReactSiteConfiguration.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public ReactSiteConfiguration()
3535
{
3636
UseHarmony = true;
3737
ReuseJavaScriptEngines = true;
38+
AllowMsieEngine = true;
3839
}
3940

4041
/// <summary>
@@ -154,5 +155,20 @@ public IReactSiteConfiguration SetMaxEngines(int? maxEngines)
154155
MaxEngines = maxEngines;
155156
return this;
156157
}
158+
159+
/// <summary>
160+
/// Gets or sets whether the MSIE engine should be used if V8 is unavailable.
161+
/// </summary>
162+
public bool AllowMsieEngine { get; set; }
163+
164+
/// <summary>
165+
/// Sets whether the MSIE engine should be used if V8 is unavailable.
166+
/// </summary>
167+
/// <returns></returns>
168+
public IReactSiteConfiguration SetAllowMsieEngine(bool allowMsieEngine)
169+
{
170+
AllowMsieEngine = allowMsieEngine;
171+
return this;
172+
}
157173
}
158174
}

0 commit comments

Comments
 (0)