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