initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma_3 / Function / arguments-001.js
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 //-------------------------------------------------------------------------------------------------
27 var UBound = 0;
28 var bug = 72884;
29 var summary = 'Testing the arguments object';
30 var status = '';
31 var statusitems = [ ];
32 var actual = '';
33 var actualvalues = [ ];
34 var expect= '';
35 var expectedvalues = [ ];
36 var a = '';
37
38
39 status = inSection(1);
40 function f()
41 {
42   delete arguments.length;
43   return arguments;
44 }
45
46 a = f();
47 actual = a instanceof Object;
48 expect = true;
49 addThis();
50
51 actual = a instanceof Array;
52 expect = false;
53 addThis();
54
55 actual = a.length;
56 expect = undefined;
57 addThis();
58
59
60
61 status = inSection(2);
62 a = f(1,2,3);
63 actual = a instanceof Object;
64 expect = true;
65 addThis();
66
67 actual = a instanceof Array;
68 expect = false;
69 addThis();
70
71 actual = a.length;
72 expect = undefined;
73 addThis();
74
75 actual = a[0];
76 expect = 1;
77 addThis();
78
79 actual = a[1];
80 expect = 2;
81 addThis();
82
83 actual = a[2];
84 expect = 3;
85 addThis();
86
87
88
89 status = 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  */
111 function g()
112 {
113   delete arguments[0];
114   return arguments[0];
115 }
116 actual = g(42);
117 expect = undefined;  // not 42...
118 addThis();
119
120
121
122 //-------------------------------------------------------------------------------------------------
123 test();
124 //-------------------------------------------------------------------------------------------------
125
126
127 function addThis()
128 {
129   statusitems[UBound] = status;
130   actualvalues[UBound] = actual;
131   expectedvalues[UBound] = expect;
132   UBound++;
133 }
134
135
136 function 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 }