Skip to content

Commit 48c0f3c

Browse files
committed
In JavaScriptEngineSwitcher.ChakraCore fixed a error that occurred during the recursive evaluation of JS files
1 parent d96ea95 commit 48c0f3c

File tree

7 files changed

+93
-10
lines changed

7 files changed

+93
-10
lines changed

src/JavaScriptEngineSwitcher.ChakraCore/JsRt/TypeMapper.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public JsValue MapToScriptType(object value)
185185
return JsValue.FromString((string)value);
186186

187187
default:
188-
return GetOrCreateScriptObject(value);
188+
return value is JsValue ? (JsValue)value : GetOrCreateScriptObject(value);
189189
}
190190
}
191191

@@ -874,15 +874,7 @@ private static Exception UnwrapException(Exception exception)
874874
Exception innerException = targetInvocationException.InnerException;
875875
if (innerException != null)
876876
{
877-
var wrapperException = innerException as WrapperException;
878-
if (wrapperException != null)
879-
{
880-
originalException = wrapperException;
881-
}
882-
else
883-
{
884-
originalException = innerException;
885-
}
877+
originalException = innerException;
886878
}
887879
}
888880

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*global require */
2+
(function () {
3+
'use strict';
4+
5+
function calculateResult() {
6+
var math = require('./math'),
7+
result = math.sum(math.cube(5), math.square(2), math.PI)
8+
;
9+
10+
return result;
11+
}
12+
13+
var exports = {
14+
calculateResult: calculateResult
15+
};
16+
17+
return exports;
18+
}());
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(function () {
2+
'use strict';
3+
4+
function sum() {
5+
var result = 0,
6+
i
7+
;
8+
9+
for (i = 0; i < arguments.length; i++) {
10+
result += arguments[i];
11+
}
12+
13+
return result;
14+
}
15+
16+
function square(num) {
17+
return num * num;
18+
}
19+
20+
function cube(num) {
21+
return num * num * num;
22+
}
23+
24+
var exports = {
25+
PI: 3.14,
26+
sum: sum,
27+
square: square,
28+
cube: cube
29+
};
30+
31+
return exports;
32+
}());

test/JavaScriptEngineSwitcher.Tests/Jint/MultithreadingTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ protected override string EngineName
66
{
77
get { return "JintJsEngine"; }
88
}
9+
10+
11+
// TODO: Remove after fixing a error
12+
public override void RecursiveEvaluationOfFilesIsCorrect()
13+
{ }
914
}
1015
}

test/JavaScriptEngineSwitcher.Tests/Msie/MultithreadingTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@ protected override string EngineName
1111
// TODO: Remove after fixing a error in the MSIE JavaScript Engine for .NET
1212
public override void RecursiveExecutionOfFilesIsCorrect()
1313
{ }
14+
15+
// TODO: Remove after fixing a error in the MSIE JavaScript Engine for .NET
16+
public override void RecursiveEvaluationOfFilesIsCorrect()
17+
{ }
1418
}
1519
}

test/JavaScriptEngineSwitcher.Tests/MultithreadingTestsBase.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Threading;
34

45
using Xunit;
@@ -57,5 +58,33 @@ public virtual void RecursiveExecutionOfFilesIsCorrect()
5758
// Assert
5859
Assert.Equal(targetOutput, output);
5960
}
61+
62+
[Fact]
63+
public virtual void RecursiveEvaluationOfFilesIsCorrect()
64+
{
65+
// Arrange
66+
const string input = "require('index').calculateResult();";
67+
const double targetOutput = 132.14;
68+
69+
// Act
70+
double output;
71+
72+
using (var jsEngine = CreateJsEngine())
73+
{
74+
Func<string, object> loadModule = name => {
75+
string path = Path.Combine("Files/recursiveEvaluation", $"{name}.js");
76+
string code = File.ReadAllText(path);
77+
object result = jsEngine.Evaluate(code, path);
78+
79+
return result;
80+
};
81+
82+
jsEngine.EmbedHostObject("require", loadModule);
83+
output = jsEngine.Evaluate<double>(input);
84+
}
85+
86+
// Assert
87+
Assert.Equal(targetOutput, output);
88+
}
6089
}
6190
}

test/JavaScriptEngineSwitcher.Tests/Vroom/MultithreadingTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ protected override string EngineName
1010

1111
public override void RecursiveExecutionOfFilesIsCorrect()
1212
{ }
13+
14+
public override void RecursiveEvaluationOfFilesIsCorrect()
15+
{ }
1316
}
1417
}

0 commit comments

Comments
 (0)