Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-68498-004.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 * Date: 15 Feb 2001
8 *
9 * SUMMARY: self.eval(str) inside a function
10 * NOTE: 'self' is just a variable used to capture the global JS object.
11 *
12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=68498
13 * See http://bugzilla.mozilla.org/showattachment.cgi?attach_id=25251
14 * See http://bugzilla.mozilla.org/show_bug.cgi?id=69441 (!!!)
15 *
16 * Brendan:
17 *
18 * "ECMA-262 Edition 3, 10.1.3 requires a FunctionDeclaration parsed as part
19 * of a Program by eval to create a property of eval's caller's variable object.
20 * This test evals in the body of a with statement, whose scope chain *is*
21 * relevant to the effect of parsing the FunctionDeclaration."
22 */
23 //-----------------------------------------------------------------------------
24 var gTestfile = 'regress-68498-004.js';
25 var BUGNUMBER = 68498;
26 var summary = 'Testing self.eval(str) inside a function';
27 var statprefix = '; currently at expect[';
28 var statsuffix = '] within test -';
29 var sToEval='';
30 var actual=[ ];
31 var expect=[ ];
32
33
34 // Capture a reference to the global object -
35 var self = this;
36
37 // You shouldn't see this global variable's value in any printout -
38 var x = 'outer';
39
40 // This function is the heart of the test -
41 function f(o,s,x) {with(o) eval(s); return z;};
42
43 // Run-time statements to pass to the eval inside f
44 sToEval += 'actual[0] = typeof g;'
45 sToEval += 'function g(){actual[1]=(typeof w == "undefined" || w); return x};'
46 sToEval += 'actual[2] = w;'
47 sToEval += 'actual[3] = typeof g;'
48 sToEval += 'var z=g();'
49
50 // Set the actual-results array. The next line will set actual[0] - actual[4] in one shot
51 actual[4] = f({w:44}, sToEval, 'inner');
52 actual[5] = 'z' in self && z;
53
54
55 /* Set the expected-results array.
56 *
57 * Sample issue: why do we set expect[4] = 'inner'? Look at actual[4]...
58 * 1. The return value of f equals z, which is not defined at compile-time
59 * 2. At run-time (via with(o) eval(s) inside f), z is defined as the return value of g
60 * 3. At run-time (via with(o) eval(s) inside f), g is defined to return x
61 * 4. In the scope of with(o), x is undefined
62 * 5. Farther up the scope chain, x can be located as an argument of f
63 * 6. The value of this argument at run-time is 'inner'
64 * 7. Even farther up the scope chain, the name x can be found as a global variable
65 * 8. The value of this global variable is 'outer', but we should NOT have gone
66 * this far up the scope chain to find x...therefore we expect 'inner'
67 */
68 expect[0] = 'function';
69 expect[1] = 44;
70 expect[2] = 44;
71 expect[3] = 'function';
72 expect[4] = 'inner';
73 expect[5] = false;
74
75
76
77 //------------------------------------------------------------------------------------------------
78 test();
79 //-------------------------------------------------------------------------------------------------
80
81
82 function test()
83 {
84 enterFunc ('test');
85 printBugNumber(BUGNUMBER);
86 printStatus (summary);
87
88 for (var i in expect)
89 {
90 reportCompare(expect[i], actual[i], getStatus(i));
91 }
92
93 exitFunc ('test');
94 }
95
96
97 function getStatus(i)
98 {
99 return (summary + statprefix + i + statsuffix);
100 }