tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

S12.14_A12_T3.js (2545B)


      1 // Copyright 2009 the Sputnik authors.  All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 info: |
      6    Using "try" with "catch" or "finally" statement within/without a "for-in"
      7    statement
      8 es5id: 12.14_A12_T3
      9 description: Try statement inside loop, where use break
     10 ---*/
     11 
     12 var x;
     13 var mycars = new Array();
     14 mycars[0] = "Saab";
     15 mycars[1] = "Volvo";
     16 mycars[2] = "BMW";
     17 
     18 // CHECK#1
     19 var c1=0,fin=0;
     20 for (x in mycars){
     21  try{
     22    c1+=1;
     23    break;
     24  }
     25  catch(er1){
     26    c1+=1;
     27  }
     28  finally{
     29    fin=1;
     30  }
     31  fin=-1;
     32  c1+=2;
     33 };
     34 if(fin!==1){
     35  throw new Test262Error('#1.1: "finally" block must be evaluated');
     36 }
     37 if(c1!==1){
     38  throw new Test262Error('#1.2: "try{break}catch finally" must work correctly');
     39 }
     40 
     41 // CHECK#2
     42 var c2=0,fin2=0;
     43 for (x in mycars){
     44  try{
     45    throw "ex1";
     46  }
     47  catch(er1){
     48    c2+=1;
     49    break;
     50  }
     51  finally{
     52    fin2=1;
     53  }
     54  c2+=2;
     55  fin2=-1;
     56 }
     57 if(fin2!==1){
     58  throw new Test262Error('#2.1: "finally" block must be evaluated');
     59 }
     60 if(c2!==1){
     61  throw new Test262Error('#2.2: "try catch{break} finally" must work correctly');
     62 }
     63 
     64 // CHECK#3
     65 var c3=0,fin3=0;
     66 for (x in mycars){
     67  try{
     68    throw "ex1";
     69  }
     70  catch(er1){
     71    c3+=1;
     72  }
     73  finally{
     74    fin3=1;
     75    break;
     76  }
     77  c3+=2;
     78  fin3=0;
     79 }
     80 if(fin3!==1){
     81  throw new Test262Error('#3.1: "finally" block must be evaluated');
     82 }
     83 if(c3!==1){
     84  throw new Test262Error('#3.2: "try catch finally{break}" must work correctly');
     85 }
     86 
     87 // CHECK#4
     88 var c4=0,fin4=0;
     89 for (x in mycars){
     90  try{
     91    c4+=1;
     92    break;
     93  }
     94  finally{
     95    fin4=1;
     96  }
     97  fin4=-1;
     98  c4+=2;
     99 }
    100 if(fin4!==1){
    101  throw new Test262Error('#4.1: "finally" block must be evaluated');
    102 }
    103 if(c4!==1){
    104  throw new Test262Error('#4.2: "try{break} finally" must work correctly');
    105 }
    106 
    107 // CHECK#5
    108 var c5=0;
    109 for (x in mycars){
    110  try{
    111    throw "ex1";
    112    c5++;
    113  }
    114  catch(er1){
    115    break;
    116    c5++;
    117  }
    118  c5++;
    119 }
    120 if(c5!==0){
    121  throw new Test262Error('#5: "try catch{break}" must work correctly');
    122 }
    123 
    124 // CHECK#6
    125 var c6=0;
    126 for (x in mycars){
    127  try{
    128    c6+=1;
    129    break;
    130  }
    131  catch(er1){}
    132  c6+=2;
    133 }
    134 if(c6!==1){
    135  throw new Test262Error('#6: "try{break} catch" must work correctly');
    136 }
    137 
    138 // CHECK#7
    139 var c7=0,fin7=0;
    140 try{
    141  for (x in mycars){
    142    try{
    143      c7+=1;
    144      throw "ex1";
    145    }
    146    finally{
    147      fin7=1;
    148      break;
    149    }
    150    fin7=-1;
    151    c7+=2;
    152  }
    153 }
    154 catch(ex1){
    155  c7=10;
    156 }
    157 if(fin7!==1){
    158  throw new Test262Error('#7.1: "finally" block must be evaluated');
    159 }
    160 if(c7!==1){
    161  throw new Test262Error('#7.2: "try finally{break}" must work correctly');
    162 }
    163 
    164 reportCompare(0, 0);