summaryrefslogtreecommitdiff
path: root/js/src/jit-test/tests/basic/testBug597736.js
blob: ded33842776f8512f5c8d6a72252779ae8a8716e (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
30
31
32
function leak_test() {
    // Create a reference loop function->script->traceFragment->object->function
    // that GC must be able to break. To embedd object into the fragment the
    // code use prototype chain of depth 2 which caches obj.__proto__.__proto__
    // into the fragment.

    // To make sure that we have no references to the function f after this
    // function returns due via the conservative scan of the native stack we
    // loop here multiple times overwriting the stack and registers with new garabge.
    for (var j = 0; j != 8; ++j) {
	var f = Function("a", "var s = 0; for (var i = 0; i != 100; ++i) s += a.b; return s;");
	var c = {b: 1, f: f, leakDetection: makeFinalizeObserver()};
	f({ __proto__: { __proto__: c}});
	f = c = a = null;
	gc();
    }
}

function test()
{
    if (typeof finalizeCount != "function")
	return;

    var base = finalizeCount();
    leak_test();
    gc();
    gc();
    var n = finalizeCount();
    assertEq(base + 4 < finalizeCount(), true, "Some finalizations must happen");
}

test();