Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * |
michael@0 | 8 | * Date: 11 Feb 2002 |
michael@0 | 9 | * SUMMARY: Testing functions having duplicate formal parameter names |
michael@0 | 10 | * |
michael@0 | 11 | * Note: given function f(x,x,x,x) {return x;}; f(1,2,3,4) should return 4. |
michael@0 | 12 | * See ECMA-262 3rd Edition Final Section 10.1.3: Variable Instantiation |
michael@0 | 13 | * |
michael@0 | 14 | * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=124900 |
michael@0 | 15 | */ |
michael@0 | 16 | //----------------------------------------------------------------------------- |
michael@0 | 17 | var UBound = 0; |
michael@0 | 18 | var BUGNUMBER = 124900; |
michael@0 | 19 | var summary = 'Testing functions having duplicate formal parameter names'; |
michael@0 | 20 | var status = ''; |
michael@0 | 21 | var statusitems = []; |
michael@0 | 22 | var actual = ''; |
michael@0 | 23 | var actualvalues = []; |
michael@0 | 24 | var expect= ''; |
michael@0 | 25 | var expectedvalues = []; |
michael@0 | 26 | |
michael@0 | 27 | |
michael@0 | 28 | function f1(x,x) |
michael@0 | 29 | { |
michael@0 | 30 | return x; |
michael@0 | 31 | } |
michael@0 | 32 | status = inSection(1); |
michael@0 | 33 | actual = f1(1,2); |
michael@0 | 34 | expect = 2; |
michael@0 | 35 | addThis(); |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | function f2(x,x,x) |
michael@0 | 39 | { |
michael@0 | 40 | return x*x*x; |
michael@0 | 41 | } |
michael@0 | 42 | status = inSection(2); |
michael@0 | 43 | actual = f2(1,2,3); |
michael@0 | 44 | expect = 27; |
michael@0 | 45 | addThis(); |
michael@0 | 46 | |
michael@0 | 47 | |
michael@0 | 48 | function f3(x,x,x,x) |
michael@0 | 49 | { |
michael@0 | 50 | return 'a' + x + 'b' + x + 'c' + x ; |
michael@0 | 51 | } |
michael@0 | 52 | status = inSection(3); |
michael@0 | 53 | actual = f3(1,2,3,4); |
michael@0 | 54 | expect = 'a4b4c4'; |
michael@0 | 55 | addThis(); |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | /* |
michael@0 | 59 | * If the value of the last duplicate parameter is not provided by |
michael@0 | 60 | * the function caller, the value of this parameter is undefined |
michael@0 | 61 | */ |
michael@0 | 62 | function f4(x,a,b,x,z) |
michael@0 | 63 | { |
michael@0 | 64 | return x; |
michael@0 | 65 | } |
michael@0 | 66 | status = inSection(4); |
michael@0 | 67 | actual = f4(1,2); |
michael@0 | 68 | expect = undefined; |
michael@0 | 69 | addThis(); |
michael@0 | 70 | |
michael@0 | 71 | |
michael@0 | 72 | /* |
michael@0 | 73 | * f.toString() should preserve any duplicate formal parameter names that exist |
michael@0 | 74 | */ |
michael@0 | 75 | function f5(x,x,x,x) |
michael@0 | 76 | { |
michael@0 | 77 | } |
michael@0 | 78 | status = inSection(5); |
michael@0 | 79 | actual = f5.toString().match(/\((.*)\)/)[1]; |
michael@0 | 80 | actual = actual.replace(/\s/g, ''); // for definiteness, remove any white space |
michael@0 | 81 | expect = 'x,x,x,x'; |
michael@0 | 82 | addThis(); |
michael@0 | 83 | |
michael@0 | 84 | |
michael@0 | 85 | function f6(x,x,x,x) |
michael@0 | 86 | { |
michael@0 | 87 | var ret = []; |
michael@0 | 88 | |
michael@0 | 89 | for (var i=0; i<arguments.length; i++) |
michael@0 | 90 | ret.push(arguments[i]); |
michael@0 | 91 | |
michael@0 | 92 | return ret.toString(); |
michael@0 | 93 | } |
michael@0 | 94 | status = inSection(6); |
michael@0 | 95 | actual = f6(1,2,3,4); |
michael@0 | 96 | expect = '1,2,3,4'; |
michael@0 | 97 | addThis(); |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | /* |
michael@0 | 101 | * This variation (assigning to x inside f) is from nboyd@atg.com |
michael@0 | 102 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=124900 |
michael@0 | 103 | */ |
michael@0 | 104 | function f7(x,x,x,x) |
michael@0 | 105 | { |
michael@0 | 106 | x = 999; |
michael@0 | 107 | var ret = []; |
michael@0 | 108 | |
michael@0 | 109 | for (var i=0; i<arguments.length; i++) |
michael@0 | 110 | ret.push(arguments[i]); |
michael@0 | 111 | |
michael@0 | 112 | return ret.toString(); |
michael@0 | 113 | } |
michael@0 | 114 | status = inSection(7); |
michael@0 | 115 | actual = f7(1,2,3,4); |
michael@0 | 116 | expect = '1,2,3,999'; |
michael@0 | 117 | addThis(); |
michael@0 | 118 | |
michael@0 | 119 | |
michael@0 | 120 | /* |
michael@0 | 121 | * Same as above, but with |var| keyword added - |
michael@0 | 122 | */ |
michael@0 | 123 | function f8(x,x,x,x) |
michael@0 | 124 | { |
michael@0 | 125 | var x = 999; |
michael@0 | 126 | var ret = []; |
michael@0 | 127 | |
michael@0 | 128 | for (var i=0; i<arguments.length; i++) |
michael@0 | 129 | ret.push(arguments[i]); |
michael@0 | 130 | |
michael@0 | 131 | return ret.toString(); |
michael@0 | 132 | } |
michael@0 | 133 | status = inSection(8); |
michael@0 | 134 | actual = f8(1,2,3,4); |
michael@0 | 135 | expect = '1,2,3,999'; |
michael@0 | 136 | addThis(); |
michael@0 | 137 | |
michael@0 | 138 | |
michael@0 | 139 | |
michael@0 | 140 | //----------------------------------------------------------------------------- |
michael@0 | 141 | test(); |
michael@0 | 142 | //----------------------------------------------------------------------------- |
michael@0 | 143 | |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | function addThis() |
michael@0 | 147 | { |
michael@0 | 148 | statusitems[UBound] = status; |
michael@0 | 149 | actualvalues[UBound] = actual; |
michael@0 | 150 | expectedvalues[UBound] = expect; |
michael@0 | 151 | UBound++; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | function test() |
michael@0 | 156 | { |
michael@0 | 157 | enterFunc('test'); |
michael@0 | 158 | printBugNumber(BUGNUMBER); |
michael@0 | 159 | printStatus(summary); |
michael@0 | 160 | |
michael@0 | 161 | for (var i=0; i<UBound; i++) |
michael@0 | 162 | { |
michael@0 | 163 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | exitFunc ('test'); |
michael@0 | 167 | } |