]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Scope/regress-77578-001.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an
8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
19 * Contributor(s): jrgm@netscape.com, pschwartau@netscape.com
22 * SUMMARY: Testing eval scope inside a function.
23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=77578
25 //-------------------------------------------------------------------------------------------------
28 var summary
= 'Testing eval scope inside a function';
33 var actualvalues
= [];
35 var expectedvalues
= [];
38 // various versions of JavaScript -
39 var JS_VER
= [100, 110, 120, 130, 140, 150];
41 // Note contrast with local variables i,j,k defined below -
47 //--------------------------------------------------
49 //--------------------------------------------------
56 printStatus (summary
);
58 // Run tests A,B,C on each version of JS and store results
59 for (var n
=0; n
!=JS_VER
.length
; n
++)
63 for (var n
=0; n
!=JS_VER
.length
; n
++)
67 for (var n
=0; n
!=JS_VER
.length
; n
++)
73 // Compare actual values to expected values -
74 for (var i
=0; i
<UBound
; i
++)
76 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);
85 // Set the version of JS to test -
88 // eval the test, so it compiles AFTER version() has executed -
91 // Define a local variable i
92 sTestScript
+= "status = 'Section A of test; JS ' + ver/100;";
93 sTestScript
+= "var i=1;";
94 sTestScript
+= "actual = eval('i');";
95 sTestScript
+= "expect = 1;";
96 sTestScript
+= "captureThis('i');";
104 // Set the version of JS to test -
107 // eval the test, so it compiles AFTER version() has executed -
108 var sTestScript
= "";
110 // Define a local for-loop iterator j
111 sTestScript
+= "status = 'Section B of test; JS ' + ver/100;";
112 sTestScript
+= "for(var j=1; j<2; j++)";
114 sTestScript
+= " actual = eval('j');";
116 sTestScript
+= "expect = 1;";
117 sTestScript
+= "captureThis('j');";
125 // Set the version of JS to test -
128 // eval the test, so it compiles AFTER version() has executed -
129 var sTestScript
= "";
131 // Define a local variable k in a try-catch block -
132 sTestScript
+= "status = 'Section C of test; JS ' + ver/100;";
133 sTestScript
+= "try";
135 sTestScript
+= " var k=1;";
136 sTestScript
+= " actual = eval('k');";
138 sTestScript
+= "catch(e)";
141 sTestScript
+= "expect = 1;";
142 sTestScript
+= "captureThis('k');";
148 function captureThis(varName
)
150 statusitems
[UBound
] = status
;
151 actualvalues
[UBound
] = varName
+ cnEquals
+ actual
;
152 expectedvalues
[UBound
] = varName
+ cnEquals
+ expect
;