Debian Codegraph @

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