summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/ch12/12.14/S12.14_A14.js
blob: af2177a0594645562ea6c47a8f4902c09f986e57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2009 the Sputnik authors.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
 * Using "try" with "catch" or "finally" statement within/without a "with" statement
 *
 * @path ch12/12.14/S12.14_A14.js
 * @description Using try/catch/finally in With and With in try/catch/finally
 * @noStrict
 */

var myObj = {p1: 'a',
             p2: 'b',
             p3: 'c',
             value: 'myObj_value',
             valueOf : function(){return 'obj_valueOf';},
             parseInt : function(){return 'obj_parseInt';},
             NaN : 'obj_NaN',
             Infinity : 'obj_Infinity',
             eval     : function(){return 'obj_eval';},
             parseFloat : function(){return 'obj_parseFloat';},
             isNaN      : function(){return 'obj_isNaN';},
             isFinite   : function(){return 'obj_isFinite';}
}

// CHECK#1
try{
  with(myObj){
    throw "ex";
  }
}
catch(e){
  if (e!=="ex") $ERROR('#1: Exception ==="ex". Actual:  Exception ==='+ e  );
}

// CHECK#2
with(myObj){
  try{
    throw p1;
  }
  catch(e){
    if (e!=="a") $ERROR('#2.1: Exception ==="a". Actual:  Exception ==='+ e  );
    p1='pass';
  }
}
if(myObj.p1!=='pass') $ERROR('#2.2: "throw p1" lead to throwing exception');

// CHECK#3
with(myObj){
  try{
    p1='fail';
    throw p2;
  }
  catch(e){
    if (e!=="b") $ERROR('#3.1: Exception ==="b". Actual:  Exception ==='+ e  );
    p1='pass';
  }
  finally{
    p2='pass';
  }
}
if(myObj.p1!=='pass') $ERROR('#3.2: "throw p2" lead to throwing exception');
if(myObj.p2!=='pass') $ERROR('#3.3: "finally" block must be evaluated');

// CHECK#4
myObj.p1='fail';
try{
  with(myObj){
    try{
      throw p3;
    }
    finally{
      p1='pass';
    }
  }
}
catch(e){}
if(myObj.p1!=='pass') $ERROR('#4: "finally" block must be evaluated');