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