| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
gTestfile = 'forin-002.js'; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var SECTION = "forin-002"; |
| 20 |
var VERSION = "ECMA_2"; |
| 21 |
var TITLE = "The for...in statement"; |
| 22 |
|
| 23 |
startTest(); |
| 24 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 25 |
|
| 26 |
function MyObject( value ) { |
| 27 |
this.value = value; |
| 28 |
this.valueOf = new Function ( "return this.value" ); |
| 29 |
this.toString = new Function ( "return this.value + \"\"" ); |
| 30 |
this.toNumber = new Function ( "return this.value + 0" ); |
| 31 |
this.toBoolean = new Function ( "return Boolean( this.value )" ); |
| 32 |
} |
| 33 |
|
| 34 |
ForIn_1(this); |
| 35 |
ForIn_2(this); |
| 36 |
|
| 37 |
ForIn_1(new MyObject(true)); |
| 38 |
ForIn_2(new MyObject(new Boolean(true))); |
| 39 |
|
| 40 |
ForIn_2(3); |
| 41 |
|
| 42 |
test(); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
function ForIn_1( object) { |
| 49 |
with ( object ) { |
| 50 |
for ( property in object ) { |
| 51 |
new TestCase( |
| 52 |
SECTION, |
| 53 |
"with loop in a for...in loop. ("+object+")["+property +"] == "+ |
| 54 |
"eval ( " + property +" )", |
| 55 |
true, |
| 56 |
object[property] == eval(property) ); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
function ForIn_2(object) { |
| 66 |
for ( property in object ) { |
| 67 |
with ( object ) { |
| 68 |
new TestCase( |
| 69 |
SECTION, |
| 70 |
"with loop in a for...in loop. ("+object+")["+property +"] == "+ |
| 71 |
"eval ( " + property +" )", |
| 72 |
true, |
| 73 |
object[property] == eval(property) ); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|