@@ -877,6 +877,41 @@ public virtual void RemovingOfEmbeddedInstanceOfCustomReferenceType()
877
877
878
878
#endregion
879
879
880
+ #region Special cases
881
+
882
+ [ Test ]
883
+ public virtual void EmbeddingOfInstanceOfCustomReferenceTypeAndModificationOfGlobalObject ( )
884
+ {
885
+ // Arrange
886
+ var someObj = new SomeClass ( ) ;
887
+
888
+ const string modifyingCode = @"(function () {
889
+ 'use strict';
890
+
891
+ var global = typeof self != 'undefined' && self.Math == Math ?
892
+ self : Function('return this')();
893
+
894
+ global['foo'] = 'bar';
895
+ })();" ;
896
+ const string variableName = "foo" ;
897
+ const string targetOutput = "bar" ;
898
+
899
+ // Act
900
+ string output ;
901
+
902
+ using ( var jsEngine = CreateJsEngine ( ) )
903
+ {
904
+ jsEngine . EmbedHostObject ( "someObj" , someObj ) ;
905
+ jsEngine . Execute ( modifyingCode ) ;
906
+ output = jsEngine . GetVariableValue < string > ( variableName ) ;
907
+ }
908
+
909
+ // Assert
910
+ Assert . AreEqual ( targetOutput , output ) ;
911
+ }
912
+
913
+ #endregion
914
+
880
915
#endregion
881
916
882
917
@@ -1443,6 +1478,41 @@ public virtual void RemovingOfEmbeddedCustomReferenceType()
1443
1478
1444
1479
#endregion
1445
1480
1481
+ #region Special cases
1482
+
1483
+ [ Test ]
1484
+ public virtual void EmbeddingOfCustomReferenceTypeAndModificationOfGlobalObject ( )
1485
+ {
1486
+ // Arrange
1487
+ var someType = typeof ( SomeClass ) ;
1488
+
1489
+ const string modifyingCode = @"(function () {
1490
+ 'use strict';
1491
+
1492
+ var global = typeof self != 'undefined' && self.Math == Math ?
1493
+ self : Function('return this')();
1494
+
1495
+ global.foo = 'baz';
1496
+ })();" ;
1497
+ const string variableName = "foo" ;
1498
+ const string targetOutput = "baz" ;
1499
+
1500
+ // Act
1501
+ string output ;
1502
+
1503
+ using ( var jsEngine = CreateJsEngine ( ) )
1504
+ {
1505
+ jsEngine . EmbedHostType ( "SomeType" , someType ) ;
1506
+ jsEngine . Execute ( modifyingCode ) ;
1507
+ output = jsEngine . GetVariableValue < string > ( variableName ) ;
1508
+ }
1509
+
1510
+ // Assert
1511
+ Assert . AreEqual ( targetOutput , output ) ;
1512
+ }
1513
+
1514
+ #endregion
1515
+
1446
1516
#endregion
1447
1517
}
1448
1518
}
0 commit comments