File tree Expand file tree Collapse file tree 7 files changed +93
-10
lines changed
src/JavaScriptEngineSwitcher.ChakraCore/JsRt
test/JavaScriptEngineSwitcher.Tests
Files/recursiveEvaluation Expand file tree Collapse file tree 7 files changed +93
-10
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ public JsValue MapToScriptType(object value)
185
185
return JsValue . FromString ( ( string ) value ) ;
186
186
187
187
default :
188
- return GetOrCreateScriptObject ( value ) ;
188
+ return value is JsValue ? ( JsValue ) value : GetOrCreateScriptObject ( value ) ;
189
189
}
190
190
}
191
191
@@ -874,15 +874,7 @@ private static Exception UnwrapException(Exception exception)
874
874
Exception innerException = targetInvocationException . InnerException ;
875
875
if ( innerException != null )
876
876
{
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 ;
886
878
}
887
879
}
888
880
Original file line number Diff line number Diff line change
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
+ } ( ) ) ;
Original file line number Diff line number Diff line change
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
+ } ( ) ) ;
Original file line number Diff line number Diff line change @@ -6,5 +6,10 @@ protected override string EngineName
6
6
{
7
7
get { return "JintJsEngine" ; }
8
8
}
9
+
10
+
11
+ // TODO: Remove after fixing a error
12
+ public override void RecursiveEvaluationOfFilesIsCorrect ( )
13
+ { }
9
14
}
10
15
}
Original file line number Diff line number Diff line change @@ -11,5 +11,9 @@ protected override string EngineName
11
11
// TODO: Remove after fixing a error in the MSIE JavaScript Engine for .NET
12
12
public override void RecursiveExecutionOfFilesIsCorrect ( )
13
13
{ }
14
+
15
+ // TODO: Remove after fixing a error in the MSIE JavaScript Engine for .NET
16
+ public override void RecursiveEvaluationOfFilesIsCorrect ( )
17
+ { }
14
18
}
15
19
}
Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . IO ;
2
3
using System . Threading ;
3
4
4
5
using Xunit ;
@@ -57,5 +58,33 @@ public virtual void RecursiveExecutionOfFilesIsCorrect()
57
58
// Assert
58
59
Assert . Equal ( targetOutput , output ) ;
59
60
}
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
+ }
60
89
}
61
90
}
Original file line number Diff line number Diff line change @@ -10,5 +10,8 @@ protected override string EngineName
10
10
11
11
public override void RecursiveExecutionOfFilesIsCorrect ( )
12
12
{ }
13
+
14
+ public override void RecursiveEvaluationOfFilesIsCorrect ( )
15
+ { }
13
16
}
14
17
}
You can’t perform that action at this time.
0 commit comments