summaryrefslogtreecommitdiffstats
path: root/js/src/devtools/gc-ubench/benchmarks/selfCyclicWeakMap.js
blob: 0a5ffb08463c61e887ad8e2b369c06818d6d6b06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
window.tests.set('selfCyclicWeakMap', (function() {
var garbage = [];
var garbageIndex = 0;
return {
    description: "var wm = new WeakMap(); wm[k1] = k2; wm[k2] = k3; ...",

    defaultGarbagePerFrame: "1K",
    defaultGarbageTotal: "1K",

    load: (N) => { garbage = new Array(N); },

    unload: () => { garbage = []; garbageIndex = 0; },

    makeGarbage: (M) => {
        var wm = new WeakMap();
        var initialKey = {};
        var key = initialKey;
        var value = {};
        for (var i = 0; i < M; i++) {
            wm.set(key, value);
            key = value;
            value = {};
        }
        garbage[garbageIndex++] = [ initialKey, wm ];
        if (garbageIndex == garbage.length)
            garbageIndex = 0;
    }
};
})());