michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Date: 07 May 2001 michael@0: * michael@0: * SUMMARY: Testing the arguments object michael@0: * michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=72884 michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 72884; michael@0: var summary = 'Testing the arguments object'; michael@0: var status = ''; michael@0: var statusitems = [ ]; michael@0: var actual = ''; michael@0: var actualvalues = [ ]; michael@0: var expect= ''; michael@0: var expectedvalues = [ ]; michael@0: var a = ''; michael@0: michael@0: michael@0: status = inSection(1); michael@0: function f() michael@0: { michael@0: delete arguments.length; michael@0: return arguments; michael@0: } michael@0: michael@0: a = f(); michael@0: actual = a instanceof Object; michael@0: expect = true; michael@0: addThis(); michael@0: michael@0: actual = a instanceof Array; michael@0: expect = false; michael@0: addThis(); michael@0: michael@0: actual = a.length; michael@0: expect = undefined; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: status = inSection(2); michael@0: a = f(1,2,3); michael@0: actual = a instanceof Object; michael@0: expect = true; michael@0: addThis(); michael@0: michael@0: actual = a instanceof Array; michael@0: expect = false; michael@0: addThis(); michael@0: michael@0: actual = a.length; michael@0: expect = undefined; michael@0: addThis(); michael@0: michael@0: actual = a[0]; michael@0: expect = 1; michael@0: addThis(); michael@0: michael@0: actual = a[1]; michael@0: expect = 2; michael@0: addThis(); michael@0: michael@0: actual = a[2]; michael@0: expect = 3; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: status = inSection(3); michael@0: /* michael@0: * Brendan: michael@0: * michael@0: * Note that only callee and length can be overridden, so deleting an indexed michael@0: * property and asking for it again causes it to be recreated by args_resolve: michael@0: * michael@0: * function g(){delete arguments[0]; return arguments[0]} michael@0: * g(42) // should this print 42? michael@0: * michael@0: * I'm not positive this violates ECMA, which allows in chapter 16 for extensions michael@0: * including properties (does it allow for magically reappearing properties?). The michael@0: * delete operator successfully deletes arguments[0] and results in true, but that michael@0: * is not distinguishable from the case where arguments[0] was delegated to michael@0: * Arguments.prototype[0], which was how the bad old code worked. michael@0: * michael@0: * I'll ponder this last detail... michael@0: * michael@0: * UPDATE: Per ECMA-262, delete on an arguments[i] should succeed michael@0: * and remove that property from the arguments object, leaving any get michael@0: * of it after the delete to evaluate to undefined. michael@0: */ michael@0: function g() michael@0: { michael@0: delete arguments[0]; michael@0: return arguments[0]; michael@0: } michael@0: actual = g(42); michael@0: expect = undefined; // not 42... michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------------------------- michael@0: test(); michael@0: //------------------------------------------------------------------------------------------------- michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[UBound] = expect; michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: for (var i = 0; i < UBound; i++) michael@0: { michael@0: reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: }