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