]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/load-varargs-elimination-bounds-check-barely.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / load-varargs-elimination-bounds-check-barely.js
CommitLineData
ed1e77d3
A
1function foo() {
2 var result = 0;
3 for (var i = 0; i < arguments.length; ++i)
4 result += arguments[i];
5 return result;
6}
7
8function bar() {
9 return foo.apply(this, arguments);
10}
11
12function baz(p) {
13 if (p)
14 return bar(1, 42);
15 return 0;
16}
17
18noInline(baz);
19
20// Execute baz() once with p set, so that the call has a valid prediction.
21baz(true);
22
23// Warm up profiling in bar and foo. Convince this profiling that bar()'s varargs call will tend to
24// pass a small number of arguments;
25for (var i = 0; i < 1000; ++i)
26 bar(1);
27
28// Now compile baz(), but don't run the bad code yet.
29for (var i = 0; i < 10000; ++i)
30 baz(false);
31
32// Finally, trigger the bug.
33var result = baz(true);
34if (result != 43)
35 throw "Error: bad result: " + result;