X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/2d39b0e377c0896910ee49ae70082ba665faf986..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/tests/stress/function-name-scope.js?ds=inline diff --git a/tests/stress/function-name-scope.js b/tests/stress/function-name-scope.js new file mode 100644 index 0000000..a93e60f --- /dev/null +++ b/tests/stress/function-name-scope.js @@ -0,0 +1,40 @@ +function foo() { + return function bar(str) { + var barBefore = bar; + var result = eval(str); + return [ + barBefore, + bar, + function () { + return bar; + }, + result + ]; + } +} + +function check() { + var bar = foo(); + + function verify(result, barAfter, evalResult) { + if (result[0] !== bar) + throw "Error: bad first entry: " + result[0]; + if (result[1] !== barAfter) + throw "Error: bad first entry: " + result[1]; + var subResult = result[2](); + if (subResult !== barAfter) + throw "Error: bad second entry: " + result[2] + "; returned: " + subResult; + if (result[3] !== evalResult) + throw "Error: bad third entry: " + result[3] + "; expected: " + evalResult; + } + + verify(bar("42"), bar, 42); + verify(bar("bar"), bar, bar); + verify(bar("var bar = 42; function fuzz() { return bar; }; fuzz()"), 42, 42); +} + +// Execute check() more than once. At the time that we wrote this regression test, trunk would fail on +// the second execution. Executing 100 times would also gives us some optimizing JIT coverage. +for (var i = 0; i < 100; ++i) + check(); +