|
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: 10 September 2001 |
|
8 * |
|
9 * SUMMARY: Testing with() statement with nested functions |
|
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=97921 |
|
11 * |
|
12 * Brendan: "The bug is peculiar to functions that have formal parameters, |
|
13 * but that are called with fewer actual arguments than the declared number |
|
14 * of formal parameters." |
|
15 */ |
|
16 //----------------------------------------------------------------------------- |
|
17 var UBound = 0; |
|
18 var BUGNUMBER = 97921; |
|
19 var summary = 'Testing with() statement with nested functions'; |
|
20 var cnYES = 'Inner value === outer value'; |
|
21 var cnNO = "Inner value !== outer value!"; |
|
22 var status = ''; |
|
23 var statusitems = []; |
|
24 var actual = ''; |
|
25 var actualvalues = []; |
|
26 var expect= ''; |
|
27 var expectedvalues = []; |
|
28 var outerValue = ''; |
|
29 var innerValue = ''; |
|
30 var useWith = ''; |
|
31 |
|
32 |
|
33 function F(i) |
|
34 { |
|
35 i = 0; |
|
36 if(useWith) with(1){i;} |
|
37 i++; |
|
38 |
|
39 outerValue = i; // capture value of i in outer function |
|
40 F1 = function() {innerValue = i;}; // capture value of i in inner function |
|
41 F1(); |
|
42 } |
|
43 |
|
44 |
|
45 status = inSection(1); |
|
46 useWith=false; |
|
47 F(); // call F without supplying the argument |
|
48 actual = innerValue === outerValue; |
|
49 expect = true; |
|
50 addThis(); |
|
51 |
|
52 status = inSection(2); |
|
53 useWith=true; |
|
54 F(); // call F without supplying the argument |
|
55 actual = innerValue === outerValue; |
|
56 expect = true; |
|
57 addThis(); |
|
58 |
|
59 |
|
60 function G(i) |
|
61 { |
|
62 i = 0; |
|
63 with (new Object()) {i=100}; |
|
64 i++; |
|
65 |
|
66 outerValue = i; // capture value of i in outer function |
|
67 G1 = function() {innerValue = i;}; // capture value of i in inner function |
|
68 G1(); |
|
69 } |
|
70 |
|
71 |
|
72 status = inSection(3); |
|
73 G(); // call G without supplying the argument |
|
74 actual = innerValue === 101; |
|
75 expect = true; |
|
76 addThis(); |
|
77 |
|
78 status = inSection(4); |
|
79 G(); // call G without supplying the argument |
|
80 actual = innerValue === outerValue; |
|
81 expect = true; |
|
82 addThis(); |
|
83 |
|
84 |
|
85 |
|
86 //----------------------------------------------------------------------------- |
|
87 test(); |
|
88 //----------------------------------------------------------------------------- |
|
89 |
|
90 |
|
91 function addThis() |
|
92 { |
|
93 statusitems[UBound] = status; |
|
94 actualvalues[UBound] = areTheseEqual(actual); |
|
95 expectedvalues[UBound] = areTheseEqual(expect); |
|
96 UBound++; |
|
97 } |
|
98 |
|
99 |
|
100 function test() |
|
101 { |
|
102 enterFunc ('test'); |
|
103 printBugNumber(BUGNUMBER); |
|
104 printStatus (summary); |
|
105 |
|
106 for (var i = 0; i < UBound; i++) |
|
107 { |
|
108 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
109 } |
|
110 |
|
111 exitFunc ('test'); |
|
112 } |
|
113 |
|
114 |
|
115 function areTheseEqual(yes) |
|
116 { |
|
117 return yes? cnYES : cnNO |
|
118 } |