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): georg (at) bioshop.de, pschwartau (at) netscape.com 20 * Date: 10 September 2001 21 * 22 * SUMMARY: Testing with() statement with nested functions 23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=97921 24 * 25 * Brendan: "The bug is peculiar to functions that have formal parameters, 26 * but that are called with fewer actual arguments than the declared number 27 * of formal parameters." 28 */ 29 //----------------------------------------------------------------------------- 30 var UBound = 0; 31 var bug = 97921; 32 var summary = 'Testing with() statement with nested functions'; 33 var cnYES = 'Inner value === outer value'; 34 var cnNO = "Inner value !== outer value!"; 35 var status = ''; 36 var statusitems = []; 37 var actual = ''; 38 var actualvalues = []; 39 var expect= ''; 40 var expectedvalues = []; 41 var outerValue = ''; 42 var innerValue = ''; 43 var useWith = ''; 44 45 46 function F(i) 47 { 48 i = 0; 49 if(useWith) with(1){i;} 50 i++; 51 52 outerValue = i; // capture value of i in outer function 53 F1 = function() {innerValue = i;}; // capture value of i in inner function 54 F1(); 55 } 56 57 58 status = inSection(1); 59 useWith=false; 60 F(); // call F without supplying the argument 61 actual = innerValue === outerValue; 62 expect = true; 63 addThis(); 64 65 status = inSection(2); 66 useWith=true; 67 F(); // call F without supplying the argument 68 actual = innerValue === outerValue; 69 expect = true; 70 addThis(); 71 72 73 function G(i) 74 { 75 i = 0; 76 with (new Object()) {i=100}; 77 i++; 78 79 outerValue = i; // capture value of i in outer function 80 G1 = function() {innerValue = i;}; // capture value of i in inner function 81 G1(); 82 } 83 84 85 status = inSection(3); 86 G(); // call G without supplying the argument 87 actual = innerValue === 101; 88 expect = true; 89 addThis(); 90 91 status = inSection(4); 92 G(); // call G without supplying the argument 93 actual = innerValue === outerValue; 94 expect = true; 95 addThis(); 96 97 98 99 //----------------------------------------------------------------------------- 100 test(); 101 //----------------------------------------------------------------------------- 102 103 104 function addThis() 105 { 106 statusitems[UBound] = status; 107 actualvalues[UBound] = areTheseEqual(actual); 108 expectedvalues[UBound] = areTheseEqual(expect); 109 UBound++; 110 } 111 112 113 function test() 114 { 115 enterFunc ('test'); 116 printBugNumber (bug); 117 printStatus (summary); 118 119 for (var i = 0; i < UBound; i++) 120 { 121 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 122 } 123 124 exitFunc ('test'); 125 } 126 127 128 function areTheseEqual(yes) 129 { 130 return yes? cnYES : cnNO 131 } 132