|
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: 11 Feb 2002 |
|
9 * SUMMARY: Testing functions having duplicate formal parameter names |
|
10 * |
|
11 * Note: given function f(x,x,x,x) {return x;}; f(1,2,3,4) should return 4. |
|
12 * See ECMA-262 3rd Edition Final Section 10.1.3: Variable Instantiation |
|
13 * |
|
14 * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=124900 |
|
15 */ |
|
16 //----------------------------------------------------------------------------- |
|
17 var UBound = 0; |
|
18 var BUGNUMBER = 124900; |
|
19 var summary = 'Testing functions having duplicate formal parameter names'; |
|
20 var status = ''; |
|
21 var statusitems = []; |
|
22 var actual = ''; |
|
23 var actualvalues = []; |
|
24 var expect= ''; |
|
25 var expectedvalues = []; |
|
26 |
|
27 |
|
28 function f1(x,x) |
|
29 { |
|
30 return x; |
|
31 } |
|
32 status = inSection(1); |
|
33 actual = f1(1,2); |
|
34 expect = 2; |
|
35 addThis(); |
|
36 |
|
37 |
|
38 function f2(x,x,x) |
|
39 { |
|
40 return x*x*x; |
|
41 } |
|
42 status = inSection(2); |
|
43 actual = f2(1,2,3); |
|
44 expect = 27; |
|
45 addThis(); |
|
46 |
|
47 |
|
48 function f3(x,x,x,x) |
|
49 { |
|
50 return 'a' + x + 'b' + x + 'c' + x ; |
|
51 } |
|
52 status = inSection(3); |
|
53 actual = f3(1,2,3,4); |
|
54 expect = 'a4b4c4'; |
|
55 addThis(); |
|
56 |
|
57 |
|
58 /* |
|
59 * If the value of the last duplicate parameter is not provided by |
|
60 * the function caller, the value of this parameter is undefined |
|
61 */ |
|
62 function f4(x,a,b,x,z) |
|
63 { |
|
64 return x; |
|
65 } |
|
66 status = inSection(4); |
|
67 actual = f4(1,2); |
|
68 expect = undefined; |
|
69 addThis(); |
|
70 |
|
71 |
|
72 /* |
|
73 * f.toString() should preserve any duplicate formal parameter names that exist |
|
74 */ |
|
75 function f5(x,x,x,x) |
|
76 { |
|
77 } |
|
78 status = inSection(5); |
|
79 actual = f5.toString().match(/\((.*)\)/)[1]; |
|
80 actual = actual.replace(/\s/g, ''); // for definiteness, remove any white space |
|
81 expect = 'x,x,x,x'; |
|
82 addThis(); |
|
83 |
|
84 |
|
85 function f6(x,x,x,x) |
|
86 { |
|
87 var ret = []; |
|
88 |
|
89 for (var i=0; i<arguments.length; i++) |
|
90 ret.push(arguments[i]); |
|
91 |
|
92 return ret.toString(); |
|
93 } |
|
94 status = inSection(6); |
|
95 actual = f6(1,2,3,4); |
|
96 expect = '1,2,3,4'; |
|
97 addThis(); |
|
98 |
|
99 |
|
100 /* |
|
101 * This variation (assigning to x inside f) is from nboyd@atg.com |
|
102 * See http://bugzilla.mozilla.org/show_bug.cgi?id=124900 |
|
103 */ |
|
104 function f7(x,x,x,x) |
|
105 { |
|
106 x = 999; |
|
107 var ret = []; |
|
108 |
|
109 for (var i=0; i<arguments.length; i++) |
|
110 ret.push(arguments[i]); |
|
111 |
|
112 return ret.toString(); |
|
113 } |
|
114 status = inSection(7); |
|
115 actual = f7(1,2,3,4); |
|
116 expect = '1,2,3,999'; |
|
117 addThis(); |
|
118 |
|
119 |
|
120 /* |
|
121 * Same as above, but with |var| keyword added - |
|
122 */ |
|
123 function f8(x,x,x,x) |
|
124 { |
|
125 var x = 999; |
|
126 var ret = []; |
|
127 |
|
128 for (var i=0; i<arguments.length; i++) |
|
129 ret.push(arguments[i]); |
|
130 |
|
131 return ret.toString(); |
|
132 } |
|
133 status = inSection(8); |
|
134 actual = f8(1,2,3,4); |
|
135 expect = '1,2,3,999'; |
|
136 addThis(); |
|
137 |
|
138 |
|
139 |
|
140 //----------------------------------------------------------------------------- |
|
141 test(); |
|
142 //----------------------------------------------------------------------------- |
|
143 |
|
144 |
|
145 |
|
146 function addThis() |
|
147 { |
|
148 statusitems[UBound] = status; |
|
149 actualvalues[UBound] = actual; |
|
150 expectedvalues[UBound] = expect; |
|
151 UBound++; |
|
152 } |
|
153 |
|
154 |
|
155 function test() |
|
156 { |
|
157 enterFunc('test'); |
|
158 printBugNumber(BUGNUMBER); |
|
159 printStatus(summary); |
|
160 |
|
161 for (var i=0; i<UBound; i++) |
|
162 { |
|
163 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
164 } |
|
165 |
|
166 exitFunc ('test'); |
|
167 } |