test_onGarbageCollection-05.js 892 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Test that the onGarbageCollection hook reports its gc cycle's number (aka the
  2. // major GC number) and that it is monotonically increasing.
  3. const root = newGlobal();
  4. const dbg = new Debugger();
  5. const wrappedRoot = dbg.addDebuggee(root)
  6. function run_test() {
  7. do_test_pending();
  8. let numFired = 0;
  9. let lastGCCycleNumber = undefined;
  10. (function loop() {
  11. if (numFired == 10) {
  12. dbg.memory.onGarbageCollection = undefined;
  13. dbg.enabled = false;
  14. return void do_test_finished();
  15. }
  16. dbg.memory.onGarbageCollection = data => {
  17. print("onGarbageCollection: " + uneval(data));
  18. if (numFired != 0) {
  19. equal(typeof lastGCCycleNumber, "number");
  20. equal(data.gcCycleNumber - lastGCCycleNumber, 1);
  21. }
  22. numFired++;
  23. lastGCCycleNumber = data.gcCycleNumber;
  24. executeSoon(loop);
  25. };
  26. root.eval("gc(this)");
  27. }());
  28. }