js/src/tests/js1_5/Scope/regress-208496-002.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bdff4ca62786
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 * In this test, we check that static function properties of
14 * of |f| are read correctly from within the |with(f)| block.
15 *
16 */
17 //-----------------------------------------------------------------------------
18 var UBound = 0;
19 var BUGNUMBER = 208496;
20 var summary = 'Testing |with (f)| inside the definition of |function f()|';
21 var STATIC_VALUE = 'read the static property';
22 var status = '';
23 var statusitems = [];
24 var actual = '(TEST FAILURE)';
25 var actualvalues = [];
26 var expect= '';
27 var expectedvalues = [];
28
29
30 function f(par)
31 {
32 with(f)
33 {
34 actual = par;
35 }
36
37 return par;
38 }
39 f.par = STATIC_VALUE;
40
41
42 status = inSection(1);
43 f('abc'); // this sets |actual| inside |f|
44 expect = STATIC_VALUE;
45 addThis();
46
47 // test the return: should be the dynamic value
48 status = inSection(2);
49 actual = f('abc');
50 expect = 'abc';
51 addThis();
52
53 status = inSection(3);
54 f(111 + 222); // sets |actual| inside |f|
55 expect = STATIC_VALUE;
56 addThis();
57
58 // test the return: should be the dynamic value
59 status = inSection(4);
60 actual = f(111 + 222);
61 expect = 333;
62 addThis();
63
64
65 /*
66 * Add a level of indirection via |x|
67 */
68 function g(par)
69 {
70 with(g)
71 {
72 var x = par;
73 actual = x;
74 }
75
76 return par;
77 }
78 g.par = STATIC_VALUE;
79
80
81 status = inSection(5);
82 g('abc'); // this sets |actual| inside |g|
83 expect = STATIC_VALUE;
84 addThis();
85
86 // test the return: should be the dynamic value
87 status = inSection(6);
88 actual = g('abc');
89 expect = 'abc';
90 addThis();
91
92 status = inSection(7);
93 g(111 + 222); // sets |actual| inside |g|
94 expect = STATIC_VALUE;
95 addThis();
96
97 // test the return: should be the dynamic value
98 status = inSection(8);
99 actual = g(111 + 222);
100 expect = 333;
101 addThis();
102
103
104
105 //-----------------------------------------------------------------------------
106 test();
107 //-----------------------------------------------------------------------------
108
109
110
111 function addThis()
112 {
113 statusitems[UBound] = status;
114 actualvalues[UBound] = actual;
115 expectedvalues[UBound] = expect;
116 UBound++;
117 }
118
119
120 function test()
121 {
122 enterFunc('test');
123 printBugNumber(BUGNUMBER);
124 printStatus(summary);
125
126 for (var i=0; i<UBound; i++)
127 {
128 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
129 }
130
131 exitFunc ('test');
132 }

mercurial