1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/extensions/10.1.3-2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * Date: 11 Feb 2002 1.12 + * SUMMARY: Testing functions having duplicate formal parameter names 1.13 + * 1.14 + * SpiderMonkey was crashing on each case below if the parameters had 1.15 + * the same name. But duplicate parameter names are permitted by ECMA; 1.16 + * see ECMA-262 3rd Edition Final Section 10.1.3 1.17 + * 1.18 + * NOTE: Rhino does not have toSource() and uneval(); they are non-ECMA 1.19 + * extensions to the language. So we include a test for them at the beginning - 1.20 + */ 1.21 +//----------------------------------------------------------------------------- 1.22 +var UBound = 0; 1.23 +var BUGNUMBER = '(none)'; 1.24 +var summary = 'Testing functions having duplicate formal parameter names'; 1.25 +var status = ''; 1.26 +var statusitems = []; 1.27 +var actual = ''; 1.28 +var actualvalues = []; 1.29 +var expect= ''; 1.30 +var expectedvalues = []; 1.31 +var OBJ = new Object(); 1.32 +var OBJ_TYPE = OBJ.toString(); 1.33 + 1.34 +/* 1.35 + * Exit if the implementation doesn't support toSource() or uneval(), 1.36 + * since these are non-ECMA extensions to the language - 1.37 + */ 1.38 +try 1.39 +{ 1.40 + if (!OBJ.toSource || !uneval(OBJ)) 1.41 + quit(); 1.42 +} 1.43 +catch(e) 1.44 +{ 1.45 + quit(); 1.46 +} 1.47 + 1.48 + 1.49 +/* 1.50 + * OK, now begin the test. Just checking that we don't crash on these - 1.51 + */ 1.52 +function f1(x,x,x,x) 1.53 +{ 1.54 + var ret = eval(arguments.toSource()); 1.55 + return ret.toString(); 1.56 +} 1.57 +status = inSection(1); 1.58 +actual = f1(1,2,3,4); 1.59 +expect = OBJ_TYPE; 1.60 +addThis(); 1.61 + 1.62 + 1.63 +/* 1.64 + * Same thing, but preface |arguments| with the function name 1.65 + */ 1.66 +function f2(x,x,x,x) 1.67 +{ 1.68 + var ret = eval(f2.arguments.toSource()); 1.69 + return ret.toString(); 1.70 +} 1.71 +status = inSection(2); 1.72 +actual = f2(1,2,3,4); 1.73 +expect = OBJ_TYPE; 1.74 +addThis(); 1.75 + 1.76 + 1.77 +function f3(x,x,x,x) 1.78 +{ 1.79 + var ret = eval(uneval(arguments)); 1.80 + return ret.toString(); 1.81 +} 1.82 +status = inSection(3); 1.83 +actual = f3(1,2,3,4); 1.84 +expect = OBJ_TYPE; 1.85 +addThis(); 1.86 + 1.87 + 1.88 +/* 1.89 + * Same thing, but preface |arguments| with the function name 1.90 + */ 1.91 +function f4(x,x,x,x) 1.92 +{ 1.93 + var ret = eval(uneval(f4.arguments)); 1.94 + return ret.toString(); 1.95 +} 1.96 +status = inSection(4); 1.97 +actual = f4(1,2,3,4); 1.98 +expect = OBJ_TYPE; 1.99 +addThis(); 1.100 + 1.101 + 1.102 + 1.103 + 1.104 +//----------------------------------------------------------------------------- 1.105 +test(); 1.106 +//----------------------------------------------------------------------------- 1.107 + 1.108 + 1.109 + 1.110 +function addThis() 1.111 +{ 1.112 + statusitems[UBound] = status; 1.113 + actualvalues[UBound] = actual; 1.114 + expectedvalues[UBound] = expect; 1.115 + UBound++; 1.116 +} 1.117 + 1.118 + 1.119 +function test() 1.120 +{ 1.121 + enterFunc('test'); 1.122 + printBugNumber(BUGNUMBER); 1.123 + printStatus(summary); 1.124 + 1.125 + for (var i=0; i<UBound; i++) 1.126 + { 1.127 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.128 + } 1.129 + 1.130 + exitFunc ('test'); 1.131 +}