Debian Codegraph @

rhino/testsrc/tests/js1_5/Scope/scope-004.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-16
8 *
9 * SUMMARY: Testing visiblity of variables from within a with block.
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90325
11 */
12 //-----------------------------------------------------------------------------
13 var gTestfile = 'scope-004.js';
14 var UBound = 0;
15 var BUGNUMBER = 90325;
16 var summary = 'Testing visiblity of variables from within a with block';
17 var status = '';
18 var statusitems = [];
19 var actual = '';
20 var actualvalues = [];
21 var expect= '';
22 var expectedvalues = [];
23
24 // (compare local definitions which follow) -
25 var A = 'global A';
26 var B = 'global B';
27 var C = 'global C';
28 var D = 'global D';
29
30 // an object with 'C' and 'D' properties -
31 var objTEST = new Object();
32 objTEST.C = C;
33 objTEST.D = D;
34
35
36 status = 'Section 1 of test';
37 with (new Object())
38 {
39 actual = A;
40 expect = 'global A';
41 }
42 addThis();
43
44
45 status = 'Section 2 of test';
46 with (Function)
47 {
48 actual = B;
49 expect = 'global B';
50 }
51 addThis();
52
53
54 status = 'Section 3 of test';
55 with (this)
56 {
57 actual = C;
58 expect = 'global C';
59 }
60 addThis();
61
62
63 status = 'Section 4 of test';
64 localA();
65 addThis();
66
67 status = 'Section 5 of test';
68 localB();
69 addThis();
70
71 status = 'Section 6 of test';
72 localC();
73 addThis();
74
75 status = 'Section 7 of test';
76 localC(new Object());
77 addThis();
78
79 status = 'Section 8 of test';
80 localC.apply(new Object());
81 addThis();
82
83 status = 'Section 9 of test';
84 localC.apply(new Object(), [objTEST]);
85 addThis();
86
87 status = 'Section 10 of test';
88 localC.apply(objTEST, [objTEST]);
89 addThis();
90
91 status = 'Section 11 of test';
92 localD(new Object());
93 addThis();
94
95 status = 'Section 12 of test';
96 localD.apply(new Object(), [objTEST]);
97 addThis();
98
99 status = 'Section 13 of test';
100 localD.apply(objTEST, [objTEST]);
101 addThis();
102
103
104
105 //-------------------------------------------------------------------------------------------------
106 test();
107 //-------------------------------------------------------------------------------------------------
108
109
110
111 // contains a with(new Object()) block -
112 function localA()
113 {
114 var A = 'local A';
115
116 with(new Object())
117 {
118 actual = A;
119 expect = 'local A';
120 }
121 }
122
123
124 // contains a with(Number) block -
125 function localB()
126 {
127 var B = 'local B';
128
129 with(Number)
130 {
131 actual = B;
132 expect = 'local B';
133 }
134 }
135
136
137 // contains a with(this) block -
138 function localC(obj)
139 {
140 var C = 'local C';
141
142 with(this)
143 {
144 actual = C;
145 }
146
147 if ('C' in this)
148 expect = this.C;
149 else
150 expect = 'local C';
151 }
152
153
154 // contains a with(obj) block -
155 function localD(obj)
156 {
157 var D = 'local D';
158
159 with(obj)
160 {
161 actual = D;
162 }
163
164 if ('D' in obj)
165 expect = obj.D;
166 else
167 expect = 'local D';
168 }
169
170
171 function addThis()
172 {
173 statusitems[UBound] = status;
174 actualvalues[UBound] = actual;
175 expectedvalues[UBound] = expect;
176 UBound++;
177 }
178
179
180 function test()
181 {
182 enterFunc ('test');
183 printBugNumber(BUGNUMBER);
184 printStatus (summary);
185
186 for (var i = 0; i < UBound; i++)
187 {
188 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
189 }
190
191 exitFunc ('test');
192 }