tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_onGarbageCollection-02.js (2518B)


      1 // Test multiple debuggers, GCs, and zones interacting with each other.
      2 //
      3 // Note: when observing both globals, but GC'ing in only one, we don't test that
      4 // we *didn't* GC in the other zone because GCs are finicky and unreliable. That
      5 // used to work when this was a jit-test, but in the process of migrating to
      6 // xpcshell, we lost some amount of reliability and determinism.
      7 
      8 const root1 = newGlobal();
      9 const dbg1 = new Debugger();
     10 dbg1.addDebuggee(root1)
     11 
     12 const root2 = newGlobal();
     13 const dbg2 = new Debugger();
     14 dbg2.addDebuggee(root2)
     15 
     16 let fired1 = false;
     17 let fired2 = false;
     18 dbg1.memory.onGarbageCollection = _ => fired1 = true;
     19 dbg2.memory.onGarbageCollection = _ => fired2 = true;
     20 
     21 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
     22 registerCleanupFunction(() => {
     23  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
     24 });
     25 
     26 function reset() {
     27  fired1 = false;
     28  fired2 = false;
     29 }
     30 
     31 function run_test() {
     32  do_test_pending();
     33 
     34  gc();
     35  executeSoon(() => {
     36    reset();
     37 
     38    // GC 1 only
     39    root1.eval(`gc(this)`);
     40    executeSoon(() => {
     41      equal(fired1, true);
     42 
     43      // GC 2 only
     44      reset();
     45      root2.eval(`gc(this)`);
     46      executeSoon(() => {
     47        equal(fired2, true);
     48 
     49        // Full GC
     50        reset();
     51        gc();
     52        executeSoon(() => {
     53          equal(fired1, true);
     54          equal(fired2, true);
     55 
     56          // Full GC with no debuggees
     57          reset();
     58          dbg1.removeAllDebuggees();
     59          dbg2.removeAllDebuggees();
     60          gc();
     61          executeSoon(() => {
     62            equal(fired1, false);
     63            equal(fired2, false);
     64 
     65            // One debugger with multiple debuggees in different zones.
     66 
     67            dbg1.addDebuggee(root1);
     68            dbg1.addDebuggee(root2);
     69 
     70            // Just debuggee 1
     71            reset();
     72            root1.eval(`gc(this)`);
     73            executeSoon(() => {
     74              equal(fired1, true);
     75              equal(fired2, false);
     76 
     77              // Just debuggee 2
     78              reset();
     79              root2.eval(`gc(this)`);
     80              executeSoon(() => {
     81                equal(fired1, true);
     82                equal(fired2, false);
     83 
     84                // All debuggees
     85                reset();
     86                gc();
     87                executeSoon(() => {
     88                  equal(fired1, true);
     89                  equal(fired2, false);
     90                  do_test_finished();
     91                });
     92              });
     93            });
     94          });
     95        });
     96      });
     97    });
     98  });
     99 }