Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / function-declarations.html
blob7e001b4aed1dcf446246658ff2773cbf2f7fc6eb
1 <p>This page tests function declarations inside various block structures and control statements.</pre>
2 <pre id="console"></pre>
4 <script>
5 if (window.testRunner)
6 testRunner.dumpAsText();
8 function log(s)
10 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
13 function shouldBe(a, b)
15 var evalA;
16 try {
17 evalA = eval(a);
18 } catch (e) {
19 evalA = e;
22 if (evalA === b) {
23 log("PASS: " + a + " should be " + b + " and is.");
24 } else {
25 log("FAIL: " + a + " should be " + b + " but instead is " + evalA + ".");
29 function testDeclarations(title)
31 var functions = [
32 "f1",
33 "f2",
34 "f3",
35 "f4",
36 "f5",
37 "f6",
38 "f7",
39 "f8",
40 "f9"
43 log(title);
44 log("-----");
45 for (var i = 0; i < functions.length; ++i)
46 shouldBe("'" + functions[i] + "' in window", true);
49 testDeclarations("Before executing blocks containing function declarations: ");
52 function f1() {}
55 if (false) {
56 function f2() {}
59 switch (true) {
60 case true: {
61 function f3() {}
62 break;
64 case false: {
65 function f4() {}
66 break;
70 for (var i = 0; i < 0; ++i) {
71 function f5() {}
74 do {
75 function f6() {}
76 } while(0);
78 while (0) {
79 function f7() {}
82 for (var p in {}) {
83 function f8() {}
86 with ({}) {
87 function f9() {}
90 log("");
91 testDeclarations("After executing blocks containing function declarations: ");
93 </script>