blob: 9a0578a2fb3fe0062b531f1ef8189fa61d9b36d4 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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"use strict";
7
8function test(expected, f) {
9 assertEquals(expected, f());
10 assertEquals(expected, f());
11 %OptimizeFunctionOnNextCall(f);
12 assertEquals(expected, f());
13 assertEquals(expected, f());
14}
15
16function testThrows(f) {
17 assertThrows(f);
18 assertThrows(f);
19 %OptimizeFunctionOnNextCall(f);
20 assertThrows(f);
21 assertThrows(f);
22}
23
24function f1() { return undefined; }
25test(void 0, f1);
26
27function f2() { return void 0; }
28test(void 0, f2);
29
30function f3() { return void 0 == void 0; }
31test(true, f3);
32
33function f4() { return void 0 == undefined; }
34test(true, f4);
35
36function f5() { return undefined == void 0; }
37test(true, f5);
38
39function f6() { return "" + undefined; }
40test("undefined", f6);
41
42function f7() { return void 0 === void 0; }
43test(true, f7);
44
45function f8() { return void 0 === undefined; }
46test(true, f8);
47
48function f9() { return undefined === void 0; }
49test(true, f9);
50
51function g1() { return this; }
52test(void 0, g1);
53
54function g2() { return void 0; }
55test(void 0, g2);
56
57function g3() { return void 0 == void 0; }
58test(true, g3);
59
60function g4() { return void 0 == this; }
61test(true, g4);
62
63function g5() { return this == void 0; }
64test(true, g5);
65
66function g6() { return "" + this; }
67test("undefined", g6);
68
69function g7() { return void 0 === void 0; }
70test(true, g7);
71
72function g8() { return void 0 === this; }
73test(true, g8);
74
75function g9() { return this === void 0; }
76test(true, g9);
77
78testThrows(function() { undefined = 111; });
79
80function h1() { return undefined; }
81test(void 0, h1);
82
83function h2() { return void 0; }
84test(void 0, h2);
85
86function h3() { return void 0 == void 0; }
87test(true, h3);
88
89function h4() { return void 0 == undefined; }
90test(true, h4);
91
92function h5() { return undefined == void 0; }
93test(true, h5);
94
95function h6() { return "" + undefined; }
96test("undefined", h6);
97
98function h7() { return void 0 === void 0; }
99test(true, h7);
100
101function h8() { return void 0 === undefined; }
102test(true, h8);
103
104function h9() { return undefined === void 0; }
105test(true, h9);
106
107// -------------
108
109function k1() { return this; }
110test(void 0, k1);
111
112function k2() { return void 0; }
113test(void 0, k2);
114
115function k3() { return this === undefined; }
116test(true, k3);
117
118function k4() { return void 0 === this; }
119test(true, k4);
120
121function k5() { return this === void 0; }
122test(true, k5);
123
124function k6() { return "" + this; }
125test("undefined", k6);
126
127function k7() { return void 0 === void 0; }
128test(true, k7);
129
130function k8() { return void 0 === this; }
131test(true, k8);
132
133function k9() { return this === void 0; }
134test(true, k9);
135
136// -------------
137
138function m1() { return this.undefined; }
139testThrows(m1);
140
141function m2() { return void 0; }
142test(void 0, m2);
143
144function m3() { return this === undefined; }
145test(true, m3);
146
147function m4() { return void 0 === this.undefined; }
148testThrows(m4);
149
150function m5() { return this.undefined == void 0; }
151testThrows(m5);
152
153function m6() { return "" + this.undefined; }
154testThrows(m6);
155
156function m7() { return void 0 === void 0; }
157test(true, m7);
158
159function m8() { return void 0 === this.undefined; }
160testThrows(m8);
161
162function m9() { return this.undefined === void 0; }
163testThrows(m9);