var SECTION = "12.10-1";
var VERSION = "ECMA_1";
startTest();
var TITLE = "The with statment";
writeHeaderToLog( SECTION + " "+ TITLE);
var testcases = getTestCases();
test();
function test() {
for ( tc=0; tc < testcases.length; tc++ ) {
testcases[tc].passed = writeTestCaseResult(
testcases[tc].expect,
testcases[tc].actual,
testcases[tc].description +" = "+
testcases[tc].actual );
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
}
stopTest();
return ( testcases );
}
function getTestCases() {
var array = new Array();
var item = 0;
array[item++] = new TestCase( SECTION,
"with( new Number() ) { this +'' }",
"[object global]",
eval("with( new Number() ) { this +'' }") );
array[item++] = new TestCase(
SECTION,
"var MYOB = new WithObject(true); with (MYOB) { parseInt() }",
true,
eval("var MYOB = new WithObject(true); with (MYOB) { parseInt() }") );
array[item++] = new TestCase(
SECTION,
"var MYOB = new WithObject(false); with (MYOB) { NaN }",
false,
eval("var MYOB = new WithObject(false); with (MYOB) { NaN }") );
array[item++] = new TestCase(
SECTION,
"var MYOB = new WithObject(NaN); with (MYOB) { Infinity }",
Number.NaN,
eval("var MYOB = new WithObject(NaN); with (MYOB) { Infinity }") );
array[item++] = new TestCase(
SECTION,
"var MYOB = new WithObject(false); with (MYOB) { }; Infinity",
Number.POSITIVE_INFINITY,
eval("var MYOB = new WithObject(false); with (MYOB) { }; Infinity") );
array[item++] = new TestCase(
SECTION,
"var MYOB = new WithObject(0); with (MYOB) { delete Infinity; Infinity }",
Number.POSITIVE_INFINITY,
eval("var MYOB = new WithObject(0); with (MYOB) { delete Infinity; Infinity }") );
array[item++] = new TestCase(
SECTION,
"var MYOB = new WithObject(0); while (true) { with (MYOB) { Infinity; break; } } Infinity",
Number.POSITIVE_INFINITY,
eval("var MYOB = new WithObject(0); while (true) { with (MYOB) { Infinity; break; } } Infinity") );
return ( array );
}
function WithObject( value ) {
this.prop1 = 1;
this.prop2 = new Boolean(true);
this.prop3 = "a string";
this.value = value;
this.parseInt = new Function( "return this.value" );
this.NaN = value;
this.Infinity = value;
this.unescape = new Function( "return this.value" );
this.escape = new Function( "return this.value" );
this.eval = new Function( "return this.value" );
this.parseFloat = new Function( "return this.value" );
this.isNaN = new Function( "return this.value" );
this.isFinite = new Function( "return this.value" );
}