Skip to content

Commit 2c564a8

Browse files
committed
Was made refactoring
1 parent 7c18d7c commit 2c564a8

File tree

13 files changed

+85
-83
lines changed

13 files changed

+85
-83
lines changed

src/MsieJavaScriptEngine/ActiveScript/ActiveScriptJsEngineBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ private object InnerGetVariableValue(string variableName)
498498
/// <param name="value">Value of variable</param>
499499
protected void InnerSetVariableValue(string variableName, object value)
500500
{
501-
object[] args = { value };
501+
object[] args = [value];
502502

503503
try
504504
{

src/MsieJavaScriptEngine/Extensions/StringExtensions.cs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22

3-
using MsieJavaScriptEngine.Utilities;
4-
53
namespace MsieJavaScriptEngine.Extensions
64
{
75
/// <summary>
@@ -70,25 +68,6 @@ public static string TrimStart(this string source, string trimString)
7068

7169
return result;
7270
}
73-
74-
/// <summary>
75-
/// Removes all leading newline characters from the current <see cref="T:System.String" /> object
76-
/// </summary>
77-
/// <param name="source">String value</param>
78-
/// <returns>The string that remains after all newline characters are removed from the start of
79-
/// the current string. If no characters can be trimmed from the current instance, the method returns
80-
/// the current instance unchanged.</returns>
81-
public static string TrimStartNewLines(this string source)
82-
{
83-
if (source is null)
84-
{
85-
throw new ArgumentNullException(nameof(source));
86-
}
87-
88-
string result = source.TrimStart(EnvironmentShortcuts.NewLineChars);
89-
90-
return result;
91-
}
9271
#if NETFRAMEWORK
9372

9473
/// <summary>
@@ -133,15 +112,18 @@ public static string CapitalizeFirstLetter(this string source)
133112
/// Splits a string into lines
134113
/// </summary>
135114
/// <param name="source">Instance of <see cref="String"/></param>
115+
/// <param name="options"><see cref="StringSplitOptions.RemoveEmptyEntries"/> to omit empty array
116+
/// elements from the array returned; or <see cref="StringSplitOptions.None"/> to include empty
117+
/// array elements in the array returned</param>
136118
/// <returns>An array of lines</returns>
137-
public static string[] SplitToLines(this string source)
119+
public static string[] SplitToLines(this string source, StringSplitOptions options)
138120
{
139121
if (source is null)
140122
{
141123
throw new ArgumentNullException(nameof(source));
142124
}
143125

144-
string[] result = source.Split(_newLineStrings, StringSplitOptions.None);
126+
string[] result = source.Split(_newLineStrings, options);
145127

146128
return result;
147129
}

src/MsieJavaScriptEngine/Helpers/JsErrorHelpers.cs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using MsieJavaScriptEngine.Extensions;
1111
using MsieJavaScriptEngine.Resources;
12+
using MsieJavaScriptEngine.Utilities;
1213

1314
namespace MsieJavaScriptEngine.Helpers
1415
{
@@ -28,6 +29,33 @@ public static class JsErrorHelpers
2829
@"\((?<documentName>" + CommonRegExps.DocumentNamePattern + @"):" +
2930
@"(?<lineNumber>\d+):(?<columnNumber>\d+)\)$");
3031

32+
33+
/// <summary>
34+
/// Gets a string representation of the script call stack
35+
/// </summary>
36+
/// <param name="message">Error message with the script call stack</param>
37+
/// <param name="messageWithoutCallStack">Error message without the script call stack</param>
38+
/// <returns>String representation of the script call stack</returns>
39+
internal static string GetCallStackFromMessage(string message, string messageWithoutCallStack)
40+
{
41+
if (string.IsNullOrWhiteSpace(message))
42+
{
43+
return string.Empty;
44+
}
45+
46+
if (string.IsNullOrWhiteSpace(messageWithoutCallStack))
47+
{
48+
return message;
49+
}
50+
51+
string callStack = message
52+
.TrimStart(messageWithoutCallStack)
53+
.TrimStart(EnvironmentShortcuts.NewLineChars)
54+
;
55+
56+
return callStack;
57+
}
58+
3159
/// <summary>
3260
/// Parses a string representation of the script call stack to produce an array of
3361
/// <see cref="CallStackItem"/> instances
@@ -41,26 +69,15 @@ internal static CallStackItem[] ParseCallStack(string callStack)
4169
return [];
4270
}
4371

44-
string[] lines = callStack.SplitToLines();
72+
string[] lines = callStack.SplitToLines(StringSplitOptions.RemoveEmptyEntries);
4573
int lineCount = lines.Length;
4674
var callStackItems = new List<CallStackItem>(lineCount);
4775

48-
for (int lineIndex = 0; lineIndex < lineCount; lineIndex++)
76+
foreach (string line in lines)
4977
{
50-
string line = lines[lineIndex];
51-
Match lineMatch = _callStackLineRegex.Match(line);
52-
53-
if (lineMatch.Success)
78+
CallStackItem callStackItem = MapCallStackItem(line);
79+
if (callStackItem is not null)
5480
{
55-
GroupCollection lineGroups = lineMatch.Groups;
56-
57-
var callStackItem = new CallStackItem
58-
{
59-
FunctionName = lineGroups["functionName"].Value,
60-
DocumentName = lineGroups["documentName"].Value,
61-
LineNumber = int.Parse(lineGroups["lineNumber"].Value),
62-
ColumnNumber = int.Parse(lineGroups["columnNumber"].Value)
63-
};
6481
callStackItems.Add(callStackItem);
6582
}
6683
else
@@ -73,6 +90,26 @@ internal static CallStackItem[] ParseCallStack(string callStack)
7390
return callStackItems.ToArray();
7491
}
7592

93+
private static CallStackItem MapCallStackItem(string callStackLine)
94+
{
95+
CallStackItem item = null;
96+
Match lineMatch = _callStackLineRegex.Match(callStackLine);
97+
98+
if (lineMatch.Success)
99+
{
100+
GroupCollection lineGroups = lineMatch.Groups;
101+
item = new CallStackItem
102+
{
103+
FunctionName = lineGroups["functionName"].Value,
104+
DocumentName = lineGroups["documentName"].Value,
105+
LineNumber = int.Parse(lineGroups["lineNumber"].Value),
106+
ColumnNumber = int.Parse(lineGroups["columnNumber"].Value)
107+
};
108+
}
109+
110+
return item;
111+
}
112+
76113
/// <summary>
77114
/// Produces a string representation of the script call stack from array of
78115
/// <see cref="CallStackItem"/> instances

src/MsieJavaScriptEngine/Helpers/ReflectionHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ namespace MsieJavaScriptEngine.Helpers
2020
internal static class ReflectionHelpers
2121
{
2222
private static readonly PropertyInfo[] _disallowedProperties =
23-
{
23+
[
2424
typeof(Delegate).GetProperty("Method"),
2525
typeof(Exception).GetProperty("TargetSite")
26-
};
26+
];
2727

2828
private static readonly MethodInfo[] _disallowedMethods =
29-
{
29+
[
3030
typeof(object).GetMethod("GetType"),
3131
typeof(Exception).GetMethod("GetType")
32-
};
32+
];
3333

3434

3535
public static BindingFlags GetDefaultBindingFlags(bool instance)

src/MsieJavaScriptEngine/Helpers/ValidationHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public static class ValidationHelpers
1515
/// List of supported types
1616
/// </summary>
1717
private static readonly Type[] _supportedTypes =
18-
{
18+
[
1919
typeof(Undefined), typeof(Boolean), typeof(Int32), typeof(Double), typeof(String)
20-
};
20+
];
2121

2222
/// <summary>
2323
/// Regular expression for working with JS names

src/MsieJavaScriptEngine/JsRt/Edge/ChakraEdgeJsRtJsEngine.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,10 @@ private WrapperException WrapJsException(OriginalException originalException,
280280
string messageWithTypeAndCallStack = stackPropertyValue.ValueType == JsValueType.String ?
281281
stackPropertyValue.ToString() : string.Empty;
282282
string messageWithType = errorValue.ConvertToString().ToString();
283-
string rawCallStack = messageWithTypeAndCallStack
284-
.TrimStart(messageWithType)
285-
.TrimStart("Error")
286-
.TrimStartNewLines()
287-
;
288-
283+
string rawCallStack = JsErrorHelpers.GetCallStackFromMessage(
284+
messageWithTypeAndCallStack, messageWithType);
289285
CallStackItem[] callStackItems = JsErrorHelpers.ParseCallStack(rawCallStack);
286+
290287
if (callStackItems.Length > 0)
291288
{
292289
CallStackItem firstCallStackItem = callStackItems[0];

src/MsieJavaScriptEngine/JsRt/Ie/ChakraIeJsRtJsEngine.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,10 @@ private WrapperException WrapJsException(OriginalException originalException,
313313
string messageWithTypeAndCallStack = stackPropertyValue.ValueType == JsValueType.String ?
314314
stackPropertyValue.ToString() : string.Empty;
315315
string messageWithType = errorValue.ConvertToString().ToString();
316-
string rawCallStack = messageWithTypeAndCallStack
317-
.TrimStart(messageWithType)
318-
.TrimStartNewLines()
319-
;
320-
316+
string rawCallStack = JsErrorHelpers.GetCallStackFromMessage(
317+
messageWithTypeAndCallStack, messageWithType);
321318
CallStackItem[] callStackItems = JsErrorHelpers.ParseCallStack(rawCallStack);
319+
322320
if (callStackItems.Length > 0)
323321
{
324322
FixCallStackItems(callStackItems);

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
<IncludeSymbols>true</IncludeSymbols>
2525
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2626
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
27-
<PackageReleaseNotes>1. Optimized a memory usage in the `ReflectionHelpers.GetBestFitMethod` method;
28-
2. Added support for .NET Standard 2.1 and .NET 10;
29-
3. Performed a migration to the modern C# null/not-null checks;
30-
4. In the `lock` statements for .NET 10 target now uses a instances of the `System.Threading.Lock` class;
31-
5. Reduced a memory allocation by using collection expressions;
32-
6. The value of a read-only field in an embedded object or type can no longer be changed.</PackageReleaseNotes>
27+
<PackageReleaseNotes>Was made refactoring.</PackageReleaseNotes>
3328
<NeutralLanguage>en-US</NeutralLanguage>
3429
<PackageOutputPath>../../nuget</PackageOutputPath>
3530
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/Utilities/TypeConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public static class TypeConverter
2424
/// List of primitive type codes
2525
/// </summary>
2626
private static readonly TypeCode[] _primitiveTypeCodes =
27-
{
27+
[
2828
TypeCode.Boolean,
2929
TypeCode.SByte, TypeCode.Byte,
3030
TypeCode.Int16, TypeCode.UInt16, TypeCode.Int32, TypeCode.UInt32, TypeCode.Int64, TypeCode.UInt64,
3131
TypeCode.Single, TypeCode.Double, TypeCode.Decimal,
3232
TypeCode.Char, TypeCode.String
33-
};
33+
];
3434

3535
/// <summary>
3636
/// Converts the specified value to the specified type

src/MsieJavaScriptEngine/readme.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
1. Optimized a memory usage in the `ReflectionHelpers.GetBestFitMethod` method;
25-
2. Added support for .NET Standard 2.1 and .NET 10;
26-
3. Performed a migration to the modern C# null/not-null checks;
27-
4. In the `lock` statements for .NET 10 target now uses a instances of the
28-
`System.Threading.Lock` class;
29-
5. Reduced a memory allocation by using collection expressions;
30-
6. The value of a read-only field in an embedded object or type can no longer be
31-
changed.
24+
Was made refactoring.
3225

3326
============
3427
PROJECT SITE

0 commit comments

Comments
 (0)