]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Statements/12.10-1.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 ECMA Section: 12.10 The with statement
27 with ( Expression ) Statement
29 The with statement adds a computed object to the front of the scope chain
30 of the current execution context, then executes a statement with this
31 augmented scope chain, then restores the scope chain.
35 The production WithStatement : with ( Expression ) Statement is evaluated
37 1. Evaluate Expression.
38 2. Call GetValue(Result(1)).
39 3. Call ToObject(Result(2)).
40 4. Add Result(3) to the front of the scope chain.
41 5. Evaluate Statement using the augmented scope chain from step 4.
42 6. Remove Result(3) from the front of the scope chain.
46 Note that no matter how control leaves the embedded Statement, whether
47 normally or by some form of abrupt completion, the scope chain is always
48 restored to its former state.
50 Author: christine@netscape.com
51 Date: 12 november 1997
54 var SECTION
= "12.10-1";
55 var VERSION
= "ECMA_1";
57 var TITLE
= "The with statment";
59 writeHeaderToLog( SECTION
+ " "+ TITLE
);
61 var testcases
= getTestCases();
66 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
67 testcases
[tc
].passed
= writeTestCaseResult(
70 testcases
[tc
].description
+" = "+
71 testcases
[tc
].actual
);
73 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
78 function getTestCases() {
79 var array
= new Array();
82 // although the scope chain changes, the this value is immutable for a given
85 array
[item
++] = new TestCase( SECTION
,
86 "with( new Number() ) { this +'' }",
88 eval("with( new Number() ) { this +'' }") );
90 // the object's functions and properties should override those of the
93 array
[item
++] = new TestCase(
95 "var MYOB = new WithObject(true); with (MYOB) { parseInt() }",
97 eval("var MYOB = new WithObject(true); with (MYOB) { parseInt() }") );
99 array
[item
++] = new TestCase(
101 "var MYOB = new WithObject(false); with (MYOB) { NaN }",
103 eval("var MYOB = new WithObject(false); with (MYOB) { NaN }") );
105 array
[item
++] = new TestCase(
107 "var MYOB = new WithObject(NaN); with (MYOB) { Infinity }",
109 eval("var MYOB = new WithObject(NaN); with (MYOB) { Infinity }") );
111 array
[item
++] = new TestCase(
113 "var MYOB = new WithObject(false); with (MYOB) { }; Infinity",
114 Number
.POSITIVE_INFINITY
,
115 eval("var MYOB = new WithObject(false); with (MYOB) { }; Infinity") );
118 array
[item
++] = new TestCase(
120 "var MYOB = new WithObject(0); with (MYOB) { delete Infinity; Infinity }",
121 Number
.POSITIVE_INFINITY
,
122 eval("var MYOB = new WithObject(0); with (MYOB) { delete Infinity; Infinity }") );
124 // let us leave the with block via a break.
126 array
[item
++] = new TestCase(
128 "var MYOB = new WithObject(0); while (true) { with (MYOB) { Infinity; break; } } Infinity",
129 Number
.POSITIVE_INFINITY
,
130 eval("var MYOB = new WithObject(0); while (true) { with (MYOB) { Infinity; break; } } Infinity") );
134 function WithObject( value
) {
136 this.prop2
= new Boolean(true);
137 this.prop3
= "a string";
140 // now we will override global functions
142 this.parseInt
= new Function( "return this.value" );
144 this.Infinity
= value
;
145 this.unescape
= new Function( "return this.value" );
146 this.escape
= new Function( "return this.value" );
147 this.eval
= new Function( "return this.value" );
148 this.parseFloat
= new Function( "return this.value" );
149 this.isNaN
= new Function( "return this.value" );
150 this.isFinite
= new Function( "return this.value" );