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): brendan@mozilla.org, pschwartau@netscape.com
20* Date: 07 May 2001
21*
22* SUMMARY:  Testing the arguments object
23*
24* See http://bugzilla.mozilla.org/show_bug.cgi?id=72884
25*/
26//-------------------------------------------------------------------------------------------------
27var UBound = 0;
28var bug = 72884;
29var summary = 'Testing the arguments object';
30var status = '';
31var statusitems = [ ];
32var actual = '';
33var actualvalues = [ ];
34var expect= '';
35var expectedvalues = [ ];
36var a = '';
37
38
39status = inSection(1);
40function f()
41{
42  delete arguments.length;
43  return arguments;
44}
45
46a = f();
47actual = a instanceof Object;
48expect = true;
49addThis();
50
51actual = a instanceof Array;
52expect = false;
53addThis();
54
55actual = a.length;
56expect = undefined;
57addThis();
58
59
60
61status = inSection(2);
62a = f(1,2,3);
63actual = a instanceof Object;
64expect = true;
65addThis();
66
67actual = a instanceof Array;
68expect = false;
69addThis();
70
71actual = a.length;
72expect = undefined;
73addThis();
74
75actual = a[0];
76expect = 1;
77addThis();
78
79actual = a[1];
80expect = 2;
81addThis();
82
83actual = a[2];
84expect = 3;
85addThis();
86
87
88
89status = inSection(3);
90/*
91 * Brendan:
92 *
93 * Note that only callee and length can be overridden, so deleting an indexed
94 * property and asking for it again causes it to be recreated by args_resolve:
95 *
96 * function g(){delete arguments[0]; return arguments[0]}
97 * g(42)     // should this print 42?
98 *
99 * I'm not positive this violates ECMA, which allows in chapter 16 for extensions
100 * including properties (does it allow for magically reappearing properties?).  The
101 * delete operator successfully deletes arguments[0] and results in true, but that
102 * is not distinguishable from the case where arguments[0] was delegated to
103 * Arguments.prototype[0], which was how the bad old code worked.
104 *
105 * I'll ponder this last detail...
106 *
107 * UPDATE: Per ECMA-262, delete on an arguments[i] should succeed
108 * and remove that property from the arguments object, leaving any get
109 * of it after the delete to evaluate to undefined.
110 */
111function g()
112{
113  delete arguments[0];
114  return arguments[0];
115}
116actual = g(42);
117expect = undefined;  // not 42...
118addThis();
119
120
121
122//-------------------------------------------------------------------------------------------------
123test();
124//-------------------------------------------------------------------------------------------------
125
126
127function addThis()
128{
129  statusitems[UBound] = status;
130  actualvalues[UBound] = actual;
131  expectedvalues[UBound] = expect;
132  UBound++;
133}
134
135
136function test()
137{
138  enterFunc ('test');
139  printBugNumber (bug);
140  printStatus (summary);
141
142  for (var i = 0; i < UBound; i++)
143  {
144    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
145  }
146
147  exitFunc ('test');
148}
149