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 8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed 9 * or 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. 17 * All Rights Reserved. 18 * 19 * Contributor(s): pschwartau (at) netscape.com, crock (at) veilnetworks.com 20 * Date: 2001-07-02 21 * 22 * SUMMARY: Testing visibility of outer function from inner function. 23 * 24 */ 25 //------------------------------------------------------------------------------------------------- 26 var UBound = 0; 27 var bug = '(none)'; 28 var summary = 'Testing visibility of outer function from inner function'; 29 var cnCousin = 'Fred'; 30 var cnColor = 'red'; 31 var cnMake = 'Toyota'; 32 var status = ''; 33 var statusitems = []; 34 var actual = ''; 35 var actualvalues = []; 36 var expect= ''; 37 var expectedvalues = []; 38 39 40 // TEST 1 41 function Outer() 42 { 43 44 function inner() 45 { 46 Outer.cousin = cnCousin; 47 return Outer.cousin; 48 } 49 50 status = 'Section 1 of test'; 51 actual = inner(); 52 expect = cnCousin; 53 addThis(); 54 } 55 56 57 Outer(); 58 status = 'Section 2 of test'; 59 actual = Outer.cousin; 60 expect = cnCousin; 61 addThis(); 62 63 64 65 // TEST 2 66 function Car(make) 67 { 68 this.make = make; 69 Car.prototype.paint = paint; 70 71 function paint() 72 { 73 Car.color = cnColor; 74 Car.prototype.color = Car.color; 75 } 76 } 77 78 79 var myCar = new Car(cnMake); 80 status = 'Section 3 of test'; 81 actual = myCar.make; 82 expect = cnMake; 83 addThis(); 84 85 86 myCar.paint(); 87 status = 'Section 4 of test'; 88 actual = myCar.color; 89 expect = cnColor; 90 addThis(); 91 92 93 94 //-------------------------------------------------- 95 test(); 96 //-------------------------------------------------- 97 98 99 100 function addThis() 101 { 102 statusitems[UBound] = status; 103 actualvalues[UBound] = actual; 104 expectedvalues[UBound] = expect; 105 UBound++; 106 } 107 108 109 function test() 110 { 111 enterFunc ('test'); 112 printBugNumber (bug); 113 printStatus (summary); 114 115 for (var i=0; i<UBound; i++) 116 { 117 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 118 } 119 120 exitFunc ('test'); 121 } 122