tor-browser

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

finalizationRegistry-cleanupSome-recursive.js (1112B)


      1 // Test trying to call cleanupSome recursively in callback.
      2 
      3 // This makes the test time out in some configs.
      4 unsetgczeal("CheckHeapBeforeMinorGC");
      5 
      6 // 0: Initial state.
      7 // 1: Attempt recursive calls.
      8 // 2: After recursive calls.
      9 let state = 0;
     10 
     11 let registry = new FinalizationRegistry(x => {
     12  if (state === 0) {
     13    state = 1;
     14    try {
     15      registry.cleanupSome();
     16    } catch (e) {
     17      // Pass the test if any error was thrown.
     18      return;
     19    } finally {
     20      state = 2;
     21    }
     22    throw new Error("expected stack overflow error");
     23  }
     24 
     25  if (state === 1) {
     26    registry.cleanupSome();
     27  }
     28 });
     29 
     30 // Attempt to find the maximum supported stack depth.
     31 var stackSize = 0;
     32 function findStackSize(i) {
     33  try {
     34    stackSize = i;
     35    findStackSize(i + 1);
     36  } catch (e) {
     37    return;
     38  }
     39 }
     40 findStackSize(0);
     41 
     42 // Multiply the calculated stack size by some factor just to be on the safe side.
     43 const exceedStackDepthLimit = stackSize * 5;
     44 
     45 let values = [];
     46 for (let i = 0; i < exceedStackDepthLimit; ++i) {
     47  let v = {};
     48  registry.register(v, i);
     49  values.push(v);
     50 }
     51 values.length = 0;
     52 
     53 gc();
     54 drainJobQueue();