Debian Codegraph @

rhino/testsrc/tests/js1_5/Scope/regress-208496-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 *
8 * Date: 05 June 2003
9 * SUMMARY: Testing |with (f)| inside the definition of |function f()|
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=208496
12 *
13 */
14 //-----------------------------------------------------------------------------
15 var gTestfile = 'regress-208496-001.js';
16 var UBound = 0;
17 var BUGNUMBER = 208496;
18 var summary = 'Testing |with (f)| inside the definition of |function f()|';
19 var status = '';
20 var statusitems = [];
21 var actual = '(TEST FAILURE)';
22 var actualvalues = [];
23 var expect= '';
24 var expectedvalues = [];
25
26
27 /*
28 * GLOBAL SCOPE
29 */
30 function f(par)
31 {
32 var a = par;
33
34 with(f)
35 {
36 var b = par;
37 actual = b;
38 }
39 }
40
41 status = inSection(1);
42 f('abc'); // this sets |actual|
43 expect = 'abc';
44 addThis();
45
46 status = inSection(2);
47 f(111 + 222); // sets |actual|
48 expect = 333;
49 addThis();
50
51
52 /*
53 * EVAL SCOPE
54 */
55 var s = '';
56 s += 'function F(par)';
57 s += '{';
58 s += ' var a = par;';
59
60 s += ' with(F)';
61 s += ' {';
62 s += ' var b = par;';
63 s += ' actual = b;';
64 s += ' }';
65 s += '}';
66
67 s += 'status = inSection(3);';
68 s += 'F("abc");'; // sets |actual|
69 s += 'expect = "abc";';
70 s += 'addThis();';
71
72 s += 'status = inSection(4);';
73 s += 'F(111 + 222);'; // sets |actual|
74 s += 'expect = 333;';
75 s += 'addThis();';
76 eval(s);
77
78
79 /*
80 * FUNCTION SCOPE
81 */
82 function g(par)
83 {
84 // Add outer variables to complicate the scope chain -
85 var a = '(TEST FAILURE)';
86 var b = '(TEST FAILURE)';
87 h(par);
88
89 function h(par)
90 {
91 var a = par;
92
93 with(h)
94 {
95 var b = par;
96 actual = b;
97 }
98 }
99 }
100
101 status = inSection(5);
102 g('abc'); // sets |actual|
103 expect = 'abc';
104 addThis();
105
106 status = inSection(6);
107 g(111 + 222); // sets |actual|
108 expect = 333;
109 addThis();
110
111
112
113
114 //-----------------------------------------------------------------------------
115 test();
116 //-----------------------------------------------------------------------------
117
118
119
120 function addThis()
121 {
122 statusitems[UBound] = status;
123 actualvalues[UBound] = actual;
124 expectedvalues[UBound] = expect;
125 UBound++;
126 }
127
128
129 function test()
130 {
131 enterFunc('test');
132 printBugNumber(BUGNUMBER);
133 printStatus(summary);
134
135 for (var i=0; i<UBound; i++)
136 {
137 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
138 }
139
140 exitFunc ('test');
141 }