blob: 7e001b4aed1dcf446246658ff2773cbf2f7fc6eb [file] [log] [blame]
<p>This page tests function declarations inside various block structures and control statements.</pre>
<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 + ".");
}
}
function testDeclarations(title)
{
var functions = [
"f1",
"f2",
"f3",
"f4",
"f5",
"f6",
"f7",
"f8",
"f9"
];
log(title);
log("-----");
for (var i = 0; i < functions.length; ++i)
shouldBe("'" + functions[i] + "' in window", true);
}
testDeclarations("Before executing blocks containing function declarations: ");
{
function f1() {}
}
if (false) {
function f2() {}
}
switch (true) {
case true: {
function f3() {}
break;
}
case false: {
function f4() {}
break;
}
}
for (var i = 0; i < 0; ++i) {
function f5() {}
}
do {
function f6() {}
} while(0);
while (0) {
function f7() {}
}
for (var p in {}) {
function f8() {}
}
with ({}) {
function f9() {}
}
log("");
testDeclarations("After executing blocks containing function declarations: ");
</script>