Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
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 UBound = 0;
15 var BUGNUMBER = 72884;
16 var summary = 'Testing the arguments object';
17 var status = '';
18 var statusitems = [ ];
19 var actual = '';
20 var actualvalues = [ ];
21 var expect= '';
22 var expectedvalues = [ ];
23 var a = '';
26 status = inSection(1);
27 function f()
28 {
29 delete arguments.length;
30 return arguments;
31 }
33 a = f();
34 actual = a instanceof Object;
35 expect = true;
36 addThis();
38 actual = a instanceof Array;
39 expect = false;
40 addThis();
42 actual = a.length;
43 expect = undefined;
44 addThis();
48 status = inSection(2);
49 a = f(1,2,3);
50 actual = a instanceof Object;
51 expect = true;
52 addThis();
54 actual = a instanceof Array;
55 expect = false;
56 addThis();
58 actual = a.length;
59 expect = undefined;
60 addThis();
62 actual = a[0];
63 expect = 1;
64 addThis();
66 actual = a[1];
67 expect = 2;
68 addThis();
70 actual = a[2];
71 expect = 3;
72 addThis();
76 status = inSection(3);
77 /*
78 * Brendan:
79 *
80 * Note that only callee and length can be overridden, so deleting an indexed
81 * property and asking for it again causes it to be recreated by args_resolve:
82 *
83 * function g(){delete arguments[0]; return arguments[0]}
84 * g(42) // should this print 42?
85 *
86 * I'm not positive this violates ECMA, which allows in chapter 16 for extensions
87 * including properties (does it allow for magically reappearing properties?). The
88 * delete operator successfully deletes arguments[0] and results in true, but that
89 * is not distinguishable from the case where arguments[0] was delegated to
90 * Arguments.prototype[0], which was how the bad old code worked.
91 *
92 * I'll ponder this last detail...
93 *
94 * UPDATE: Per ECMA-262, delete on an arguments[i] should succeed
95 * and remove that property from the arguments object, leaving any get
96 * of it after the delete to evaluate to undefined.
97 */
98 function g()
99 {
100 delete arguments[0];
101 return arguments[0];
102 }
103 actual = g(42);
104 expect = undefined; // not 42...
105 addThis();
109 //-------------------------------------------------------------------------------------------------
110 test();
111 //-------------------------------------------------------------------------------------------------
114 function addThis()
115 {
116 statusitems[UBound] = status;
117 actualvalues[UBound] = actual;
118 expectedvalues[UBound] = expect;
119 UBound++;
120 }
123 function test()
124 {
125 enterFunc ('test');
126 printBugNumber(BUGNUMBER);
127 printStatus (summary);
129 for (var i = 0; i < UBound; i++)
130 {
131 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
132 }
134 exitFunc ('test');
135 }