Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / eval-overriding.html
blob795da371e50910a8c66a8f7f2db372319628dc4d
1 <p>This page verifies that eval can be overridden.</p>
2 <p>If the test passes, you'll see a series of pass messages below.</p>
3 <pre id="console"></pre>
4 <hr>
6 <script>
7 if (window.testRunner)
8 testRunner.dumpAsText();
10 var x = "built-in eval";
12 function log(s)
14 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
17 function shouldBe(aDescription, a, b)
19 if (a === b) {
20 log("PASS: " + aDescription + " should be " + b + " and is.");
21 } else {
22 log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
26 // Test overriding eval in global scope
27 eval = function() { return "global-scope eval override"; }
28 shouldBe('eval("x")', eval("x"), "global-scope eval override");
30 // Test overriding eval using "with"
31 with ({ eval: function() { return "with-scope eval override"; }}) {
32 shouldBe('eval("x")', eval("x"), "with-scope eval override");
35 // Test overriding eval using "catch"
36 try {
37 throw function() { return "catch-scope eval override"; };
38 } catch(eval) {
39 shouldBe('eval("x")', eval("x"), "catch-scope eval override");
42 // Test overriding eval using locally declared function
43 (function()
45 function eval() { return "local-scope eval override"; }
46 shouldBe('eval("x")', eval("x"), "local-scope eval override");
47 })()
48 </script>