1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
<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>
|