Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-146596.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 *
8 * Date: 18 Jun 2002
9 * SUMMARY: Shouldn't crash when catch parameter is "hidden" by varX
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=146596
11 *
12 */
13 //-----------------------------------------------------------------------------
14 var gTestfile = 'regress-146596.js';
15 var UBound = 0;
16 var BUGNUMBER = 146596;
17 var summary = "Shouldn't crash when catch parameter is 'hidden' by varX";
18 var status = '';
19 var statusitems = [];
20 var actual = '';
21 var actualvalues = [];
22 var expect= '';
23 var expectedvalues = [];
24
25
26 /*
27 * Just seeing we don't crash when executing this function -
28 * This example provided by [email protected]
29 *
30 * Brendan: "Jim, thanks for the testcase. But note that |var|
31 * in a JS function makes a function-scoped variable -- JS lacks
32 * block scope apart from for catch variables within catch blocks.
33 *
34 * Therefore the catch variable hides the function-local variable."
35 */
36 function F()
37 {
38 try
39 {
40 return "A simple exception";
41 }
42 catch(e)
43 {
44 var e = "Another exception";
45 }
46
47 return 'XYZ';
48 }
49
50 status = inSection(1);
51 actual = F();
52 expect = "A simple exception";
53 addThis();
54
55
56
57 /*
58 * Sanity check by Brendan: "This should output
59 *
60 * 24
61 * 42
62 * undefined
63 *
64 * and throw no uncaught exception."
65 *
66 */
67 function f(obj)
68 {
69 var res = [];
70
71 try
72 {
73 throw 42;
74 }
75 catch(e)
76 {
77 with(obj)
78 {
79 var e;
80 res[0] = e; // |with| binds tighter than |catch|; s/b |obj.e|
81 }
82
83 res[1] = e; // |catch| binds tighter than function scope; s/b 42
84 }
85
86 res[2] = e; // |var e| has function scope; s/b visible but contain |undefined|
87 return res;
88 }
89
90 status = inSection(2);
91 actual = f({e:24});
92 expect = [24, 42, undefined];
93 addThis();
94
95
96
97
98 //-----------------------------------------------------------------------------
99 test();
100 //-----------------------------------------------------------------------------
101
102
103
104 function addThis()
105 {
106 statusitems[UBound] = status;
107 actualvalues[UBound] = actual.toString();
108 expectedvalues[UBound] = expect.toString();
109 UBound++;
110 }
111
112
113 function test()
114 {
115 enterFunc('test');
116 printBugNumber(BUGNUMBER);
117 printStatus(summary);
118
119 for (var i=0; i<UBound; i++)
120 {
121 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
122 }
123
124 exitFunc ('test');
125 }