DebugHandlerTests.cs 1.5 KB

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