| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 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 BUGNUMBER = 68498; |
| 25 |
var summary = 'Testing self.eval(str) inside a function'; |
| 26 |
var statprefix = '; currently at expect['; |
| 27 |
var statsuffix = '] within test -'; |
| 28 |
var sToEval=''; |
| 29 |
var actual=[ ]; |
| 30 |
var expect=[ ]; |
| 31 |
|
| 32 |
|
| 33 |
// Capture a reference to the global object - |
| 34 |
var self = this; |
| 35 |
|
| 36 |
// You shouldn't see this global variable's value in any printout - |
| 37 |
var x = 'outer'; |
| 38 |
|
| 39 |
// This function is the heart of the test - |
| 40 |
function f(o,s,x) {with(o) eval(s); return z;}; |
| 41 |
|
| 42 |
// Run-time statements to pass to the eval inside f |
| 43 |
sToEval += 'actual[0] = typeof g;' |
| 44 |
sToEval += 'function g(){actual[1]=(typeof w == "undefined" || w); return x};' |
| 45 |
sToEval += 'actual[2] = w;' |
| 46 |
sToEval += 'actual[3] = typeof g;' |
| 47 |
sToEval += 'var z=g();' |
| 48 |
|
| 49 |
// Set the actual-results array. The next line will set actual[0] - actual[4] in one shot |
| 50 |
actual[4] = f({w:44}, sToEval, 'inner'); |
| 51 |
actual[5] = 'z' in self && z; |
| 52 |
|
| 53 |
|
| 54 |
/* Set the expected-results array. |
| 55 |
* |
| 56 |
* Sample issue: why do we set expect[4] = 'inner'? Look at actual[4]... |
| 57 |
* 1. The return value of f equals z, which is not defined at compile-time |
| 58 |
* 2. At run-time (via with(o) eval(s) inside f), z is defined as the return value of g |
| 59 |
* 3. At run-time (via with(o) eval(s) inside f), g is defined to return x |
| 60 |
* 4. In the scope of with(o), x is undefined |
| 61 |
* 5. Farther up the scope chain, x can be located as an argument of f |
| 62 |
* 6. The value of this argument at run-time is 'inner' |
| 63 |
* 7. Even farther up the scope chain, the name x can be found as a global variable |
| 64 |
* 8. The value of this global variable is 'outer', but we should NOT have gone |
| 65 |
* this far up the scope chain to find x...therefore we expect 'inner' |
| 66 |
*/ |
| 67 |
expect[0] = 'function'; |
| 68 |
expect[1] = 44; |
| 69 |
expect[2] = 44; |
| 70 |
expect[3] = 'function'; |
| 71 |
expect[4] = 'inner'; |
| 72 |
expect[5] = false; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
//------------------------------------------------------------------------------------------------ |
| 77 |
test(); |
| 78 |
//------------------------------------------------------------------------------------------------- |
| 79 |
|
| 80 |
|
| 81 |
function test() |
| 82 |
{ |
| 83 |
printBugNumber(BUGNUMBER); |
| 84 |
printStatus (summary); |
| 85 |
|
| 86 |
for (var i in expect) |
| 87 |
{ |
| 88 |
reportCompare(expect[i], actual[i], getStatus(i)); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
function getStatus(i) |
| 94 |
{ |
| 95 |
return (summary + statprefix + i + statsuffix); |
| 96 |
} |