@@ -27,7 +27,7 @@ public void TearDown()
27
27
public void GetFunctionExpressionFromJsContext ( )
28
28
{
29
29
_context . Run ( "a = function(a, b) { return a + b; }" ) ;
30
-
30
+
31
31
JavascriptFunction funcObj = _context . GetParameter ( "a" ) as JavascriptFunction ;
32
32
funcObj . Should ( ) . NotBeNull ( ) ;
33
33
funcObj . Call ( 1 , 2 ) . Should ( ) . BeOfType < int > ( ) . Which . Should ( ) . Be ( 3 ) ;
@@ -37,7 +37,7 @@ public void GetFunctionExpressionFromJsContext()
37
37
public void GetNamedFunctionFromJsContext ( )
38
38
{
39
39
_context . Run ( "function test(a, b) { return a + b; }" ) ;
40
-
40
+
41
41
JavascriptFunction funcObj = _context . GetParameter ( "test" ) as JavascriptFunction ;
42
42
funcObj . Should ( ) . NotBeNull ( ) ;
43
43
funcObj . Call ( 1 , 2 ) . Should ( ) . BeOfType < int > ( ) . Which . Should ( ) . Be ( 3 ) ;
@@ -47,7 +47,7 @@ public void GetNamedFunctionFromJsContext()
47
47
public void GetArrowFunctionExpressionFromJsContext ( )
48
48
{
49
49
_context . Run ( "a = (a, b) => a + b" ) ;
50
-
50
+
51
51
JavascriptFunction funcObj = _context . GetParameter ( "a" ) as JavascriptFunction ;
52
52
funcObj . Should ( ) . NotBeNull ( ) ;
53
53
funcObj . Call ( 1 , 2 ) . Should ( ) . BeOfType < int > ( ) . Which . Should ( ) . Be ( 3 ) ;
@@ -57,7 +57,7 @@ public void GetArrowFunctionExpressionFromJsContext()
57
57
public void PassFunctionToMethodInManagedObjectAndUseItToFilterAList ( )
58
58
{
59
59
_context . SetParameter ( "collection" , new CollectionWrapper ( ) ) ;
60
-
60
+
61
61
var result = _context . Run ( "collection.Filter(x => x % 2 === 0)" ) as IEnumerable < int > ;
62
62
result . Should ( ) . NotBeNull ( ) ;
63
63
result . Should ( ) . BeEquivalentTo ( 2 , 4 ) ;
@@ -73,6 +73,21 @@ public void ExceptionsAreHandledAndWrappedInAJavascriptExceptionObject()
73
73
}
74
74
}
75
75
76
+ [ TestClass ]
77
+ public class JavascriptFunctionTestsWithoutAutomaticContext
78
+ {
79
+ [ TestMethod ]
80
+ public void CannotUseAFunctionWhenItsContextIsDisposed ( )
81
+ {
82
+ JavascriptFunction function ;
83
+ using ( var context = new JavascriptContext ( ) ) {
84
+ function = context . Run ( "() => { throw new Error('test'); }" ) as JavascriptFunction ;
85
+ }
86
+ Action action = ( ) => function . Call ( ) ;
87
+ action . ShouldThrowExactly < JavascriptException > ( ) . WithMessage ( "This function's owning JavascriptContext has been disposed" ) ;
88
+ }
89
+ }
90
+
76
91
class CollectionWrapper
77
92
{
78
93
private IEnumerable < int > numbers = new List < int > { 1 , 2 , 3 , 4 , 5 } ;
0 commit comments