Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / Regress / regress-68498-004.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   brendan@mozilla.org, pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  * Date: 15 Feb 2001
41  *
42  * SUMMARY:  self.eval(str) inside a function
43  * NOTE: 'self' is just a variable used to capture the global JS object.
44  *
45  * See http://bugzilla.mozilla.org/show_bug.cgi?id=68498
46  * See http://bugzilla.mozilla.org/showattachment.cgi?attach_id=25251
47  * See http://bugzilla.mozilla.org/show_bug.cgi?id=69441 (!!!)
48  *
49  * Brendan:
50  *
51  * "ECMA-262 Edition 3, 10.1.3 requires a FunctionDeclaration parsed as part
52  * of  a Program by eval to create a property of eval's caller's variable object.
53  * This test evals in the body of a with statement, whose scope chain *is*
54  * relevant to the effect of parsing the FunctionDeclaration."
55  */
56 //-----------------------------------------------------------------------------
57 var BUGNUMBER = 68498;
58 var summary = 'Testing self.eval(str) inside a function';
59 var statprefix = '; currently at expect[';
60 var statsuffix = '] within test -';
61 var sToEval='';
62 var actual=[ ];
63 var expect=[ ];
64
65
66 // Capture a reference to the global object -
67 var self = this;
68
69 // You shouldn't see this global variable's value in any printout -
70 var x = 'outer';
71
72 // This function is the heart of the test -
73 function f(o,s,x) {with(o) eval(s); return z;};
74
75 // Run-time statements to pass to the eval inside f
76 sToEval += 'actual[0] = typeof g;'
77 sToEval += 'function g(){actual[1]=(typeof w == "undefined"  ||  w); return x};'
78 sToEval += 'actual[2] = w;'
79 sToEval += 'actual[3] = typeof g;'
80 sToEval += 'var z=g();'
81
82 // Set the actual-results array. The next line will set actual[0] - actual[4] in one shot
83 actual[4] = f({w:44}, sToEval, 'inner');
84 actual[5] = 'z' in self && z;
85
86
87 /* Set the expected-results array.
88  *
89  *  Sample issue: why do we set expect[4] = 'inner'?  Look at actual[4]...
90  *  1. The return value of f equals z, which is not defined at compile-time
91  *  2. At run-time (via with(o) eval(s) inside f), z is defined as the return value of g
92  *  3. At run-time (via with(o) eval(s) inside f), g is defined to return x
93  *  4. In the scope of with(o), x is undefined
94  *  5. Farther up the scope chain, x can be located as an argument of f
95  *  6. The value of this argument at run-time is 'inner'
96  *  7. Even farther up the scope chain, the name x can be found as a global variable
97  *  8. The value of this global variable is 'outer', but we should NOT have gone
98  *      this far up the scope chain to find x...therefore we expect 'inner'
99  */
100 expect[0] = 'function';
101 expect[1] = 44;
102 expect[2] = 44;
103 expect[3] = 'function';
104 expect[4] = 'inner';
105 expect[5] = false;
106
107
108
109 //------------------------------------------------------------------------------------------------
110 test();
111 //-------------------------------------------------------------------------------------------------
112
113
114 function test()
115 {
116   enterFunc ('test');
117   printBugNumber(BUGNUMBER);
118   printStatus (summary);
119
120   for (var i in expect)
121   {
122     reportCompare(expect[i], actual[i], getStatus(i));
123   }
124
125   exitFunc ('test');
126 }
127
128
129 function getStatus(i)
130 {
131   return (summary  +  statprefix  +  i  +  statsuffix);
132 }