Skip to content

Commit 1b69897

Browse files
committed
1. JsRuntimeErrorHelpers class was renamed to JsErrorHelpers class;
2. Was made refactoring.
1 parent 4e41f17 commit 1b69897

File tree

12 files changed

+55
-24
lines changed

12 files changed

+55
-24
lines changed

src/JavaScriptEngineSwitcher.ChakraCore/AssemblyResolver.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#endif
88

99
using JavaScriptEngineSwitcher.Core.Helpers;
10+
using JavaScriptEngineSwitcher.Core.Utilities;
1011

1112
using JavaScriptEngineSwitcher.ChakraCore.Resources;
1213

@@ -30,12 +31,11 @@ internal static class AssemblyResolver
3031
/// </summary>
3132
public static void Initialize()
3233
{
34+
bool is64BitProcess = Utils.Is64BitProcess();
3335
string baseDirectoryPath;
34-
bool is64BitProcess;
3536

3637
#if NETSTANDARD1_3
3738
baseDirectoryPath = PlatformServices.Default.Application.ApplicationBasePath;
38-
is64BitProcess = IntPtr.Size == 8;
3939
#else
4040
AppDomain currentDomain = AppDomain.CurrentDomain;
4141
baseDirectoryPath = currentDomain.SetupInformation.PrivateBinPath;
@@ -45,7 +45,6 @@ public static void Initialize()
4545
// need to use the `BaseDirectory` property
4646
baseDirectoryPath = currentDomain.BaseDirectory;
4747
}
48-
is64BitProcess = Environment.Is64BitProcess;
4948
#endif
5049

5150
if (!PathHelpers.ContainsDirectory(baseDirectoryPath, "bin"))

src/JavaScriptEngineSwitcher.ChakraCore/ChakraCoreJsEngine.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public sealed class ChakraCoreJsEngine : JsEngineBase
5050
/// <summary>
5151
/// List of external objects
5252
/// </summary>
53-
private ISet<object> _externalObjects = new HashSet<object>();
53+
private readonly HashSet<object> _externalObjects = new HashSet<object>();
5454

5555
/// <summary>
5656
/// Callback for finalization of external object
@@ -60,7 +60,7 @@ public sealed class ChakraCoreJsEngine : JsEngineBase
6060
/// <summary>
6161
/// List of native function callbacks
6262
/// </summary>
63-
private ISet<JsNativeFunction> _nativeFunctions = new HashSet<JsNativeFunction>();
63+
private readonly HashSet<JsNativeFunction> _nativeFunctions = new HashSet<JsNativeFunction>();
6464

6565
/// <summary>
6666
/// Gets a name of JS engine
@@ -92,6 +92,8 @@ static ChakraCoreJsEngine()
9292
/// </summary>
9393
public ChakraCoreJsEngine()
9494
{
95+
_externalObjectFinalizeCallback = ExternalObjectFinalizeCallback;
96+
9597
try
9698
{
9799
_jsRuntime = JsRuntime.Create(JsRuntimeAttributes.AllowScriptInterrupt, JsRuntimeVersion.VersionEdge, null);
@@ -103,8 +105,6 @@ public ChakraCoreJsEngine()
103105
string.Format(CoreStrings.Runtime_JsEngineNotLoaded,
104106
EngineName, e.Message), EngineName, EngineVersion, e);
105107
}
106-
107-
_externalObjectFinalizeCallback = ExternalObjectFinalizeCallback;
108108
}
109109

110110
/// <summary>
@@ -164,13 +164,11 @@ private void Dispose(bool disposing)
164164
if (_externalObjects != null)
165165
{
166166
_externalObjects.Clear();
167-
_externalObjects = null;
168167
}
169168

170169
if (_nativeFunctions != null)
171170
{
172171
_nativeFunctions.Clear();
173-
_nativeFunctions = null;
174172
}
175173

176174
_externalObjectFinalizeCallback = null;
@@ -346,7 +344,10 @@ private void ExternalObjectFinalizeCallback(IntPtr data)
346344

347345
lock (_executionSynchronizer)
348346
{
349-
_externalObjects.Remove(obj);
347+
if (_externalObjects != null)
348+
{
349+
_externalObjects.Remove(obj);
350+
}
350351
}
351352
}
352353

src/JavaScriptEngineSwitcher.Core/Helpers/JsRuntimeErrorHelpers.cs renamed to src/JavaScriptEngineSwitcher.Core/Helpers/JsErrorHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace JavaScriptEngineSwitcher.Core.Helpers
1010
/// <summary>
1111
/// JS error helpers
1212
/// </summary>
13-
public static class JsRuntimeErrorHelpers
13+
public static class JsErrorHelpers
1414
{
1515
/// <summary>
1616
/// Generates a detailed error message

src/JavaScriptEngineSwitcher.Core/Helpers/ValidationHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static class ValidationHelpers
2222
/// <summary>
2323
/// List of primitive type codes
2424
/// </summary>
25-
private static readonly TypeCode[] _primitiveTypeCodes = new[]
25+
private static readonly TypeCode[] _primitiveTypeCodes =
2626
{
2727
TypeCode.Boolean,
2828
TypeCode.SByte, TypeCode.Byte,

src/JavaScriptEngineSwitcher.Core/Utilities/DelegateExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if NET40
2+
using System;
23
using System.Reflection;
34

45
namespace JavaScriptEngineSwitcher.Core.Utilities
@@ -23,4 +24,5 @@ public static MethodInfo GetMethodInfo(this Delegate source)
2324
return source.Method;
2425
}
2526
}
26-
}
27+
}
28+
#endif

src/JavaScriptEngineSwitcher.Core/Utilities/TypeInfo.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if NET40
2+
using System;
23
using System.Reflection;
34

45
namespace JavaScriptEngineSwitcher.Core.Utilities
@@ -65,4 +66,5 @@ public bool IsInstanceOfType(object o)
6566
return _type.IsInstanceOfType(o);
6667
}
6768
}
68-
}
69+
}
70+
#endif

src/JavaScriptEngineSwitcher.Core/Utilities/Utils.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4+
using System.Runtime.CompilerServices;
45
using System.Text;
56

67
using JavaScriptEngineSwitcher.Core.Resources;
@@ -9,6 +10,22 @@ namespace JavaScriptEngineSwitcher.Core.Utilities
910
{
1011
public static class Utils
1112
{
13+
/// <summary>
14+
/// Determines whether the current process is a 64-bit process
15+
/// </summary>
16+
/// <returns>true if the process is 64-bit; otherwise, false</returns>
17+
[MethodImpl((MethodImplOptions)256 /* AggressiveInlining */)]
18+
public static bool Is64BitProcess()
19+
{
20+
#if NETSTANDARD1_3
21+
bool is64Bit = IntPtr.Size == 8;
22+
#else
23+
bool is64Bit = Environment.Is64BitProcess;
24+
#endif
25+
26+
return is64Bit;
27+
}
28+
1229
/// <summary>
1330
/// Gets a content of the embedded resource as string
1431
/// </summary>

src/JavaScriptEngineSwitcher.Msie/JsEngineMode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public enum JsEngineMode
1414
/// Classic MSIE JavaScript engine (supports ECMAScript 3 with
1515
/// possibility of using the ECMAScript 5 Polyfill and the JSON2 library).
1616
/// Requires Internet Explorer 6 or higher on the machine.
17+
/// Not supported in version for .NET Core.
1718
/// </summary>
1819
Classic,
1920

2021
/// <summary>
2122
/// ActiveScript version of Chakra JavaScript engine (supports ECMAScript 3
2223
/// with possibility of using the ECMAScript 5 Polyfill and the JSON2 library).
2324
/// Requires Internet Explorer 9 or higher on the machine.
25+
/// Not supported in version for .NET Core.
2426
/// </summary>
2527
ChakraActiveScript,
2628

test/JavaScriptEngineSwitcher.Tests/Interop/Drawing/Color.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if NETCOREAPP1_0
2+
using System;
23
using System.Text;
34

45
namespace JavaScriptEngineSwitcher.Tests.Interop.Drawing
@@ -382,4 +383,5 @@ public override string ToString()
382383
return sb.ToString();
383384
}
384385
}
385-
}
386+
}
387+
#endif
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace JavaScriptEngineSwitcher.Tests.Interop.Drawing
1+
#if NETCOREAPP1_0
2+
namespace JavaScriptEngineSwitcher.Tests.Interop.Drawing
23
{
34
/// <summary>
45
/// Specifies the known system colors
@@ -7,4 +8,5 @@ public enum KnownColor
78
{
89
OrangeRed = 128
910
}
10-
}
11+
}
12+
#endif

0 commit comments

Comments
 (0)