Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / jit-test / tests / basic / testBug597736.js
1 function leak_test() {
2     // Create a reference loop function->script->traceFragment->object->function
3     // that GC must be able to break. To embedd object into the fragment the
4     // code use prototype chain of depth 2 which caches obj.__proto__.__proto__
5     // into the fragment.
6
7     // To make sure that we have no references to the function f after this
8     // function returns due via the conservative scan of the native stack we
9     // loop here multiple times overwriting the stack and registers with new garabge.
10     for (var j = 0; j != 8; ++j) {
11         var f = Function("a", "var s = 0; for (var i = 0; i != 100; ++i) s += a.b; return s;");
12         var c = {b: 1, f: f, leakDetection: makeFinalizeObserver()};
13         f({ __proto__: { __proto__: c}});
14         f = c = a = null;
15         gc();
16     }
17 }
18
19 function test()
20 {
21     if (typeof finalizeCount != "function")
22         return;
23
24     var base = finalizeCount();
25     leak_test();
26     gc();
27     gc();
28     var n = finalizeCount();
29     assertEq(base + 4 < finalizeCount(), true, "Some finalizations must happen");
30 }
31
32 test();