| <p>This page tests the evaluated value of a while expression.</p> | |
| <pre id="console"></pre> | |
| <script> | |
| if (window.testRunner) | |
| testRunner.dumpAsText(); | |
| function log(s) | |
| { | |
| document.getElementById("console").appendChild(document.createTextNode(s + "\n")); | |
| } | |
| function shouldBe(a, b) | |
| { | |
| var evalA; | |
| try { | |
| evalA = eval(a); | |
| } catch(e) { | |
| evalA = e; | |
| } | |
| if (evalA === b) { | |
| log("PASS: " + a + " should be " + b + " and is."); | |
| } else { | |
| log("FAIL: " + a + " should be " + b + " but instead is " + evalA + "."); | |
| } | |
| } | |
| var x, condition; | |
| condition = true; | |
| x = eval("while (condition) { condition = false; 1; }"); | |
| shouldBe("x", 1); | |
| condition = true; | |
| var x = eval("while (condition) { condition = false; 1; break; }"); | |
| shouldBe("x", 1); | |
| condition = true; | |
| var x = eval("while (condition) { condition = false; 1; continue; }"); | |
| shouldBe("x", 1); | |
| condition = true; | |
| var x = eval("while (condition) { condition = false; 1; ; }"); | |
| shouldBe("x", 1); | |
| </script> |