Debian Codegraph @

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