Skip to content

Commit a51f990

Browse files
committed
In version for .NET Framework was fixed a error that occurred during the recursive execution and evaluation of JS files
1 parent dac54bd commit a51f990

File tree

8 files changed

+131
-18
lines changed

8 files changed

+131
-18
lines changed

src/MsieJavaScriptEngine/Helpers/TypeMappingHelpers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static object MapToScriptType(object value, JsEngineMode engineMode)
2929
return null;
3030
}
3131

32-
if (TypeConverter.IsPrimitiveType(value.GetType()))
32+
Type type = value.GetType();
33+
if (TypeConverter.IsPrimitiveType(type) || type.FullName == "System.__ComObject")
3334
{
3435
return value;
3536
}

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<RepositoryUrl>https://github.com/Taritsyn/MsieJavaScriptEngine</RepositoryUrl>
2222
<RepositoryType>git</RepositoryType>
2323
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
24-
<PackageReleaseNotes>In version for .NET Core was fixed a error that occurred during the recursive execution and evaluation of JS files.</PackageReleaseNotes>
24+
<PackageReleaseNotes>Fixed a error that occurred during the recursive execution and evaluation of JS files (while without correct handling of host exceptions).</PackageReleaseNotes>
2525
<NeutralLanguage>en-US</NeutralLanguage>
2626
<PackageOutputPath>../../nuget</PackageOutputPath>
2727
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
In version for .NET Core was fixed a error that occurred during the recursive
25-
execution and evaluation of JS files.
24+
Fixed a error that occurred during the recursive execution and evaluation of JS
25+
files (while without correct handling of host exceptions).
2626

2727
============
2828
PROJECT SITE

test/MsieJavaScriptEngine.Test.ChakraActiveScript/InteropTests.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using NUnit.Framework;
1+
using System;
2+
using System.IO;
3+
4+
using NUnit.Framework;
25

36
using MsieJavaScriptEngine.Test.Common;
47

@@ -8,5 +11,61 @@ namespace MsieJavaScriptEngine.Test.ChakraActiveScript
811
public class InteropTests : InteropTestsBase
912
{
1013
protected override JsEngineMode EngineMode => JsEngineMode.ChakraActiveScript;
14+
15+
16+
#region Embedding of objects
17+
18+
#region Recursive calls
19+
20+
#region Mapping of errors
21+
22+
[Test]
23+
public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect()
24+
{
25+
// Arrange
26+
string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError");
27+
const string input = "require('index').calculateResult();";
28+
29+
// Act
30+
JsRuntimeException exception = null;
31+
32+
using (var jsEngine = CreateJsEngine())
33+
{
34+
try
35+
{
36+
Func<string, object> loadModule = path => {
37+
string absolutePath = Path.Combine(directoryPath, $"{path}.js");
38+
string code = File.ReadAllText(absolutePath);
39+
object result = jsEngine.Evaluate(code, absolutePath);
40+
41+
return result;
42+
};
43+
44+
jsEngine.EmbedHostObject("require", loadModule);
45+
double output = jsEngine.Evaluate<double>(input);
46+
}
47+
catch (JsRuntimeException e)
48+
{
49+
exception = e;
50+
}
51+
}
52+
53+
// Assert
54+
Assert.NotNull(exception);
55+
Assert.AreEqual("Runtime error", exception.Category);
56+
Assert.AreEqual("'argumens' is undefined", exception.Description);
57+
Assert.AreEqual("ReferenceError", exception.Type);
58+
Assert.AreEqual("math.js", exception.DocumentName);
59+
Assert.AreEqual(10, exception.LineNumber);
60+
Assert.AreEqual(4, exception.ColumnNumber);
61+
Assert.IsEmpty(exception.SourceFragment);
62+
Assert.IsEmpty(exception.CallStack);
63+
}
64+
65+
#endregion
66+
67+
#endregion
68+
69+
#endregion
1170
}
1271
}

test/MsieJavaScriptEngine.Test.ChakraEdgeJsRt/InteropTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#if NETCOREAPP
2-
using System;
1+
using System;
32
using System.IO;
43

5-
#endif
64
using NUnit.Framework;
75

86
using MsieJavaScriptEngine.Test.Common;
@@ -13,10 +11,10 @@ namespace MsieJavaScriptEngine.Test.ChakraEdgeJsRt
1311
public class InteropTests : InteropTestsBase
1412
{
1513
protected override JsEngineMode EngineMode => JsEngineMode.ChakraEdgeJsRt;
16-
#if NETCOREAPP
1714

1815

1916
#region Embedding of objects
17+
#if NETCOREAPP
2018

2119
#region Delegates
2220

@@ -42,6 +40,7 @@ public void EmbeddedInstanceOfDelegateHasFunctionPrototype()
4240
}
4341

4442
#endregion
43+
#endif
4544

4645
#region Recursive calls
4746

@@ -100,6 +99,5 @@ public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect()
10099
#endregion
101100

102101
#endregion
103-
#endif
104102
}
105103
}

test/MsieJavaScriptEngine.Test.ChakraIeJsRt/InteropTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#if NETCOREAPP
2-
using System;
1+
using System;
32
using System.IO;
43

5-
#endif
64
using NUnit.Framework;
75

86
using MsieJavaScriptEngine.Test.Common;
@@ -13,10 +11,10 @@ namespace MsieJavaScriptEngine.Test.ChakraIeJsRt
1311
public class InteropTests : InteropTestsBase
1412
{
1513
protected override JsEngineMode EngineMode => JsEngineMode.ChakraIeJsRt;
16-
#if NETCOREAPP
1714

1815

1916
#region Embedding of objects
17+
#if NETCOREAPP
2018

2119
#region Delegates
2220

@@ -42,6 +40,7 @@ public void EmbeddedInstanceOfDelegateHasFunctionPrototype()
4240
}
4341

4442
#endregion
43+
#endif
4544

4645
#region Recursive calls
4746

@@ -100,6 +99,5 @@ public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect()
10099
#endregion
101100

102101
#endregion
103-
#endif
104102
}
105103
}

test/MsieJavaScriptEngine.Test.Classic/InteropTests.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using NUnit.Framework;
1+
using System;
2+
using System.IO;
3+
4+
using NUnit.Framework;
25

36
using MsieJavaScriptEngine.Test.Common;
47

@@ -8,5 +11,61 @@ namespace MsieJavaScriptEngine.Test.Classic
811
public class InteropTests : InteropTestsBase
912
{
1013
protected override JsEngineMode EngineMode => JsEngineMode.Classic;
14+
15+
16+
#region Embedding of objects
17+
18+
#region Recursive calls
19+
20+
#region Mapping of errors
21+
22+
[Test]
23+
public void MappingRuntimeErrorDuringRecursiveEvaluationOfFilesIsCorrect()
24+
{
25+
// Arrange
26+
string directoryPath = GetAbsolutePath("SharedFiles/recursiveEvaluation/runtimeError");
27+
const string input = "require('index').calculateResult();";
28+
29+
// Act
30+
JsRuntimeException exception = null;
31+
32+
using (var jsEngine = CreateJsEngine())
33+
{
34+
try
35+
{
36+
Func<string, object> loadModule = path => {
37+
string absolutePath = Path.Combine(directoryPath, $"{path}.js");
38+
string code = File.ReadAllText(absolutePath);
39+
object result = jsEngine.Evaluate(code, absolutePath);
40+
41+
return result;
42+
};
43+
44+
jsEngine.EmbedHostObject("require", loadModule);
45+
double output = jsEngine.Evaluate<double>(input);
46+
}
47+
catch (JsRuntimeException e)
48+
{
49+
exception = e;
50+
}
51+
}
52+
53+
// Assert
54+
Assert.NotNull(exception);
55+
Assert.AreEqual("Runtime error", exception.Category);
56+
Assert.AreEqual("'argumens' is undefined", exception.Description);
57+
Assert.AreEqual("TypeError", exception.Type);
58+
Assert.AreEqual("math.js", exception.DocumentName);
59+
Assert.AreEqual(10, exception.LineNumber);
60+
Assert.AreEqual(4, exception.ColumnNumber);
61+
Assert.IsEmpty(exception.SourceFragment);
62+
Assert.IsEmpty(exception.CallStack);
63+
}
64+
65+
#endregion
66+
67+
#endregion
68+
69+
#endregion
1170
}
1271
}

test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ public virtual void InteractionOfEmbeddedCustomValueTypeAndDelegateInstancesIsCo
638638
}
639639

640640
#endregion
641-
#if NETCOREAPP
642641

643642
#region Recursive calls
644643

@@ -698,7 +697,6 @@ public virtual void RecursiveExecutionOfFilesIsCorrect()
698697
}
699698

700699
#endregion
701-
#endif
702700

703701
#region Removal
704702

0 commit comments

Comments
 (0)