test_onGarbageCollection-04.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Test that the onGarbageCollection reentrancy guard is on a per Debugger
  2. // basis. That is if our first Debugger is observing our second Debugger's
  3. // compartment, and this second Debugger triggers a GC inside its
  4. // onGarbageCollection hook, the first Debugger's onGarbageCollection hook is
  5. // still called.
  6. //
  7. // This is the scenario we are setting up: top level debugging the `debuggeree`
  8. // global, which is debugging the `debuggee` global. Then, we trigger the
  9. // following events:
  10. //
  11. // debuggee gc
  12. // |
  13. // V
  14. // debuggeree's onGarbageCollection
  15. // |
  16. // V
  17. // debuggeree gc
  18. // |
  19. // V
  20. // top level onGarbageCollection
  21. //
  22. // Note that the top level's onGarbageCollection hook should be fired, at the
  23. // same time that we are preventing reentrancy into debuggeree's
  24. // onGarbageCollection hook.
  25. function run_test() {
  26. do_test_pending();
  27. const debuggeree = newGlobal();
  28. const debuggee = debuggeree.debuggee = newGlobal();
  29. debuggeree.eval(
  30. `
  31. var dbg = new Debugger(this.debuggee);
  32. var fired = 0;
  33. dbg.memory.onGarbageCollection = _ => {
  34. fired++;
  35. gc(this);
  36. };
  37. `
  38. );
  39. const dbg = new Debugger(debuggeree);
  40. let fired = 0;
  41. dbg.memory.onGarbageCollection = _ => {
  42. fired++;
  43. };
  44. debuggee.eval(`gc(this)`);
  45. // Let first onGarbageCollection runnable get run.
  46. executeSoon(() => {
  47. // Let second onGarbageCollection runnable get run.
  48. executeSoon(() => {
  49. // Even though we request GC'ing a single zone, we can't rely on that
  50. // behavior and both zones could have been scheduled for gc for both
  51. // gc(this) calls.
  52. ok(debuggeree.fired >= 1);
  53. ok(fired >= 1);
  54. debuggeree.dbg.enabled = dbg.enabled = false;
  55. do_test_finished();
  56. });
  57. });
  58. }