test_onGarbageCollection-03.js 602 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Test that the onGarbageCollection hook is not reentrant.
  2. function run_test() {
  3. do_test_pending();
  4. const root = newGlobal();
  5. const dbg = new Debugger();
  6. const wrappedRoot = dbg.addDebuggee(root)
  7. let fired = true;
  8. let depth = 0;
  9. dbg.memory.onGarbageCollection = _ => {
  10. fired = true;
  11. equal(depth, 0);
  12. depth++;
  13. try {
  14. root.eval(`gc()`);
  15. } finally {
  16. equal(depth, 1);
  17. depth--;
  18. }
  19. }
  20. root.eval(`gc()`);
  21. executeSoon(() => {
  22. ok(fired);
  23. equal(depth, 0);
  24. dbg.memory.onGarbageCollection = undefined;
  25. do_test_finished();
  26. });
  27. }