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