@@ -1123,7 +1123,9 @@ public virtual void EmbeddingOfCustomReferenceTypeWithField()
11231123 // Arrange
11241124 Type defaultLoggerType = typeof ( DefaultLogger ) ;
11251125 Type throwExceptionLoggerType = typeof ( ThrowExceptionLogger ) ;
1126- const string updateCode = "DefaultLogger.Current = new ThrowExceptionLogger();" ;
1126+ const string updateCode = @"var oldLogger = DefaultLogger.Current;
1127+ DefaultLogger.Current = new ThrowExceptionLogger();" ;
1128+ const string rollbackCode = "DefaultLogger.Current = oldLogger;" ;
11271129
11281130 const string input = "DefaultLogger.Current.ToString()" ;
11291131 const string targetOutput = "[throw exception logger]" ;
@@ -1135,9 +1137,13 @@ public virtual void EmbeddingOfCustomReferenceTypeWithField()
11351137 {
11361138 jsEngine . EmbedHostType ( "DefaultLogger" , defaultLoggerType ) ;
11371139 jsEngine . EmbedHostType ( "ThrowExceptionLogger" , throwExceptionLoggerType ) ;
1138- jsEngine . Execute ( updateCode ) ;
11391140
1140- output = jsEngine . Evaluate < string > ( input ) ;
1141+ lock ( DefaultLogger . SyncRoot )
1142+ {
1143+ jsEngine . Execute ( updateCode ) ;
1144+ output = jsEngine . Evaluate < string > ( input ) ;
1145+ jsEngine . Execute ( rollbackCode ) ;
1146+ }
11411147 }
11421148
11431149 // Assert
@@ -1230,7 +1236,9 @@ public virtual void EmbeddingOfCustomReferenceTypeWithProperty()
12301236 {
12311237 // Arrange
12321238 Type bundleTableType = typeof ( BundleTable ) ;
1233- const string updateCode = "BundleTable.EnableOptimizations = false;" ;
1239+ const string updateCode = @"var oldEnableOptimizationsValue = BundleTable.EnableOptimizations;
1240+ BundleTable.EnableOptimizations = false;" ;
1241+ const string rollbackCode = "BundleTable.EnableOptimizations = oldEnableOptimizationsValue;" ;
12341242
12351243 const string input = "BundleTable.EnableOptimizations" ;
12361244 const bool targetOutput = false ;
@@ -1241,9 +1249,13 @@ public virtual void EmbeddingOfCustomReferenceTypeWithProperty()
12411249 using ( var jsEngine = CreateJsEngine ( ) )
12421250 {
12431251 jsEngine . EmbedHostType ( "BundleTable" , bundleTableType ) ;
1244- jsEngine . Execute ( updateCode ) ;
12451252
1246- output = jsEngine . Evaluate < bool > ( input ) ;
1253+ lock ( BundleTable . SyncRoot )
1254+ {
1255+ jsEngine . Execute ( updateCode ) ;
1256+ output = jsEngine . Evaluate < bool > ( input ) ;
1257+ jsEngine . Execute ( rollbackCode ) ;
1258+ }
12471259 }
12481260
12491261 // Assert
0 commit comments