1 // 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 24 description( 25 "This test checks that function declarations are treated as statements." 26 ); 27 28 function f() 29 { 30 return false; 31 } 32 33 function ifTest() 34 { 35 if (true) 36 function f() 37 { 38 return true; 39 } 40 41 return f(); 42 } 43 44 shouldBeTrue("ifTest()"); 45 46 function ifElseTest() 47 { 48 if (false) 49 return false; 50 else 51 function f() 52 { 53 return true; 54 } 55 56 return f(); 57 } 58 59 shouldBeTrue("ifElseTest()"); 60 61 function doWhileTest() 62 { 63 var i = 0; 64 do 65 function f() 66 { 67 return true; 68 } 69 while (i++ < 10) 70 71 return f(); 72 } 73 74 shouldBeTrue("doWhileTest()"); 75 76 function whileTest() 77 { 78 var i = 0; 79 while (i++ < 10) 80 function f() 81 { 82 return true; 83 } 84 85 return f(); 86 } 87 88 shouldBeTrue("whileTest()"); 89 90 function forTest() 91 { 92 var i; 93 for (i = 0; i < 10; ++i) 94 function f() 95 { 96 return true; 97 } 98 99 return f(); 100 } 101 102 shouldBeTrue("forTest()"); 103 104 function forVarTest() 105 { 106 for (var i = 0; i < 10; ++i) 107 function f() 108 { 109 return true; 110 } 111 112 return f(); 113 } 114 115 shouldBeTrue("forVarTest()"); 116 117 function forInTest() 118 { 119 var a; 120 for (a in { field: false }) 121 function f() 122 { 123 return true; 124 } 125 126 return f(); 127 } 128 129 shouldBeTrue("forInTest()"); 130 131 function forInVarTest() 132 { 133 var a; 134 for (var a in { field: false }) 135 function f() 136 { 137 return true; 138 } 139 140 return f(); 141 } 142 143 shouldBeTrue("forInVarTest()"); 144 145 function forInVarInitTest() 146 { 147 var a; 148 for (var a = false in { field: false }) 149 function f() 150 { 151 return true; 152 } 153 154 return f(); 155 } 156 157 shouldBeTrue("forInVarInitTest()"); 158 159 function withTest() 160 { 161 with ({ }) 162 function f() 163 { 164 return true; 165 } 166 167 return f(); 168 } 169 170 shouldBeTrue("withTest()"); 171 172 function labelTest() 173 { 174 label: 175 function f() 176 { 177 return true; 178 } 179 180 return f(); 181 } 182 183 shouldBeTrue("labelTest()"); 184