DebugHandlerTests.cs 1.7 KB

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