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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Regress/regress-68498-004.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Date: 15 Feb 2001
    1.11 + *
    1.12 + * SUMMARY:  self.eval(str) inside a function
    1.13 + * NOTE: 'self' is just a variable used to capture the global JS object.
    1.14 + *
    1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=68498
    1.16 + * See http://bugzilla.mozilla.org/showattachment.cgi?attach_id=25251
    1.17 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=69441 (!!!)
    1.18 + *
    1.19 + * Brendan:
    1.20 + *
    1.21 + * "ECMA-262 Edition 3, 10.1.3 requires a FunctionDeclaration parsed as part
    1.22 + * of  a Program by eval to create a property of eval's caller's variable object.
    1.23 + * This test evals in the body of a with statement, whose scope chain *is*
    1.24 + * relevant to the effect of parsing the FunctionDeclaration."
    1.25 + */
    1.26 +//-----------------------------------------------------------------------------
    1.27 +var BUGNUMBER = 68498;
    1.28 +var summary = 'Testing self.eval(str) inside a function';
    1.29 +var statprefix = '; currently at expect[';
    1.30 +var statsuffix = '] within test -';
    1.31 +var sToEval='';
    1.32 +var actual=[ ];
    1.33 +var expect=[ ];
    1.34 +
    1.35 +
    1.36 +// Capture a reference to the global object -
    1.37 +var self = this;
    1.38 +
    1.39 +// You shouldn't see this global variable's value in any printout -
    1.40 +var x = 'outer';
    1.41 +
    1.42 +// This function is the heart of the test -
    1.43 +function f(o,s,x) {with(o) eval(s); return z;};
    1.44 +
    1.45 +// Run-time statements to pass to the eval inside f
    1.46 +sToEval += 'actual[0] = typeof g;'
    1.47 +sToEval += 'function g(){actual[1]=(typeof w == "undefined"  ||  w); return x};'
    1.48 +sToEval += 'actual[2] = w;'
    1.49 +sToEval += 'actual[3] = typeof g;'
    1.50 +sToEval += 'var z=g();'
    1.51 +
    1.52 +// Set the actual-results array. The next line will set actual[0] - actual[4] in one shot
    1.53 +actual[4] = f({w:44}, sToEval, 'inner');
    1.54 +actual[5] = 'z' in self && z;
    1.55 +
    1.56 +
    1.57 +/* Set the expected-results array.
    1.58 + *
    1.59 + *  Sample issue: why do we set expect[4] = 'inner'?  Look at actual[4]...
    1.60 + *  1. The return value of f equals z, which is not defined at compile-time
    1.61 + *  2. At run-time (via with(o) eval(s) inside f), z is defined as the return value of g
    1.62 + *  3. At run-time (via with(o) eval(s) inside f), g is defined to return x
    1.63 + *  4. In the scope of with(o), x is undefined
    1.64 + *  5. Farther up the scope chain, x can be located as an argument of f
    1.65 + *  6. The value of this argument at run-time is 'inner'
    1.66 + *  7. Even farther up the scope chain, the name x can be found as a global variable
    1.67 + *  8. The value of this global variable is 'outer', but we should NOT have gone
    1.68 + *      this far up the scope chain to find x...therefore we expect 'inner'
    1.69 + */
    1.70 +expect[0] = 'function';
    1.71 +expect[1] = 44;
    1.72 +expect[2] = 44;
    1.73 +expect[3] = 'function';
    1.74 +expect[4] = 'inner';
    1.75 +expect[5] = false;
    1.76 +
    1.77 +
    1.78 +
    1.79 +//------------------------------------------------------------------------------------------------
    1.80 +test();
    1.81 +//-------------------------------------------------------------------------------------------------
    1.82 +
    1.83 +
    1.84 +function test()
    1.85 +{
    1.86 +  enterFunc ('test');
    1.87 +  printBugNumber(BUGNUMBER);
    1.88 +  printStatus (summary);
    1.89 +
    1.90 +  for (var i in expect)
    1.91 +  {
    1.92 +    reportCompare(expect[i], actual[i], getStatus(i));
    1.93 +  }
    1.94 +
    1.95 +  exitFunc ('test');
    1.96 +}
    1.97 +
    1.98 +
    1.99 +function getStatus(i)
   1.100 +{
   1.101 +  return (summary  +  statprefix  +  i  +  statsuffix);
   1.102 +}

mercurial