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 24description("KDE JS Test"); 25var myvar = 1; 26 27function varInFunction() { 28 return (myvar == undefined); 29 var myvar = 2; 30} 31 32function varInVarList() { 33 return (myvar == undefined); 34 var a = 1, b = 0, myvar = 2; 35} 36 37function varListOrder() { 38 var tmp = 0; 39 var i = ++tmp, j = ++tmp; 40 return j == 2; 41} 42 43function varInBlock() { 44 return (myvar == undefined); 45 { 46 var myvar = 2; 47 } 48} 49 50function varInIf() { 51 return (myvar == undefined); 52 if (false) 53 var myvar = 2; 54} 55 56function varInElse() { 57 return (myvar == undefined); 58 if (true) { 59 } 60 else 61 var myvar = 2; 62} 63 64function varInDoWhile() { 65 return (myvar == undefined); 66 do 67 var myvar = 2; 68 while (false); 69} 70 71function varInWhile() { 72 return (myvar == undefined); 73 while (false) 74 var myvar = 2; 75} 76 77function varInFor() { 78 return (myvar == undefined); 79 var i; 80 for (i = 0; i < 0; i++) 81 var myvar = 2; 82} 83 84function varInForInitExpr() { 85 return (myvar == undefined); 86 for (var myvar = 2; i < 2; i++) { 87 } 88} 89 90function varInForIn() { 91 return (myvar == undefined); 92 var o = new Object(); 93 var i; 94 for (i in o) 95 var myvar = 2; 96} 97 98function varInWith() { 99 return (myvar == undefined); 100 with (String) 101 var myvar = 2; 102} 103 104function varInCase() { 105 return (myvar == undefined); 106 switch (1) { 107 case 0: 108 var myvar = 2; 109 case 1: 110 } 111} 112 113function varInLabel() { 114 return (myvar == undefined); 115label1: 116 var myvar = 2; 117} 118 119function varInCatch() { 120 return (myvar == undefined); 121 try { 122 } 123 catch (e) { 124 var myvar = 2; 125 } 126} 127 128function varInFinally() { 129 return (myvar == undefined); 130 try { 131 } 132 finally { 133 var myvar = 2; 134 } 135} 136 137function varInTry() { 138 return (myvar == undefined); 139 try { 140 var myvar = 2; 141 } 142 catch (e) { 143 } 144 finally { 145 } 146} 147 148function varInSubFunction() { 149 return (myvar == 1); 150 function subfunction() { 151 var myvar = 2; 152 } 153} 154 155if (!varGlobal) 156 var varGlobal = 1; 157 158shouldBe("varInFunction()","true"); 159shouldBe("varInVarList()","true"); 160shouldBe("varListOrder()","true"); 161shouldBe("varInBlock()","true"); 162shouldBe("varInIf()","true"); 163shouldBe("varInElse()","true"); 164shouldBe("varInDoWhile()","true"); 165shouldBe("varInWhile()","true"); 166shouldBe("varInFor()","true"); 167shouldBe("varInForIn()","true"); 168shouldBe("varInWith()","true"); 169shouldBe("varInCase()","true"); 170shouldBe("varInLabel()","true"); 171shouldBe("varInCatch()","true"); 172shouldBe("varInFinally()","true"); 173shouldBe("varInTry()","true"); 174shouldBe("varInForInitExpr()","true"); 175shouldBe("varInSubFunction()","true"); 176shouldBe("varGlobal", "1"); 177 178var overrideVar = 1; 179var overrideVar; 180shouldBe("overrideVar", "1"); 181 182var overrideVar2 = 1; 183var overrideVar2 = 2; 184shouldBe("overrideVar2", "2"); 185