Skip to content

Commit 79ca155

Browse files
Taritsyndustinsoftware
authored andcommitted
Added support of the JavaScript Engine Switcher version 3.0.0 Beta and JSPool version 3.1.0 Beta 1 (#551)
1 parent 5cbcd22 commit 79ca155

35 files changed

+216
-274
lines changed

src/React.Core/AssemblyRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Register(TinyIoCContainer container)
3535
// One instance shared for the whole app
3636
container.Register<IReactSiteConfiguration>((c, o) => ReactSiteConfiguration.Configuration);
3737
container.Register<IFileCacheHash, FileCacheHash>().AsPerRequestSingleton();
38-
container.Register<JsEngineSwitcher>((c, o) => JsEngineSwitcher.Instance);
38+
container.Register<IJsEngineSwitcher>((c, o) => JsEngineSwitcher.Current);
3939
container.Register<IJavaScriptEngineFactory, JavaScriptEngineFactory>().AsSingleton();
4040
container.Register<IReactIdGenerator, ReactIdGenerator>().AsSingleton();
4141

src/React.Core/Exceptions/BabelException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when an error occurs when transforming a JavaScript file via Babel.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class BabelException : ReactException
@@ -33,7 +33,7 @@ public BabelException(string message) : base(message) { }
3333
public BabelException(string message, Exception innerException)
3434
: base(message, innerException) { }
3535

36-
#if NET40
36+
#if !NETSTANDARD1_6
3737
/// <summary>
3838
/// Used by deserialization
3939
/// </summary>

src/React.Core/Exceptions/BabelNotLoadedException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when Babel is required but has not been loaded.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class BabelNotLoadedException : ReactException
@@ -25,7 +25,7 @@ public class BabelNotLoadedException : ReactException
2525
/// </summary>
2626
public BabelNotLoadedException() : base(GetMessage()) { }
2727

28-
#if NET40
28+
#if !NETSTANDARD1_6
2929
/// <summary>
3030
/// Used by deserialization
3131
/// </summary>

src/React.Core/Exceptions/ClearScriptV8InitialisationException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when the ClearScript V8 JavaScript engine fails to initialise
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ClearScriptV8InitialisationException : ReactException
@@ -26,7 +26,7 @@ public class ClearScriptV8InitialisationException : ReactException
2626
public ClearScriptV8InitialisationException(Exception innerException) :
2727
base(GetMessage(innerException), innerException) { }
2828

29-
#if NET40
29+
#if !NETSTANDARD1_6
3030
/// <summary>
3131
/// Used by deserialization
3232
/// </summary>

src/React.Core/Exceptions/ReactConfigurationException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when an error occurs while reading a site configuration file.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactConfigurationException : ReactException
@@ -33,7 +33,7 @@ public ReactConfigurationException(string message) : base(message) { }
3333
public ReactConfigurationException(string message, Exception innerException)
3434
: base(message, innerException) { }
3535

36-
#if NET40
36+
#if !NETSTANDARD1_6
3737
/// <summary>
3838
/// Used by deserialization
3939
/// </summary>

src/React.Core/Exceptions/ReactEngineNotFoundException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2015, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when no valid JavaScript engine is found.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactEngineNotFoundException : ReactException
@@ -31,7 +31,7 @@ public ReactEngineNotFoundException() : base(GetMessage()) { }
3131
/// <param name="message">The message that describes the error.</param>
3232
public ReactEngineNotFoundException(string message) : base(message) { }
3333

34-
#if NET40
34+
#if !NETSTANDARD1_6
3535
/// <summary>
3636
/// Used by deserialization
3737
/// </summary>

src/React.Core/Exceptions/ReactException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Base class for all ReactJS.NET exceptions
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactException : Exception
@@ -37,7 +37,7 @@ public ReactException(string message) : base(message) { }
3737
public ReactException(string message, Exception innerException)
3838
: base(message, innerException) { }
3939

40-
#if NET40
40+
#if !NETSTANDARD1_6
4141
/// <summary>
4242
/// Used by deserialization
4343
/// </summary>

src/React.Core/Exceptions/ReactInvalidComponentException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when a non-existent component is rendered.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactInvalidComponentException : ReactException
@@ -33,7 +33,7 @@ public ReactInvalidComponentException(string message) : base(message) { }
3333
public ReactInvalidComponentException(string message, Exception innerException)
3434
: base(message, innerException) { }
3535

36-
#if NET40
36+
#if !NETSTANDARD1_6
3737
/// <summary>
3838
/// Used by deserialization
3939
/// </summary>

src/React.Core/Exceptions/ReactNotInitialisedException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2015, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when React has not been initialised correctly.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactNotInitialisedException : ReactException
@@ -34,7 +34,7 @@ public ReactNotInitialisedException(string message) : base(message) { }
3434
public ReactNotInitialisedException(string message, Exception innerException)
3535
: base(message, innerException) { }
3636

37-
#if NET40
37+
#if !NETSTANDARD1_6
3838
/// <summary>
3939
/// Used by deserialization
4040
/// </summary>

src/React.Core/Exceptions/ReactScriptLoadException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when an error is encountered while loading a JavaScript file.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactScriptLoadException : ReactException
@@ -34,7 +34,7 @@ public ReactScriptLoadException(string message) : base(message) { }
3434
public ReactScriptLoadException(string message, Exception innerException)
3535
: base(message, innerException) { }
3636

37-
#if NET40
37+
#if !NETSTANDARD1_6
3838
/// <summary>
3939
/// Used by deserialization
4040
/// </summary>

src/React.Core/Exceptions/ReactServerRenderingException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when an error occurs during server rendering of a React component.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class ReactServerRenderingException : ReactException
@@ -34,7 +34,7 @@ public ReactServerRenderingException(string message) : base(message) { }
3434
public ReactServerRenderingException(string message, Exception innerException)
3535
: base(message, innerException) { }
3636

37-
#if NET40
37+
#if !NETSTANDARD1_6
3838
/// <summary>
3939
/// Used by deserialization
4040
/// </summary>

src/React.Core/Exceptions/VroomJsInitialisationException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -15,7 +15,7 @@ namespace React.Exceptions
1515
/// <summary>
1616
/// Thrown when the VroomJs V8 JavaScript engine fails to initialise.
1717
/// </summary>
18-
#if NET40
18+
#if !NETSTANDARD1_6
1919
[Serializable]
2020
#endif
2121
public class VroomJsInitialisationException : ReactException
@@ -26,7 +26,7 @@ public class VroomJsInitialisationException : ReactException
2626
public VroomJsInitialisationException(string innerMessage) :
2727
base(GetMessage(innerMessage)) { }
2828

29-
#if NET40
29+
#if !NETSTANDARD1_6
3030
/// <summary>
3131
/// Used by deserialization
3232
/// </summary>

src/React.Core/FileCacheHash.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class FileCacheHash : IFileCacheHash
2727
/// <summary>
2828
/// Algorithm for calculating file hashes
2929
/// </summary>
30-
#if NET40
30+
#if NET40 || NET45
3131
private readonly HashAlgorithm _hash = SHA1.Create("System.Security.Cryptography.SHA1Cng");
3232
#else
3333
private readonly HashAlgorithm _hash = SHA1.Create();

src/React.Core/Initializer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2014-Present, Facebook, Inc.
33
* All rights reserved.
44
*
@@ -13,7 +13,7 @@
1313
using System.Reflection;
1414
using RegisterOptions = React.TinyIoC.TinyIoCContainer.RegisterOptions;
1515

16-
#if !NET40
16+
#if !NET40 && !NET45
1717
using Microsoft.Extensions.DependencyModel;
1818
#endif
1919

@@ -55,7 +55,7 @@ public static void Initialize(Func<RegisterOptions, RegisterOptions> requestLife
5555
private static void InitializeIoC(Func<RegisterOptions, RegisterOptions> requestLifetimeRegistration)
5656
{
5757
TinyIoCExtensions.AsRequestLifetime = requestLifetimeRegistration;
58-
#if NET40
58+
#if NET40 || NET45
5959
var types = AppDomain.CurrentDomain.GetAssemblies()
6060
// Only bother checking React assemblies
6161
.Where(IsReactAssembly)

src/React.Core/JavaScriptEngineFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Threading;
77
using JavaScriptEngineSwitcher.Core;
88
using JavaScriptEngineSwitcher.Msie;
9-
#if NET40
9+
#if NET45
1010
using JavaScriptEngineSwitcher.V8;
1111
#else
1212
using JavaScriptEngineSwitcher.ChakraCore;
@@ -37,7 +37,7 @@ public class JavaScriptEngineFactory : IDisposable, IJavaScriptEngineFactory
3737
/// <summary>
3838
/// The JavaScript Engine Switcher instance used by ReactJS.NET
3939
/// </summary>
40-
protected readonly JsEngineSwitcher _jsEngineSwitcher;
40+
protected readonly IJsEngineSwitcher _jsEngineSwitcher;
4141
/// <summary>
4242
/// Contains all current JavaScript engine instances. One per thread, keyed on thread ID.
4343
/// </summary>
@@ -60,7 +60,7 @@ protected readonly ConcurrentDictionary<int, IJsEngine> _engines
6060
/// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
6161
/// </summary>
6262
public JavaScriptEngineFactory(
63-
JsEngineSwitcher jsEngineSwitcher,
63+
IJsEngineSwitcher jsEngineSwitcher,
6464
IReactSiteConfiguration config,
6565
IFileSystem fileSystem
6666
)
@@ -238,7 +238,7 @@ public virtual PooledJsEngine GetEngine()
238238
/// The first functioning JavaScript engine with the lowest priority will be used.
239239
/// </summary>
240240
/// <returns>Function to create JavaScript engine</returns>
241-
private static Func<IJsEngine> GetFactory(JsEngineSwitcher jsEngineSwitcher, bool allowMsie)
241+
private static Func<IJsEngine> GetFactory(IJsEngineSwitcher jsEngineSwitcher, bool allowMsie)
242242
{
243243
EnsureJsEnginesRegistered(jsEngineSwitcher, allowMsie);
244244

@@ -286,22 +286,22 @@ private static Func<IJsEngine> GetFactory(JsEngineSwitcher jsEngineSwitcher, boo
286286

287287
// Epic fail, none of the engines worked. Nothing we can do now.
288288
// Throw an error relevant to the engine they should be able to use.
289-
#if NET40
289+
#if NET45
290290
if (JavaScriptEngineUtils.EnvironmentSupportsClearScript())
291291
{
292292
JavaScriptEngineUtils.EnsureEngineFunctional<V8JsEngine, ClearScriptV8InitialisationException>(
293293
ex => new ClearScriptV8InitialisationException(ex)
294294
);
295295
}
296+
296297
#endif
297-
#if NET40 || NETSTANDARD1_6
298298
if (JavaScriptEngineUtils.EnvironmentSupportsVroomJs())
299299
{
300300
JavaScriptEngineUtils.EnsureEngineFunctional<VroomJsEngine, VroomJsInitialisationException>(
301301
ex => new VroomJsInitialisationException(ex.Message)
302302
);
303303
}
304-
#endif
304+
305305
throw new ReactEngineNotFoundException();
306306
}
307307

@@ -362,7 +362,7 @@ public void EnsureValidState()
362362
/// </summary>
363363
/// <param name="jsEngineSwitcher">JavaScript Engine Switcher instance</param>
364364
/// <param name="allowMsie">Whether to allow the MSIE JS engine</param>
365-
private static void EnsureJsEnginesRegistered(JsEngineSwitcher jsEngineSwitcher, bool allowMsie)
365+
private static void EnsureJsEnginesRegistered(IJsEngineSwitcher jsEngineSwitcher, bool allowMsie)
366366
{
367367
if (jsEngineSwitcher.EngineFactories.Any())
368368
{
@@ -377,15 +377,15 @@ private static void EnsureJsEnginesRegistered(JsEngineSwitcher jsEngineSwitcher,
377377
"for more information."
378378
);
379379

380-
#if NET40
380+
#if NET45
381381
jsEngineSwitcher.EngineFactories.AddV8();
382382
#endif
383383
jsEngineSwitcher.EngineFactories.AddVroom();
384384
if (allowMsie)
385385
{
386386
jsEngineSwitcher.EngineFactories.AddMsie();
387387
}
388-
#if !NET40
388+
#if !NET45
389389
jsEngineSwitcher.EngineFactories.AddChakraCore();
390390
#endif
391391
}

0 commit comments

Comments
 (0)