Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / function-argument-evaluation.html
blob3d4f675daf8e567589c26aa995f9bfd9a3cc1187
1 <p>This page tests function calls whose argument expressions overwrite the callee.</p>
2 <p>If the test passes, you'll see PASS messages below.
3 </p>
4 <pre id="console"></pre>
6 <script>
7 function log(s)
9 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
12 function shouldBe(aDescription, a, b)
14 if (a === b) {
15 log("PASS: " + aDescription + " should be " + b + " and is.");
16 } else {
17 log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
21 function test1(callback, x) {
22 try {
23 return callback.apply(this, [ callback = x ]);
24 } catch(e) {
25 return e;
29 function test2(callback, x) {
30 try {
31 return callback(callback = x);
32 } catch(e) {
33 return e;
37 (function () {
38 if (window.testRunner)
39 testRunner.dumpAsText();
41 var callback = function callback(x) {
42 return x;
45 shouldBe("test1(callback, 1)", test1(callback, 1), 1);
46 shouldBe("test2(callback, 1)", test2(callback, 1), 1);
47 })();
48 </script>