scope-002.js (1872B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * Date: 2001-07-02 8 * 9 * SUMMARY: Testing visibility of outer function from inner function. 10 * 11 */ 12 //----------------------------------------------------------------------------- 13 var UBound = 0; 14 var BUGNUMBER = '(none)'; 15 var summary = 'Testing visibility of outer function from inner function'; 16 var cnCousin = 'Fred'; 17 var cnColor = 'red'; 18 var cnMake = 'Toyota'; 19 var status = ''; 20 var statusitems = []; 21 var actual = ''; 22 var actualvalues = []; 23 var expect= ''; 24 var expectedvalues = []; 25 26 27 // TEST 1 28 function Outer() 29 { 30 31 function inner() 32 { 33 Outer.cousin = cnCousin; 34 return Outer.cousin; 35 } 36 37 status = 'Section 1 of test'; 38 actual = inner(); 39 expect = cnCousin; 40 addThis(); 41 } 42 43 44 Outer(); 45 status = 'Section 2 of test'; 46 actual = Outer.cousin; 47 expect = cnCousin; 48 addThis(); 49 50 51 52 // TEST 2 53 function Car(make) 54 { 55 this.make = make; 56 Car.prototype.paint = paint; 57 58 function paint() 59 { 60 Car.color = cnColor; 61 Car.prototype.color = Car.color; 62 } 63 } 64 65 66 var myCar = new Car(cnMake); 67 status = 'Section 3 of test'; 68 actual = myCar.make; 69 expect = cnMake; 70 addThis(); 71 72 73 myCar.paint(); 74 status = 'Section 4 of test'; 75 actual = myCar.color; 76 expect = cnColor; 77 addThis(); 78 79 80 81 //-------------------------------------------------- 82 test(); 83 //-------------------------------------------------- 84 85 86 87 function addThis() 88 { 89 statusitems[UBound] = status; 90 actualvalues[UBound] = actual; 91 expectedvalues[UBound] = expect; 92 UBound++; 93 } 94 95 96 function test() 97 { 98 printBugNumber(BUGNUMBER); 99 printStatus (summary); 100 101 for (var i=0; i<UBound; i++) 102 { 103 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 104 } 105 }