Debian Codegraph @

rhino/testsrc/tests/js1_5/Scope/regress-77578-001.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 * Date: 2001-07-11
8 *
9 * SUMMARY: Testing eval scope inside a function.
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=77578
11 */
12 //-----------------------------------------------------------------------------
13 var gTestfile = 'regress-77578-001.js';
14 var UBound = 0;
15 var BUGNUMBER = 77578;
16 var summary = 'Testing eval scope inside a function';
17 var cnEquals = '=';
18 var status = '';
19 var statusitems = [];
20 var actual = '';
21 var actualvalues = [];
22 var expect= '';
23 var expectedvalues = [];
24
25
26 // various versions of JavaScript -
27 var JS_VER = [100, 110, 120, 130, 140, 150];
28
29 // Note contrast with local variables i,j,k defined below -
30 var i = 999;
31 var j = 999;
32 var k = 999;
33
34
35 //--------------------------------------------------
36 test();
37 //--------------------------------------------------
38
39
40 function test()
41 {
42 enterFunc ('test');
43 printBugNumber(BUGNUMBER);
44 printStatus (summary);
45
46 // Run tests A,B,C on each version of JS and store results
47 for (var n=0; n!=JS_VER.length; n++)
48 {
49 testA(JS_VER[n]);
50 }
51 for (var n=0; n!=JS_VER.length; n++)
52 {
53 testB(JS_VER[n]);
54 }
55 for (var n=0; n!=JS_VER.length; n++)
56 {
57 testC(JS_VER[n]);
58 }
59
60
61 // Compare actual values to expected values -
62 for (var i=0; i<UBound; i++)
63 {
64 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
65 }
66
67 exitFunc ('test');
68 }
69
70
71 function testA(ver)
72 {
73 // Set the version of JS to test -
74 if (typeof version == 'function')
75 {
76 version(ver);
77 }
78
79 // eval the test, so it compiles AFTER version() has executed -
80 var sTestScript = "";
81
82 // Define a local variable i
83 sTestScript += "status = 'Section A of test; JS ' + ver/100;";
84 sTestScript += "var i=1;";
85 sTestScript += "actual = eval('i');";
86 sTestScript += "expect = 1;";
87 sTestScript += "captureThis('i');";
88
89 eval(sTestScript);
90 }
91
92
93 function testB(ver)
94 {
95 // Set the version of JS to test -
96 if (typeof version == 'function')
97 {
98 version(ver);
99 }
100
101 // eval the test, so it compiles AFTER version() has executed -
102 var sTestScript = "";
103
104 // Define a local for-loop iterator j
105 sTestScript += "status = 'Section B of test; JS ' + ver/100;";
106 sTestScript += "for(var j=1; j<2; j++)";
107 sTestScript += "{";
108 sTestScript += " actual = eval('j');";
109 sTestScript += "};";
110 sTestScript += "expect = 1;";
111 sTestScript += "captureThis('j');";
112
113 eval(sTestScript);
114 }
115
116
117 function testC(ver)
118 {
119 // Set the version of JS to test -
120 if (typeof version == 'function')
121 {
122 version(ver);
123 }
124
125 // eval the test, so it compiles AFTER version() has executed -
126 var sTestScript = "";
127
128 // Define a local variable k in a try-catch block -
129 sTestScript += "status = 'Section C of test; JS ' + ver/100;";
130 sTestScript += "try";
131 sTestScript += "{";
132 sTestScript += " var k=1;";
133 sTestScript += " actual = eval('k');";
134 sTestScript += "}";
135 sTestScript += "catch(e)";
136 sTestScript += "{";
137 sTestScript += "};";
138 sTestScript += "expect = 1;";
139 sTestScript += "captureThis('k');";
140
141 eval(sTestScript);
142 }
143
144
145 function captureThis(varName)
146 {
147 statusitems[UBound] = status;
148 actualvalues[UBound] = varName + cnEquals + actual;
149 expectedvalues[UBound] = varName + cnEquals + expect;
150 UBound++;
151 }