|
10 | 10 |
|
11 | 11 | using JavaScriptEngineSwitcher.Tests.Interop;
|
12 | 12 | using JavaScriptEngineSwitcher.Tests.Interop.Animals;
|
| 13 | +using JavaScriptEngineSwitcher.Tests.Interop.Logging; |
13 | 14 |
|
14 | 15 | namespace JavaScriptEngineSwitcher.Tests.Jint
|
15 | 16 | {
|
@@ -462,6 +463,43 @@ string TestAllowReflectionSetting(bool allowReflection)
|
462 | 463 |
|
463 | 464 | #endregion
|
464 | 465 |
|
| 466 | + #region Types with fields |
| 467 | + |
| 468 | + [Fact] |
| 469 | + public override void EmbeddingOfCustomReferenceTypeWithField() |
| 470 | + { |
| 471 | + // Arrange |
| 472 | + Type defaultLoggerType = typeof(DefaultLogger); |
| 473 | + Type throwExceptionLoggerType = typeof(ThrowExceptionLogger); |
| 474 | + const string updateCode = @"var oldLogger = DefaultLogger.Current; |
| 475 | +DefaultLogger.Current = new ThrowExceptionLogger();"; |
| 476 | + const string rollbackCode = "DefaultLogger.Current = oldLogger;"; |
| 477 | + |
| 478 | + const string input = "DefaultLogger.Current"; |
| 479 | + const string targetOutput = "[throw exception logger]"; |
| 480 | + |
| 481 | + // Act |
| 482 | + string output; |
| 483 | + |
| 484 | + using (var jsEngine = CreateJsEngine()) |
| 485 | + { |
| 486 | + jsEngine.EmbedHostType("DefaultLogger", defaultLoggerType); |
| 487 | + jsEngine.EmbedHostType("ThrowExceptionLogger", throwExceptionLoggerType); |
| 488 | + |
| 489 | + lock (DefaultLogger.SyncRoot) |
| 490 | + { |
| 491 | + jsEngine.Execute(updateCode); |
| 492 | + output = jsEngine.Evaluate<string>(input); |
| 493 | + jsEngine.Execute(rollbackCode); |
| 494 | + } |
| 495 | + } |
| 496 | + |
| 497 | + // Assert |
| 498 | + Assert.Equal(targetOutput, output); |
| 499 | + } |
| 500 | + |
| 501 | + #endregion |
| 502 | + |
465 | 503 | #region Types with methods
|
466 | 504 |
|
467 | 505 | [Fact]
|
|
0 commit comments