<p>This page tests function.caller and function.arguments in interesting nested scopes.
</p>
<p>If the test passes, you'll see a series of PASS messages below.
</p>
<pre id="console"></pre>

<script>
function log(s)
{
    document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
}

if (window.layoutTestController)
    layoutTestController.dumpAsText();

function f() { return this.eval('f.arguments instanceof Object ? "PASS" : "FAIL"'); }

var resultArray = [
// ----- arguments -----

// function scope inside global eval scope, uncalled function
(function g() { return this.eval('f.arguments instanceof Object ? "FAIL" : "PASS"'); })(),

// function scope inside local eval scope, uncalled function
(function g() { return eval('f.arguments instanceof Object ? "FAIL" : "PASS"'); })(),

// global eval scope, called function
f(),

// local eval scope, called function
(function f() { return eval('f.arguments instanceof Object ? "PASS" : "FAIL"'); })(),

// eval scope, uncalled function
eval('(function () { }).arguments instanceof Object ? "FAIL" : "PASS"'),

// re-entrant function scope, outer called function
(function f() {
    return String({ toString: function g() { return f.arguments instanceof Object ? "PASS" : "FAIL"; } });
})(),

// re-entrant function scope, inner called function
(function f() {
    return String({ toString: function g() { return g.arguments instanceof Object ? "PASS" : "FAIL"; } });
})(),

// function scope, outer called function
(function f() {
    return (function g() {
        return f.arguments instanceof Object ? "PASS" : "FAIL";
    })();
})(),

// function scope, inner called function
(function f() {
    return (function g() {
        return g.arguments instanceof Object ? "PASS" : "FAIL";
    })();
})(),

// function scope, uncalled function
(function f() {
    return (function g() { }).arguments instanceof Object ? "FAIL" : "PASS";
})(),

// global scope, uncalled function
(function () { }).arguments instanceof Object ? "FAIL" : "PASS",

// ----- caller -----

(function f() {
    return (function g() {
        return g.caller instanceof Object ? "PASS" : "FAIL";
    })();
})(),

(function f() { return f.caller instanceof Object ? "FAIL" : "PASS"; })(),

(function () { }).caller instanceof Object ? "FAIL" : "PASS",

eval('(function f() { return f.caller instanceof Object ? "FAIL" : "PASS"; })()'),

(function f() {
    return String({ toString: function g() { return g.caller instanceof Object ? "FAIL" : "PASS"; } });
})(),

(function f() {
    function g() { return h.apply(this); }
    function h() { return k(); }
    function k() { return k.caller instanceof Object ? "PASS" : "FAIL"; }
    
    return g();
})()
];

log(resultArray);
</script>
