]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/elide-new-object-dag-then-exit.js
fbe99a5f7db0b54a61fddd450eec13ccfbfcfe43
[apple/javascriptcore.git] / tests / stress / elide-new-object-dag-then-exit.js
1 function sumOfArithSeries(limit) {
2 return limit * (limit + 1) / 2;
3 }
4
5 var n = 10000000;
6
7 function bar() { }
8
9 function verify(q, i) {
10 if (q.f == q.g)
11 throw "Error: q.f == q.g";
12 if (q.f.f != q.g.f)
13 throw "Error: q.f.f != q.g.f";
14 if (q.f.f.f != i)
15 throw "Error: q.f.f.f != i";
16 }
17
18 function foo() {
19 var result = 0;
20 for (var i = 0; i < n; ++i) {
21 var leaf = {f:i};
22 var o = {f:leaf};
23 var p = {f:leaf};
24 var q = {f:o, g:p};
25 result += q.f.f.f;
26 if (i >= n - 100) {
27 // We want the materialization to happen in the exit. So, before calling the thing that
28 // causes the materialization, we call bar(). We've never profiled this call at the time
29 // of FTL compilation, so this should be an exit.
30 bar();
31 verify(q, i);
32 }
33 }
34 return result;
35 }
36
37 noInline(foo);
38 noInline(verify);
39 noInline(bar);
40
41 var result = foo();
42 if (result != sumOfArithSeries(n - 1))
43 throw "Error: bad result: " + result;