1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --allow-natives-syntax
6
7function test(expected, f) {
8  assertEquals(expected, f());
9  assertEquals(expected, f());
10  %OptimizeFunctionOnNextCall(f);
11  assertEquals(expected, f());
12  assertEquals(expected, f());
13}
14
15function testThrows(f) {
16  assertThrows(f);
17  assertThrows(f);
18  %OptimizeFunctionOnNextCall(f);
19  assertThrows(f);
20  assertThrows(f);
21}
22
23function f1() { return undefined; }
24test(void 0, f1);
25
26function f2() { return void 0; }
27test(void 0, f2);
28
29function f3() { return void 0 == void 0; }
30test(true, f3);
31
32function f4() { return void 0 == undefined; }
33test(true, f4);
34
35function f5() { return undefined == void 0; }
36test(true, f5);
37
38function f6() { return "" + undefined; }
39test("undefined", f6);
40
41function f7() { return void 0 === void 0; }
42test(true, f7);
43
44function f8() { return void 0 === undefined; }
45test(true, f8);
46
47function f9() { return undefined === void 0; }
48test(true, f9);
49
50delete undefined;
51
52function g1() { return undefined; }
53test(void 0, g1);
54
55function g2() { return void 0; }
56test(void 0, g2);
57
58function g3() { return void 0 == void 0; }
59test(true, g3);
60
61function g4() { return void 0 == undefined; }
62test(true, g4);
63
64function g5() { return undefined == void 0; }
65test(true, g5);
66
67function g6() { return "" + undefined; }
68test("undefined", g6);
69
70function g7() { return void 0 === void 0; }
71test(true, g7);
72
73function g8() { return void 0 === undefined; }
74test(true, g8);
75
76function g9() { return undefined === void 0; }
77test(true, g9);
78
79undefined = 111;
80
81function h1() { return undefined; }
82test(void 0, h1);
83
84function h2() { return void 0; }
85test(void 0, h2);
86
87function h3() { return void 0 == void 0; }
88test(true, h3);
89
90function h4() { return void 0 == undefined; }
91test(true, h4);
92
93function h5() { return undefined == void 0; }
94test(true, h5);
95
96function h6() { return "" + undefined; }
97test("undefined", h6);
98
99function h7() { return void 0 === void 0; }
100test(true, h7);
101
102function h8() { return void 0 === undefined; }
103test(true, h8);
104
105function h9() { return undefined === void 0; }
106test(true, h9);
107
108// -------------
109
110function k1() { return this.undefined; }
111test(void 0, k1);
112
113function k2() { return void 0; }
114test(void 0, k2);
115
116function k3() { return void 0 == void 0; }
117test(true, k3);
118
119function k4() { return void 0 == this.undefined; }
120test(true, k4);
121
122function k5() { return this.undefined == void 0; }
123test(true, k5);
124
125function k6() { return "" + this.undefined; }
126test("undefined", k6);
127
128function k7() { return void 0 === void 0; }
129test(true, k7);
130
131function k8() { return void 0 === this.undefined; }
132test(true, k8);
133
134function k9() { return this.undefined === void 0; }
135test(true, k9);
136
137// -------------
138
139function m1() { return undefined.x; }
140testThrows(m1);
141
142function m2() { return undefined.undefined; }
143testThrows(m2);
144
145function m3() { return (void 0).x; }
146testThrows(m3);
147
148function m4() { return (void 0).undefined; }
149testThrows(m4);
150