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)
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
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
66 {
77 get { return "JintJsEngine" ; }
88 }
9+
10+
11+ // TODO: Remove after fixing a error
12+ public override void RecursiveEvaluationOfFilesIsCorrect ( )
13+ { }
914 }
1015}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11using System ;
2+ using System . IO ;
23using System . Threading ;
34
45using 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments