gecko-dev/js/tests/ecma_2/Statements/forin-002.js

72 строки
1.6 KiB
JavaScript
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
1999-05-27 01:22:57 +04:00
/**
* File Name: forin-002.js
* ECMA Section:
* Description: The forin-001 statement
*
* Verify that the property name is assigned to the property on the left
* hand side of the for...in expression.
*
* Author: christine@netscape.com
* Date: 28 August 1998
*/
var SECTION = "forin-002";
var VERSION = "ECMA_2";
var TITLE = "The for...in statement";
1999-05-27 01:22:57 +04:00
startTest();
writeHeaderToLog( SECTION + " "+ TITLE);
1999-05-27 01:22:57 +04:00
function MyObject( value ) {
this.value = value;
this.valueOf = new Function ( "return this.value" );
this.toString = new Function ( "return this.value + \"\"" );
this.toNumber = new Function ( "return this.value + 0" );
this.toBoolean = new Function ( "return Boolean( this.value )" );
}
1999-05-27 01:22:57 +04:00
ForIn_1(this);
ForIn_2(this);
1999-05-27 01:22:57 +04:00
ForIn_1(new MyObject(true));
ForIn_2(new MyObject(new Boolean(true)));
1999-05-27 01:22:57 +04:00
ForIn_2(3);
1999-05-27 01:22:57 +04:00
test();
1999-05-27 01:22:57 +04:00
/**
* For ... In in a With Block
*
*/
function ForIn_1( object) {
with ( object ) {
for ( property in object ) {
new TestCase(
SECTION,
"with loop in a for...in loop. ("+object+")["+property +"] == "+
"eval ( " + property +" )",
true,
object[property] == eval(property) );
1999-05-27 01:22:57 +04:00
}
}
}
1999-05-27 01:22:57 +04:00
/**
* With block in a For...In loop
*
*/
function ForIn_2(object) {
for ( property in object ) {
with ( object ) {
new TestCase(
SECTION,
"with loop in a for...in loop. ("+object+")["+property +"] == "+
"eval ( " + property +" )",
true,
object[property] == eval(property) );
1999-05-27 01:22:57 +04:00
}
}
}
1999-05-27 01:22:57 +04:00