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: 08 August 2001 michael@0: * michael@0: * SUMMARY: When we invoke a function, the arguments object should take michael@0: * a back seat to any local identifier named "arguments". michael@0: * michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=94506 michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 94506; michael@0: var summary = 'Testing functions employing identifiers named "arguments"'; 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 TYPE_OBJECT = typeof new Object(); michael@0: var arguments = 5555; michael@0: michael@0: michael@0: // use a parameter named "arguments" michael@0: function F1(arguments) michael@0: { michael@0: return arguments; michael@0: } michael@0: michael@0: michael@0: // use a local variable named "arguments" michael@0: function F2() michael@0: { michael@0: var arguments = 55; michael@0: return arguments; michael@0: } michael@0: michael@0: michael@0: // same thing in a different order. CHANGES THE RESULT! michael@0: function F3() michael@0: { michael@0: return arguments; michael@0: var arguments = 555; michael@0: } michael@0: michael@0: michael@0: // use the global variable above named "arguments" michael@0: function F4() michael@0: { michael@0: return arguments; michael@0: } michael@0: michael@0: michael@0: michael@0: /* michael@0: * In Sections 1 and 2, expect the local identifier, not the arguments object. michael@0: * In Sections 3 and 4, expect the arguments object, not the the identifier. michael@0: */ michael@0: michael@0: status = 'Section 1 of test'; michael@0: actual = F1(5); michael@0: expect = 5; michael@0: addThis(); michael@0: michael@0: michael@0: status = 'Section 2 of test'; michael@0: actual = F2(); michael@0: expect = 55; michael@0: addThis(); michael@0: michael@0: michael@0: status = 'Section 3 of test'; michael@0: actual = typeof F3(); michael@0: expect = TYPE_OBJECT; michael@0: addThis(); michael@0: michael@0: michael@0: status = 'Section 4 of test'; michael@0: actual = typeof F4(); michael@0: expect = TYPE_OBJECT; michael@0: addThis(); michael@0: michael@0: michael@0: // Let's try calling F1 without providing a parameter - michael@0: status = 'Section 5 of test'; michael@0: actual = F1(); michael@0: expect = undefined; michael@0: addThis(); michael@0: michael@0: michael@0: // Let's try calling F1 with too many parameters - michael@0: status = 'Section 6 of test'; michael@0: actual = F1(3,33,333); michael@0: expect = 3; 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: }