summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/function-name-is-in-scope.html
blob: b5890ad5a49219cc117701645718abfca120f53a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<p>This tests verifies the scope of a function's name.
</p>
<pre id="console"></pre>

<script>
function log(s)
{
	document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
}

function shouldBe(a, aDescription, b)
{
	if (a == b) {
		log("PASS: " + aDescription + " should be " + b + " and is.");
		return;
	}
	log("FAIL: " + aDescription + " should be " + b + " but instead is " + a + ".");
}

if (window.testRunner) {
	testRunner.dumpAsText();
}

// Function declarations do not put the function's name in scope.
function f()
{
	shouldBe(
		f.name == 'f',
		"f.name == 'f'",
		true
	);

	f = 1;
	shouldBe(
		f == 1,
		"f == 1",
		true
	);
};

f();

// Function expressions do put the function's name in scope, as a read-only property.
var g = function g()
{
	shouldBe(
		g.name == 'g',
		"g.name == 'g'",
		true
	);

	g = 1;
	shouldBe(
		g == arguments.callee,
		"g == arguments.callee",
		true
	);
};

g();

</script>