| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var gTestfile = 'scope-004.js'; |
| 14 |
var UBound = 0; |
| 15 |
var BUGNUMBER = 90325; |
| 16 |
var summary = 'Testing visiblity of variables from within a with block'; |
| 17 |
var status = ''; |
| 18 |
var statusitems = []; |
| 19 |
var actual = ''; |
| 20 |
var actualvalues = []; |
| 21 |
var expect= ''; |
| 22 |
var expectedvalues = []; |
| 23 |
|
| 24 |
|
| 25 |
var A = 'global A'; |
| 26 |
var B = 'global B'; |
| 27 |
var C = 'global C'; |
| 28 |
var D = 'global D'; |
| 29 |
|
| 30 |
|
| 31 |
var objTEST = new Object(); |
| 32 |
objTEST.C = C; |
| 33 |
objTEST.D = D; |
| 34 |
|
| 35 |
|
| 36 |
status = 'Section 1 of test'; |
| 37 |
with (new Object()) |
| 38 |
{ |
| 39 |
actual = A; |
| 40 |
expect = 'global A'; |
| 41 |
} |
| 42 |
addThis(); |
| 43 |
|
| 44 |
|
| 45 |
status = 'Section 2 of test'; |
| 46 |
with (Function) |
| 47 |
{ |
| 48 |
actual = B; |
| 49 |
expect = 'global B'; |
| 50 |
} |
| 51 |
addThis(); |
| 52 |
|
| 53 |
|
| 54 |
status = 'Section 3 of test'; |
| 55 |
with (this) |
| 56 |
{ |
| 57 |
actual = C; |
| 58 |
expect = 'global C'; |
| 59 |
} |
| 60 |
addThis(); |
| 61 |
|
| 62 |
|
| 63 |
status = 'Section 4 of test'; |
| 64 |
localA(); |
| 65 |
addThis(); |
| 66 |
|
| 67 |
status = 'Section 5 of test'; |
| 68 |
localB(); |
| 69 |
addThis(); |
| 70 |
|
| 71 |
status = 'Section 6 of test'; |
| 72 |
localC(); |
| 73 |
addThis(); |
| 74 |
|
| 75 |
status = 'Section 7 of test'; |
| 76 |
localC(new Object()); |
| 77 |
addThis(); |
| 78 |
|
| 79 |
status = 'Section 8 of test'; |
| 80 |
localC.apply(new Object()); |
| 81 |
addThis(); |
| 82 |
|
| 83 |
status = 'Section 9 of test'; |
| 84 |
localC.apply(new Object(), [objTEST]); |
| 85 |
addThis(); |
| 86 |
|
| 87 |
status = 'Section 10 of test'; |
| 88 |
localC.apply(objTEST, [objTEST]); |
| 89 |
addThis(); |
| 90 |
|
| 91 |
status = 'Section 11 of test'; |
| 92 |
localD(new Object()); |
| 93 |
addThis(); |
| 94 |
|
| 95 |
status = 'Section 12 of test'; |
| 96 |
localD.apply(new Object(), [objTEST]); |
| 97 |
addThis(); |
| 98 |
|
| 99 |
status = 'Section 13 of test'; |
| 100 |
localD.apply(objTEST, [objTEST]); |
| 101 |
addThis(); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
test(); |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
function localA() |
| 113 |
{ |
| 114 |
var A = 'local A'; |
| 115 |
|
| 116 |
with(new Object()) |
| 117 |
{ |
| 118 |
actual = A; |
| 119 |
expect = 'local A'; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
function localB() |
| 126 |
{ |
| 127 |
var B = 'local B'; |
| 128 |
|
| 129 |
with(Number) |
| 130 |
{ |
| 131 |
actual = B; |
| 132 |
expect = 'local B'; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
function localC(obj) |
| 139 |
{ |
| 140 |
var C = 'local C'; |
| 141 |
|
| 142 |
with(this) |
| 143 |
{ |
| 144 |
actual = C; |
| 145 |
} |
| 146 |
|
| 147 |
if ('C' in this) |
| 148 |
expect = this.C; |
| 149 |
else |
| 150 |
expect = 'local C'; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
function localD(obj) |
| 156 |
{ |
| 157 |
var D = 'local D'; |
| 158 |
|
| 159 |
with(obj) |
| 160 |
{ |
| 161 |
actual = D; |
| 162 |
} |
| 163 |
|
| 164 |
if ('D' in obj) |
| 165 |
expect = obj.D; |
| 166 |
else |
| 167 |
expect = 'local D'; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
function addThis() |
| 172 |
{ |
| 173 |
statusitems[UBound] = status; |
| 174 |
actualvalues[UBound] = actual; |
| 175 |
expectedvalues[UBound] = expect; |
| 176 |
UBound++; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
function test() |
| 181 |
{ |
| 182 |
enterFunc ('test'); |
| 183 |
printBugNumber(BUGNUMBER); |
| 184 |
printStatus (summary); |
| 185 |
|
| 186 |
for (var i = 0; i < UBound; i++) |
| 187 |
{ |
| 188 |
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 189 |
} |
| 190 |
|
| 191 |
exitFunc ('test'); |
| 192 |
} |