blob: 795da371e50910a8c66a8f7f2db372319628dc4d [file] [log] [blame]
<p>This page verifies that eval can be overridden.</p>
<p>If the test passes, you'll see a series of pass messages below.</p>
<pre id="console"></pre>
<hr>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var x = "built-in eval";
function log(s)
{
document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
}
function shouldBe(aDescription, a, b)
{
if (a === b) {
log("PASS: " + aDescription + " should be " + b + " and is.");
} else {
log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
}
}
// Test overriding eval in global scope
eval = function() { return "global-scope eval override"; }
shouldBe('eval("x")', eval("x"), "global-scope eval override");
// Test overriding eval using "with"
with ({ eval: function() { return "with-scope eval override"; }}) {
shouldBe('eval("x")', eval("x"), "with-scope eval override");
}
// Test overriding eval using "catch"
try {
throw function() { return "catch-scope eval override"; };
} catch(eval) {
shouldBe('eval("x")', eval("x"), "catch-scope eval override");
}
// Test overriding eval using locally declared function
(function()
{
function eval() { return "local-scope eval override"; }
shouldBe('eval("x")', eval("x"), "local-scope eval override");
})()
</script>