js/src/tests/js1_5/Regress/regress-68498-004.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial