]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/function-name-scope.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / function-name-scope.js
CommitLineData
ed1e77d3
A
1function foo() {
2 return function bar(str) {
3 var barBefore = bar;
4 var result = eval(str);
5 return [
6 barBefore,
7 bar,
8 function () {
9 return bar;
10 },
11 result
12 ];
13 }
14}
15
16function check() {
17 var bar = foo();
18
19 function verify(result, barAfter, evalResult) {
20 if (result[0] !== bar)
21 throw "Error: bad first entry: " + result[0];
22 if (result[1] !== barAfter)
23 throw "Error: bad first entry: " + result[1];
24 var subResult = result[2]();
25 if (subResult !== barAfter)
26 throw "Error: bad second entry: " + result[2] + "; returned: " + subResult;
27 if (result[3] !== evalResult)
28 throw "Error: bad third entry: " + result[3] + "; expected: " + evalResult;
29 }
30
31 verify(bar("42"), bar, 42);
32 verify(bar("bar"), bar, bar);
33 verify(bar("var bar = 42; function fuzz() { return bar; }; fuzz()"), 42, 42);
34}
35
36// Execute check() more than once. At the time that we wrote this regression test, trunk would fail on
37// the second execution. Executing 100 times would also gives us some optimizing JIT coverage.
38for (var i = 0; i < 100; ++i)
39 check();
40