| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var gTestfile = 'scope-002.js'; |
| 14 |
var UBound = 0; |
| 15 |
var BUGNUMBER = '(none)'; |
| 16 |
var summary = 'Testing visibility of outer function from inner function'; |
| 17 |
var cnCousin = 'Fred'; |
| 18 |
var cnColor = 'red'; |
| 19 |
var cnMake = 'Toyota'; |
| 20 |
var status = ''; |
| 21 |
var statusitems = []; |
| 22 |
var actual = ''; |
| 23 |
var actualvalues = []; |
| 24 |
var expect= ''; |
| 25 |
var expectedvalues = []; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
function Outer() |
| 30 |
{ |
| 31 |
|
| 32 |
function inner() |
| 33 |
{ |
| 34 |
Outer.cousin = cnCousin; |
| 35 |
return Outer.cousin; |
| 36 |
} |
| 37 |
|
| 38 |
status = 'Section 1 of test'; |
| 39 |
actual = inner(); |
| 40 |
expect = cnCousin; |
| 41 |
addThis(); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
Outer(); |
| 46 |
status = 'Section 2 of test'; |
| 47 |
actual = Outer.cousin; |
| 48 |
expect = cnCousin; |
| 49 |
addThis(); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
function Car(make) |
| 55 |
{ |
| 56 |
this.make = make; |
| 57 |
Car.prototype.paint = paint; |
| 58 |
|
| 59 |
function paint() |
| 60 |
{ |
| 61 |
Car.color = cnColor; |
| 62 |
Car.prototype.color = Car.color; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
var myCar = new Car(cnMake); |
| 68 |
status = 'Section 3 of test'; |
| 69 |
actual = myCar.make; |
| 70 |
expect = cnMake; |
| 71 |
addThis(); |
| 72 |
|
| 73 |
|
| 74 |
myCar.paint(); |
| 75 |
status = 'Section 4 of test'; |
| 76 |
actual = myCar.color; |
| 77 |
expect = cnColor; |
| 78 |
addThis(); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
test(); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
function addThis() |
| 89 |
{ |
| 90 |
statusitems[UBound] = status; |
| 91 |
actualvalues[UBound] = actual; |
| 92 |
expectedvalues[UBound] = expect; |
| 93 |
UBound++; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
function test() |
| 98 |
{ |
| 99 |
enterFunc ('test'); |
| 100 |
printBugNumber(BUGNUMBER); |
| 101 |
printStatus (summary); |
| 102 |
|
| 103 |
for (var i=0; i<UBound; i++) |
| 104 |
{ |
| 105 |
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 106 |
} |
| 107 |
|
| 108 |
exitFunc ('test'); |
| 109 |
} |