Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / function-name-is-in-scope.html
blobb5890ad5a49219cc117701645718abfca120f53a
1 <p>This tests verifies the scope of a function's name.
2 </p>
3 <pre id="console"></pre>
5 <script>
6 function log(s)
8 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
11 function shouldBe(a, aDescription, b)
13 if (a == b) {
14 log("PASS: " + aDescription + " should be " + b + " and is.");
15 return;
17 log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
20 if (window.testRunner) {
21 testRunner.dumpAsText();
24 // Function declarations do not put the function's name in scope.
25 function f()
27 shouldBe(
28 f.name == 'f',
29 "f.name == 'f'",
30 true
33 f = 1;
34 shouldBe(
35 f == 1,
36 "f == 1",
37 true
41 f();
43 // Function expressions do put the function's name in scope, as a read-only property.
44 var g = function g()
46 shouldBe(
47 g.name == 'g',
48 "g.name == 'g'",
49 true
52 g = 1;
53 shouldBe(
54 g == arguments.callee,
55 "g == arguments.callee",
56 true
60 g();
62 </script>