tor-browser

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

pairCyclicWeakMap.js (1155B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 tests.set(
      6  "pairCyclicWeakMap",
      7  (function() {
      8    var garbage = [];
      9    var garbageIndex = 0;
     10    return {
     11      description: "wm1[k1] = k2; wm2[k2] = k3; wm1[k3] = k4; wm2[k4] = ...",
     12 
     13      defaultGarbagePerFrame: "10K",
     14      defaultGarbagePiles: "1K",
     15 
     16      load: N => {
     17        garbage = new Array(N);
     18      },
     19 
     20      unload: () => {
     21        garbage = [];
     22        garbageIndex = 0;
     23      },
     24 
     25      makeGarbage: M => {
     26        var wm1 = new WeakMap();
     27        var wm2 = new WeakMap();
     28        var initialKey = {};
     29        var key = initialKey;
     30        var value = {};
     31        for (var i = 0; i < M / 2; i++) {
     32          wm1.set(key, value);
     33          key = value;
     34          value = {};
     35          wm2.set(key, value);
     36          key = value;
     37          value = {};
     38        }
     39        garbage[garbageIndex++] = [initialKey, wm1, wm2];
     40        if (garbageIndex == garbage.length) {
     41          garbageIndex = 0;
     42        }
     43      },
     44    };
     45  })()
     46 );