blob: 34e3fdd14f28b4bf6ddc1223f1835d107a91c12d [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2013 the V8 project authors. All rights reserved.
2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7// 1. Redistributions of source code must retain the above copyright
8// notice, this list of conditions and the following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
Ben Murdochda12d292016-06-02 14:46:10 +010024// Flags: --no-harmony-restrictive-declarations
25
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026description(
27"This test checks that function declarations are treated as statements."
28);
29
30function f()
31{
32 return false;
33}
34
35function ifTest()
36{
37 if (true)
38 function f()
39 {
40 return true;
41 }
42
43 return f();
44}
45
46shouldBeTrue("ifTest()");
47
48function ifElseTest()
49{
50 if (false)
51 return false;
52 else
53 function f()
54 {
55 return true;
56 }
57
58 return f();
59}
60
61shouldBeTrue("ifElseTest()");
62
63function doWhileTest()
64{
65 var i = 0;
66 do
67 function f()
68 {
69 return true;
70 }
71 while (i++ < 10)
72
73 return f();
74}
75
76shouldBeTrue("doWhileTest()");
77
78function whileTest()
79{
80 var i = 0;
81 while (i++ < 10)
82 function f()
83 {
84 return true;
85 }
86
87 return f();
88}
89
90shouldBeTrue("whileTest()");
91
92function forTest()
93{
94 var i;
95 for (i = 0; i < 10; ++i)
96 function f()
97 {
98 return true;
99 }
100
101 return f();
102}
103
104shouldBeTrue("forTest()");
105
106function forVarTest()
107{
108 for (var i = 0; i < 10; ++i)
109 function f()
110 {
111 return true;
112 }
113
114 return f();
115}
116
117shouldBeTrue("forVarTest()");
118
119function forInTest()
120{
121 var a;
122 for (a in { field: false })
123 function f()
124 {
125 return true;
126 }
127
128 return f();
129}
130
131shouldBeTrue("forInTest()");
132
133function forInVarTest()
134{
135 var a;
136 for (var a in { field: false })
137 function f()
138 {
139 return true;
140 }
141
142 return f();
143}
144
145shouldBeTrue("forInVarTest()");
146
147function forInVarInitTest()
148{
149 var a;
150 for (var a = false in { field: false })
151 function f()
152 {
153 return true;
154 }
155
156 return f();
157}
158
159shouldBeTrue("forInVarInitTest()");
160
161function withTest()
162{
163 with ({ })
164 function f()
165 {
166 return true;
167 }
168
169 return f();
170}
171
172shouldBeTrue("withTest()");
173
174function labelTest()
175{
176 label:
177 function f()
178 {
179 return true;
180 }
181
182 return f();
183}
184
185shouldBeTrue("labelTest()");