1 /* 2 * The contents of this file are subject to the Netscape Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/NPL/ 6 * 7 * Software distributed under the License is distributed on an "AS 8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 * implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is mozilla.org code. 13 * 14 * The Initial Developer of the Original Code is Netscape 15 * Communications Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): deneen (at) alum.bucknell.edu, shaver (at) mozilla.org 20 * Date: 08 August 2001 21 * 22 * SUMMARY: When we invoke a function, the arguments object should take 23 * a back seat to any local identifier named "arguments". 24 * 25 * See http://bugzilla.mozilla.org/show_bug.cgi?id=94506 26 */ 27 //----------------------------------------------------------------------------- 28 var UBound = 0; 29 var bug = 94506; 30 var summary = 'Testing functions employing identifiers named "arguments"'; 31 var status = ''; 32 var statusitems = []; 33 var actual = ''; 34 var actualvalues = []; 35 var expect= ''; 36 var expectedvalues = []; 37 var TYPE_OBJECT = typeof new Object(); 38 var arguments = 5555; 39 40 41 // use a parameter named "arguments" 42 function F1(arguments) 43 { 44 return arguments; 45 } 46 47 48 // use a local variable named "arguments" 49 function F2() 50 { 51 var arguments = 55; 52 return arguments; 53 } 54 55 56 // same thing in a different order. CHANGES THE RESULT! 57 function F3() 58 { 59 return arguments; 60 var arguments = 555; 61 } 62 63 64 // use the global variable above named "arguments" 65 function F4() 66 { 67 return arguments; 68 } 69 70 71 72 /* 73 * In Sections 1 and 2, expect the local identifier, not the arguments object. 74 * In Sections 3 and 4, expect the arguments object, not the the identifier. 75 */ 76 77 status = 'Section 1 of test'; 78 actual = F1(5); 79 expect = 5; 80 addThis(); 81 82 83 status = 'Section 2 of test'; 84 actual = F2(); 85 expect = 55; 86 addThis(); 87 88 89 status = 'Section 3 of test'; 90 actual = typeof F3(); 91 expect = TYPE_OBJECT; 92 addThis(); 93 94 95 status = 'Section 4 of test'; 96 actual = typeof F4(); 97 expect = TYPE_OBJECT; 98 addThis(); 99 100 101 // Let's try calling F1 without providing a parameter - 102 status = 'Section 5 of test'; 103 actual = F1(); 104 expect = undefined; 105 addThis(); 106 107 108 // Let's try calling F1 with too many parameters - 109 status = 'Section 6 of test'; 110 actual = F1(3,33,333); 111 expect = 3; 112 addThis(); 113 114 115 116 //----------------------------------------------------------------------------- 117 test(); 118 //----------------------------------------------------------------------------- 119 120 121 function addThis() 122 { 123 statusitems[UBound] = status; 124 actualvalues[UBound] = actual; 125 expectedvalues[UBound] = expect; 126 UBound++; 127 } 128 129 130 function test() 131 { 132 enterFunc ('test'); 133 printBugNumber (bug); 134 printStatus (summary); 135 136 for (var i = 0; i < UBound; i++) 137 { 138 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 139 } 140 141 exitFunc ('test'); 142 } 143