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: * michael@0: * Date: 11 Feb 2002 michael@0: * SUMMARY: Testing functions having duplicate formal parameter names michael@0: * michael@0: * SpiderMonkey was crashing on each case below if the parameters had michael@0: * the same name. But duplicate parameter names are permitted by ECMA; michael@0: * see ECMA-262 3rd Edition Final Section 10.1.3 michael@0: * michael@0: * NOTE: Rhino does not have toSource() and uneval(); they are non-ECMA michael@0: * extensions to the language. So we include a test for them at the beginning - michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = '(none)'; michael@0: var summary = 'Testing functions having duplicate formal parameter names'; 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 OBJ = new Object(); michael@0: var OBJ_TYPE = OBJ.toString(); michael@0: michael@0: /* michael@0: * Exit if the implementation doesn't support toSource() or uneval(), michael@0: * since these are non-ECMA extensions to the language - michael@0: */ michael@0: try michael@0: { michael@0: if (!OBJ.toSource || !uneval(OBJ)) michael@0: quit(); michael@0: } michael@0: catch(e) michael@0: { michael@0: quit(); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * OK, now begin the test. Just checking that we don't crash on these - michael@0: */ michael@0: function f1(x,x,x,x) michael@0: { michael@0: var ret = eval(arguments.toSource()); michael@0: return ret.toString(); michael@0: } michael@0: status = inSection(1); michael@0: actual = f1(1,2,3,4); michael@0: expect = OBJ_TYPE; michael@0: addThis(); michael@0: michael@0: michael@0: /* michael@0: * Same thing, but preface |arguments| with the function name michael@0: */ michael@0: function f2(x,x,x,x) michael@0: { michael@0: var ret = eval(f2.arguments.toSource()); michael@0: return ret.toString(); michael@0: } michael@0: status = inSection(2); michael@0: actual = f2(1,2,3,4); michael@0: expect = OBJ_TYPE; michael@0: addThis(); michael@0: michael@0: michael@0: function f3(x,x,x,x) michael@0: { michael@0: var ret = eval(uneval(arguments)); michael@0: return ret.toString(); michael@0: } michael@0: status = inSection(3); michael@0: actual = f3(1,2,3,4); michael@0: expect = OBJ_TYPE; michael@0: addThis(); michael@0: michael@0: michael@0: /* michael@0: * Same thing, but preface |arguments| with the function name michael@0: */ michael@0: function f4(x,x,x,x) michael@0: { michael@0: var ret = eval(uneval(f4.arguments)); michael@0: return ret.toString(); michael@0: } michael@0: status = inSection(4); michael@0: actual = f4(1,2,3,4); michael@0: expect = OBJ_TYPE; michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- 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