Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / var-declarations.html
blobe5d884b3bada7d653c32dcd11053b88e7c0b7622
1 <p>This page tests var 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 vars = [
32 "v1",
33 "v2",
34 "v3",
35 "v4",
36 "v5",
37 "v6",
38 "v7",
39 "v8",
40 "v9"
43 log(title);
44 log("-----");
45 for (var i = 0; i < vars.length; ++i)
46 shouldBe("'" + vars[i] + "' in window", true);
49 testDeclarations("Before executing blocks containing var declarations: ");
52 var v1;
55 if (false) {
56 var v2;
59 switch (true) {
60 case true: {
61 var v3;
62 break;
64 case false: {
65 var v4;
66 break;
70 for (var i = 0; i < 0; ++i) {
71 var v5;
74 do {
75 var v6;
76 } while(0);
78 while (0) {
79 var v7;
82 for (var p in {}) {
83 var v8;
86 with ({}) {
87 var v9;
90 log("");
91 testDeclarations("After executing blocks containing var declarations: ");
93 </script>