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.

     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/. */
     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=[ ];
    33 // Capture a reference to the global object -
    34 var self = this;
    36 // You shouldn't see this global variable's value in any printout -
    37 var x = 'outer';
    39 // This function is the heart of the test -
    40 function f(o,s,x) {with(o) eval(s); return z;};
    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();'
    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;
    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;
    76 //------------------------------------------------------------------------------------------------
    77 test();
    78 //-------------------------------------------------------------------------------------------------
    81 function test()
    82 {
    83   enterFunc ('test');
    84   printBugNumber(BUGNUMBER);
    85   printStatus (summary);
    87   for (var i in expect)
    88   {
    89     reportCompare(expect[i], actual[i], getStatus(i));
    90   }
    92   exitFunc ('test');
    93 }
    96 function getStatus(i)
    97 {
    98   return (summary  +  statprefix  +  i  +  statsuffix);
    99 }

mercurial