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
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/
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
15 * The Original Code is mozilla.org code.
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.
23 * brendan@mozilla.org, pschwartau@netscape.com
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.
37 * ***** END LICENSE BLOCK ***** */
42 * SUMMARY: self.eval(str) inside a function
43 * NOTE: 'self' is just a variable used to capture the global JS object.
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 (!!!)
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."
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 -';
66 // Capture a reference to the global object -
69 // You shouldn't see this global variable's value in any printout -
72 // This function is the heart of the test -
73 function f(o,s,x) {with(o) eval(s); return z;};
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();'
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;
87 /* Set the expected-results array.
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'
100 expect[0] = 'function';
103 expect[3] = 'function';
109 //------------------------------------------------------------------------------------------------
111 //-------------------------------------------------------------------------------------------------
117 printBugNumber(BUGNUMBER);
118 printStatus (summary);
120 for (var i in expect)
122 reportCompare(expect[i], actual[i], getStatus(i));
129 function getStatus(i)
131 return (summary + statprefix + i + statsuffix);