Debian Codegraph @

rhino/testsrc/tests/ecma_3/Function/regress-131964.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: 19 Mar 2002
9 * SUMMARY: Function declarations in global or function scope are {DontDelete}.
10 * Function declarations in eval scope are not {DontDelete}.
11 *
12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=131964
13 *
14 */
15 //-----------------------------------------------------------------------------
16 var gTestfile = 'regress-131964.js';
17 var UBound = 0;
18 var BUGNUMBER = 131964;
19 var summary = 'Functions defined in global or function scope are {DontDelete}';
20 var status = '';
21 var statusitems = [];
22 var actual = '';
23 var actualvalues = [];
24 var expect= '';
25 var expectedvalues = [];
26
27
28 status = inSection(1);
29 function f()
30 {
31 return 'f lives!';
32 }
33 delete f;
34
35 try
36 {
37 actual = f();
38 }
39 catch(e)
40 {
41 actual = 'f was deleted';
42 }
43
44 expect = 'f lives!';
45 addThis();
46
47
48
49 /*
50 * Try the same test in function scope -
51 */
52 status = inSection(2);
53 function g()
54 {
55 function f()
56 {
57 return 'f lives!';
58 }
59 delete f;
60
61 try
62 {
63 actual = f();
64 }
65 catch(e)
66 {
67 actual = 'f was deleted';
68 }
69
70 expect = 'f lives!';
71 addThis();
72 }
73 g();
74
75
76
77 /*
78 * Try the same test in eval scope - here we EXPECT the function to be deleted (?)
79 */
80 status = inSection(3);
81 var s = '';
82 s += 'function h()';
83 s += '{ ';
84 s += ' return "h lives!";';
85 s += '}';
86 s += 'delete h;';
87
88 s += 'try';
89 s += '{';
90 s += ' actual = h();';
91 s += '}';
92 s += 'catch(e)';
93 s += '{';
94 s += ' actual = "h was deleted";';
95 s += '}';
96
97 s += 'expect = "h was deleted";';
98 s += 'addThis();';
99 eval(s);
100
101
102 /*
103 * Define the function in eval scope, but delete it in global scope -
104 */
105 status = inSection(4);
106 s = '';
107 s += 'function k()';
108 s += '{ ';
109 s += ' return "k lives!";';
110 s += '}';
111 eval(s);
112
113 delete k;
114
115 try
116 {
117 actual = k();
118 }
119 catch(e)
120 {
121 actual = 'k was deleted';
122 }
123
124 expect = 'k was deleted';
125 addThis();
126
127
128
129
130 //-----------------------------------------------------------------------------
131 test();
132 //-----------------------------------------------------------------------------
133
134
135
136 function wasDeleted(functionName)
137 {
138 return functionName + ' was deleted...';
139 }
140
141
142 function addThis()
143 {
144 statusitems[UBound] = status;
145 actualvalues[UBound] = actual;
146 expectedvalues[UBound] = expect;
147 UBound++;
148 }
149
150
151 function test()
152 {
153 enterFunc('test');
154 printBugNumber(BUGNUMBER);
155 printStatus(summary);
156
157 for (var i=0; i<UBound; i++)
158 {
159 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
160 }
161
162 exitFunc ('test');
163 }