• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* The contents of this file are subject to the Netscape Public
3* License Version 1.1 (the "License"); you may not use this file
4* except in compliance with the License. You may obtain a copy of
5* the License at http://www.mozilla.org/NPL/
6*
7* Software distributed under the License is distributed on an "AS
8* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9* implied. See the License for the specific language governing
10* rights and limitations under the License.
11*
12* The Original Code is mozilla.org code.
13*
14* The Initial Developer of the Original Code is Netscape
15* Communications Corporation.  Portions created by Netscape are
16* Copyright (C) 1998 Netscape Communications Corporation. All
17* Rights Reserved.
18*
19* Contributor(s): deneen@alum.bucknell.edu, shaver@mozilla.org
20* Date: 08 August 2001
21*
22* SUMMARY: When we invoke a function, the arguments object should take
23*          a back seat to any local identifier named "arguments".
24*
25* See http://bugzilla.mozilla.org/show_bug.cgi?id=94506
26*/
27//-----------------------------------------------------------------------------
28var UBound = 0;
29var bug = 94506;
30var summary = 'Testing functions employing identifiers named "arguments"';
31var status = '';
32var statusitems = [];
33var actual = '';
34var actualvalues = [];
35var expect= '';
36var expectedvalues = [];
37var TYPE_OBJECT = typeof new Object();
38var arguments = 5555;
39
40
41// use a parameter named "arguments"
42function F1(arguments)
43{
44  return arguments;
45}
46
47
48// use a local variable named "arguments"
49function F2()
50{
51  var arguments = 55;
52  return arguments;
53}
54
55
56// same thing in a different order. CHANGES THE RESULT!
57function F3()
58{
59  return arguments;
60  var arguments = 555;
61}
62
63
64// use the global variable above named "arguments"
65function F4()
66{
67  return arguments;
68}
69
70
71
72/*
73 * In Sections 1 and 2, expect the local identifier, not the arguments object.
74 * In Sections 3 and 4, expect the arguments object, not the the identifier.
75 */
76
77status = 'Section 1 of test';
78actual = F1(5);
79expect = 5;
80addThis();
81
82
83status = 'Section 2 of test';
84actual = F2();
85expect = 55;
86addThis();
87
88
89status = 'Section 3 of test';
90actual = typeof F3();
91expect = TYPE_OBJECT;
92addThis();
93
94
95status = 'Section 4 of test';
96actual = typeof F4();
97expect = TYPE_OBJECT;
98addThis();
99
100
101// Let's try calling F1 without providing a parameter -
102status = 'Section 5 of test';
103actual = F1();
104expect = undefined;
105addThis();
106
107
108// Let's try calling F1 with too many parameters -
109status = 'Section 6 of test';
110actual = F1(3,33,333);
111expect = 3;
112addThis();
113
114
115
116//-----------------------------------------------------------------------------
117test();
118//-----------------------------------------------------------------------------
119
120
121function addThis()
122{
123  statusitems[UBound] = status;
124  actualvalues[UBound] = actual;
125  expectedvalues[UBound] = expect;
126  UBound++;
127}
128
129
130function test()
131{
132  enterFunc ('test');
133  printBugNumber (bug);
134  printStatus (summary);
135
136  for (var i = 0; i < UBound; i++)
137  {
138    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
139  }
140
141  exitFunc ('test');
142}
143