Debian Codegraph @

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