Skip to content

Commit f28ad46

Browse files
committed
In JavaScriptEngineSwitcher.V8 fixed a error, that occurred during parsing of the original error message
1 parent 0d4b378 commit f28ad46

File tree

6 files changed

+156
-16
lines changed

6 files changed

+156
-16
lines changed

NuGet/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.nuspec

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>JavaScriptEngineSwitcher.V8 contains adapter `V8JsEngine` (wrapper for the Microsoft ClearScript.V8 (http://clearscript.codeplex.com) version 5.4.7 with support of V8 version 5.3.332.45). For correct working of the Microsoft ClearScript.V8 require assemblies `msvcp120.dll` and `msvcr120.dll` from the Visual C++ Redistributable Packages for Visual Studio 2013.</description>
1414
<summary>JavaScriptEngineSwitcher.V8 contains adapter `V8JsEngine` (wrapper for the Microsoft ClearScript.V8 version 5.4.7 with support of V8 version 5.3.332.45).</summary>
15-
<releaseNotes>1. Removed dependency on `System.Configuration.dll` (no longer supported configuration by using the `Web.config` and `App.config` files);
16-
2. Added support of .NET Framework 4.5.1;
17-
3. Microsoft ClearScript.V8 was updated to version 5.4.7 (support of V8 version 5.3.332.45);
18-
4. In configuration settings of the V8 JS engine was changed type of `DebugPort` property from `int` to `ushort`.</releaseNotes>
15+
<releaseNotes>Fixed a error, that occurred during parsing of the original error message.</releaseNotes>
1916
<copyright>Copyright (c) 2013-2016 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
2017
<language>en-US</language>
2118
<tags>JavaScriptEngineSwitcher JavaScript ECMAScript V8 ClearScript</tags>

NuGet/JavaScriptEngineSwitcher.V8/readme.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@
2020
=============
2121
RELEASE NOTES
2222
=============
23-
1. Removed dependency on `System.Configuration.dll` (no longer supported
24-
configuration by using the `Web.config` and `App.config` files);
25-
2. Added support of .NET Framework 4.5.1;
26-
3. Microsoft ClearScript.V8 was updated to version 5.4.7 (support of V8 version
27-
5.3.332.45);
28-
4. In configuration settings of the V8 JS engine was changed type of `DebugPort`
29-
property from `int` to `ushort`.
23+
Fixed a error, that occurred during parsing of the original error message.
3024

3125
====================
3226
POST-INSTALL ACTIONS

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/JsValue.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ public static JsValue FromInt32(int value)
303303
public static JsValue FromString(string value)
304304
{
305305
JsValue reference;
306-
JsErrorCode errorCode;
307-
308-
errorCode = Utils.IsWindows() ?
306+
JsErrorCode errorCode = Utils.IsWindows() ?
309307
NativeMethods.JsPointerToString(value, new UIntPtr((uint)value.Length), out reference)
310308
:
311309
NativeMethods.JsPointerToStringUtf8(value, new UIntPtr((uint)value.Length), out reference)

src/JavaScriptEngineSwitcher.V8/V8JsEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public sealed class V8JsEngine : JsEngineBase
4949
/// </summary>
5050
private static readonly Regex _errorStringRegex =
5151
new Regex(@"at (?:[A-Za-z_\$][0-9A-Za-z_\$]* )?" +
52-
@"\(?Script Document(?:\s*\[\d+\])?:(?<lineNumber>\d+):(?<columnNumber>\d+)\)?");
52+
@"\(?Script Document(?:\s*\[(temp|\d+)\])?:(?<lineNumber>\d+):(?<columnNumber>\d+)\)?");
5353

5454
/// <summary>
5555
/// Synchronizer of code execution

test/JavaScriptEngineSwitcher.Tests/CommonTestsBase.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,5 +786,78 @@ public virtual void GarbageCollectionIsCorrect()
786786
}
787787

788788
#endregion
789+
790+
#region Mapping errors
791+
792+
[Fact]
793+
public virtual void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect()
794+
{
795+
// Arrange
796+
const string input = @"var $variable1 = 611;
797+
var _variable2 = 711;
798+
var @variable3 = 678;
799+
800+
$variable1 + _variable2 - variable3;";
801+
802+
JsRuntimeException exception = null;
803+
804+
// Act
805+
using (var jsEngine = CreateJsEngine())
806+
{
807+
try
808+
{
809+
int result = jsEngine.Evaluate<int>(input);
810+
}
811+
catch (JsRuntimeException e)
812+
{
813+
exception = e;
814+
}
815+
}
816+
817+
// Assert
818+
Assert.NotNull(exception);
819+
Assert.NotEmpty(exception.Message);
820+
Assert.Equal(3, exception.LineNumber);
821+
Assert.Equal(5, exception.ColumnNumber);
822+
}
823+
824+
public virtual void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect()
825+
{
826+
// Arrange
827+
const string input = @"function factorial(value) {
828+
if (value <= 0) {
829+
throw new Error(""The value must be greater than or equal to zero."");
830+
}
831+
832+
return value !== 1 ? value * factorial(value - 1) : 1;
833+
}
834+
835+
factorial(5);
836+
factorial(@);
837+
factorial(0);";
838+
839+
JsRuntimeException exception = null;
840+
841+
// Act
842+
using (var jsEngine = CreateJsEngine())
843+
{
844+
try
845+
{
846+
jsEngine.Execute(input);
847+
}
848+
catch (JsRuntimeException e)
849+
{
850+
exception = e;
851+
}
852+
}
853+
854+
// Assert
855+
Assert.NotNull(exception);
856+
Assert.NotEmpty(exception.Message);
857+
Assert.Equal(10, exception.LineNumber);
858+
Assert.Equal(11, exception.ColumnNumber);
859+
}
860+
861+
#endregion
789862
}
790863
}
Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,88 @@
1-
namespace JavaScriptEngineSwitcher.Tests.Jurassic
1+
using Xunit;
2+
3+
using JavaScriptEngineSwitcher.Core;
4+
5+
namespace JavaScriptEngineSwitcher.Tests.Jurassic
26
{
37
public class CommonTests : CommonTestsBase
48
{
59
protected override string EngineName
610
{
711
get { return "JurassicJsEngine"; }
812
}
13+
14+
15+
#region Mapping errors
16+
17+
[Fact]
18+
public override void MappingRuntimeErrorDuringEvaluationOfExpressionIsCorrect()
19+
{
20+
// Arrange
21+
const string input = @"var $variable1 = 611;
22+
var _variable2 = 711;
23+
var @variable3 = 678;
24+
25+
$variable1 + _variable2 - variable3;";
26+
27+
JsRuntimeException exception = null;
28+
29+
// Act
30+
using (var jsEngine = CreateJsEngine())
31+
{
32+
try
33+
{
34+
int result = jsEngine.Evaluate<int>(input);
35+
}
36+
catch (JsRuntimeException e)
37+
{
38+
exception = e;
39+
}
40+
}
41+
42+
// Assert
43+
Assert.NotNull(exception);
44+
Assert.NotEmpty(exception.Message);
45+
Assert.Equal(3, exception.LineNumber);
46+
Assert.Equal(0, exception.ColumnNumber);
47+
}
48+
49+
public override void MappingRuntimeErrorDuringExecutionOfCodeIsCorrect()
50+
{
51+
// Arrange
52+
const string input = @"function factorial(value) {
53+
if (value <= 0) {
54+
throw new Error(""The value must be greater than or equal to zero."");
55+
}
56+
57+
return value !== 1 ? value * factorial(value - 1) : 1;
58+
}
59+
60+
factorial(5);
61+
factorial(@);
62+
factorial(0);";
63+
64+
JsRuntimeException exception = null;
65+
66+
// Act
67+
using (var jsEngine = CreateJsEngine())
68+
{
69+
try
70+
{
71+
jsEngine.Execute(input);
72+
}
73+
catch (JsRuntimeException e)
74+
{
75+
exception = e;
76+
}
77+
}
78+
79+
// Assert
80+
Assert.NotNull(exception);
81+
Assert.NotEmpty(exception.Message);
82+
Assert.Equal(10, exception.LineNumber);
83+
Assert.Equal(0, exception.ColumnNumber);
84+
}
85+
86+
#endregion
987
}
1088
}

0 commit comments

Comments
 (0)