DebugHandlerTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Jint.Native.Object;
  2. using Jint.Runtime.Debugger;
  3. using Xunit;
  4. #pragma warning disable 618
  5. namespace Jint.Tests.Runtime.Debugger
  6. {
  7. public class DebugHandlerTests
  8. {
  9. [Fact]
  10. public void AvoidsPauseRecursion()
  11. {
  12. // While the DebugHandler is in a paused state, it shouldn't relay further OnStep calls to Break/Step.
  13. // Such calls would occur e.g. if Step/Break event handlers evaluate accessors. Failing to avoid
  14. // reentrance in a multithreaded environment (e.g. using ManualResetEvent(Slim)) would cause
  15. // a deadlock.
  16. string script = @"
  17. const obj = { get name() { 'fail'; return 'Smith'; } };
  18. 'target';
  19. ";
  20. var engine = new Engine(options => options.DebugMode());
  21. bool didPropertyAccess = false;
  22. engine.DebugHandler.Step += (sender, info) =>
  23. {
  24. // We should never reach "fail", because the only way it's executed is from
  25. // within this Step handler
  26. Assert.False(info.ReachedLiteral("fail"));
  27. if (info.ReachedLiteral("target"))
  28. {
  29. var obj = info.CurrentScopeChain.Global.GetBindingValue("obj") as ObjectInstance;
  30. var prop = obj.GetOwnProperty("name");
  31. // This is where reentrance would occur:
  32. var value = prop.Get.Invoke(engine);
  33. didPropertyAccess = true;
  34. }
  35. return StepMode.Into;
  36. };
  37. engine.Execute(script);
  38. Assert.True(didPropertyAccess);
  39. }
  40. }
  41. }