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
|
<p>This page tests function calls whose argument expressions overwrite the callee.</p>
<p>If the test passes, you'll see PASS messages below.
</p>
<pre id="console"></pre>
<script>
function log(s)
{
document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
}
function shouldBe(aDescription, a, b)
{
if (a === b) {
log("PASS: " + aDescription + " should be " + b + " and is.");
} else {
log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
}
}
function test1(callback, x) {
try {
return callback.apply(this, [ callback = x ]);
} catch(e) {
return e;
}
};
function test2(callback, x) {
try {
return callback(callback = x);
} catch(e) {
return e;
}
};
(function () {
if (window.layoutTestController)
layoutTestController.dumpAsText();
var callback = function callback(x) {
return x;
};
shouldBe("test1(callback, 1)", test1(callback, 1), 1);
shouldBe("test2(callback, 1)", test2(callback, 1), 1);
})();
</script>
|