1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/ExecutionContexts/10.1.3-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,167 @@ 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 + * Note: given function f(x,x,x,x) {return x;}; f(1,2,3,4) should return 4. 1.15 + * See ECMA-262 3rd Edition Final Section 10.1.3: Variable Instantiation 1.16 + * 1.17 + * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=124900 1.18 + */ 1.19 +//----------------------------------------------------------------------------- 1.20 +var UBound = 0; 1.21 +var BUGNUMBER = 124900; 1.22 +var summary = 'Testing functions having duplicate formal parameter names'; 1.23 +var status = ''; 1.24 +var statusitems = []; 1.25 +var actual = ''; 1.26 +var actualvalues = []; 1.27 +var expect= ''; 1.28 +var expectedvalues = []; 1.29 + 1.30 + 1.31 +function f1(x,x) 1.32 +{ 1.33 + return x; 1.34 +} 1.35 +status = inSection(1); 1.36 +actual = f1(1,2); 1.37 +expect = 2; 1.38 +addThis(); 1.39 + 1.40 + 1.41 +function f2(x,x,x) 1.42 +{ 1.43 + return x*x*x; 1.44 +} 1.45 +status = inSection(2); 1.46 +actual = f2(1,2,3); 1.47 +expect = 27; 1.48 +addThis(); 1.49 + 1.50 + 1.51 +function f3(x,x,x,x) 1.52 +{ 1.53 + return 'a' + x + 'b' + x + 'c' + x ; 1.54 +} 1.55 +status = inSection(3); 1.56 +actual = f3(1,2,3,4); 1.57 +expect = 'a4b4c4'; 1.58 +addThis(); 1.59 + 1.60 + 1.61 +/* 1.62 + * If the value of the last duplicate parameter is not provided by 1.63 + * the function caller, the value of this parameter is undefined 1.64 + */ 1.65 +function f4(x,a,b,x,z) 1.66 +{ 1.67 + return x; 1.68 +} 1.69 +status = inSection(4); 1.70 +actual = f4(1,2); 1.71 +expect = undefined; 1.72 +addThis(); 1.73 + 1.74 + 1.75 +/* 1.76 + * f.toString() should preserve any duplicate formal parameter names that exist 1.77 + */ 1.78 +function f5(x,x,x,x) 1.79 +{ 1.80 +} 1.81 +status = inSection(5); 1.82 +actual = f5.toString().match(/\((.*)\)/)[1]; 1.83 +actual = actual.replace(/\s/g, ''); // for definiteness, remove any white space 1.84 +expect = 'x,x,x,x'; 1.85 +addThis(); 1.86 + 1.87 + 1.88 +function f6(x,x,x,x) 1.89 +{ 1.90 + var ret = []; 1.91 + 1.92 + for (var i=0; i<arguments.length; i++) 1.93 + ret.push(arguments[i]); 1.94 + 1.95 + return ret.toString(); 1.96 +} 1.97 +status = inSection(6); 1.98 +actual = f6(1,2,3,4); 1.99 +expect = '1,2,3,4'; 1.100 +addThis(); 1.101 + 1.102 + 1.103 +/* 1.104 + * This variation (assigning to x inside f) is from nboyd@atg.com 1.105 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=124900 1.106 + */ 1.107 +function f7(x,x,x,x) 1.108 +{ 1.109 + x = 999; 1.110 + var ret = []; 1.111 + 1.112 + for (var i=0; i<arguments.length; i++) 1.113 + ret.push(arguments[i]); 1.114 + 1.115 + return ret.toString(); 1.116 +} 1.117 +status = inSection(7); 1.118 +actual = f7(1,2,3,4); 1.119 +expect = '1,2,3,999'; 1.120 +addThis(); 1.121 + 1.122 + 1.123 +/* 1.124 + * Same as above, but with |var| keyword added - 1.125 + */ 1.126 +function f8(x,x,x,x) 1.127 +{ 1.128 + var x = 999; 1.129 + var ret = []; 1.130 + 1.131 + for (var i=0; i<arguments.length; i++) 1.132 + ret.push(arguments[i]); 1.133 + 1.134 + return ret.toString(); 1.135 +} 1.136 +status = inSection(8); 1.137 +actual = f8(1,2,3,4); 1.138 +expect = '1,2,3,999'; 1.139 +addThis(); 1.140 + 1.141 + 1.142 + 1.143 +//----------------------------------------------------------------------------- 1.144 +test(); 1.145 +//----------------------------------------------------------------------------- 1.146 + 1.147 + 1.148 + 1.149 +function addThis() 1.150 +{ 1.151 + statusitems[UBound] = status; 1.152 + actualvalues[UBound] = actual; 1.153 + expectedvalues[UBound] = expect; 1.154 + UBound++; 1.155 +} 1.156 + 1.157 + 1.158 +function test() 1.159 +{ 1.160 + enterFunc('test'); 1.161 + printBugNumber(BUGNUMBER); 1.162 + printStatus(summary); 1.163 + 1.164 + for (var i=0; i<UBound; i++) 1.165 + { 1.166 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.167 + } 1.168 + 1.169 + exitFunc ('test'); 1.170 +}