js/src/tests/js1_5/Scope/regress-191276.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Scope/regress-191276.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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 + *
    1.11 + * Date:    30 January 2003
    1.12 + * SUMMARY: Testing |this[name]| via Function.prototype.call(), apply()
    1.13 + *
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=191276
    1.15 + *
    1.16 + * Igor: "This script fails when run in Rhino compiled mode, but passes in
    1.17 + * interpreted mode. Note that presence of the never-called |unused_function|
    1.18 + * with |f('a')| line is essential; the script works OK without it."
    1.19 + *
    1.20 + */
    1.21 +//-----------------------------------------------------------------------------
    1.22 +var UBound = 0;
    1.23 +var BUGNUMBER = 191276;
    1.24 +var summary = 'Testing |this[name]| via Function.prototype.call(), apply()';
    1.25 +var status = '';
    1.26 +var statusitems = [];
    1.27 +var actual = '';
    1.28 +var actualvalues = [];
    1.29 +var expect= '';
    1.30 +var expectedvalues = [];
    1.31 +
    1.32 +
    1.33 +function F(name)
    1.34 +{
    1.35 +  return this[name];
    1.36 +}
    1.37 +
    1.38 +function unused_function()
    1.39 +{
    1.40 +  F('a');
    1.41 +}
    1.42 +
    1.43 +status = inSection(1);
    1.44 +actual = F.call({a: 'aaa'}, 'a');
    1.45 +expect = 'aaa';
    1.46 +addThis();
    1.47 +
    1.48 +status = inSection(2);
    1.49 +actual = F.apply({a: 'aaa'}, ['a']);
    1.50 +expect = 'aaa';
    1.51 +addThis();
    1.52 +
    1.53 +/*
    1.54 + * Try the same things with an object variable instead of a literal
    1.55 + */
    1.56 +var obj = {a: 'aaa'};
    1.57 +
    1.58 +status = inSection(3);
    1.59 +actual = F.call(obj, 'a');
    1.60 +expect = 'aaa';
    1.61 +addThis();
    1.62 +
    1.63 +status = inSection(4);
    1.64 +actual = F.apply(obj, ['a']);
    1.65 +expect = 'aaa';
    1.66 +addThis();
    1.67 +
    1.68 +
    1.69 +
    1.70 +//-----------------------------------------------------------------------------
    1.71 +test();
    1.72 +//-----------------------------------------------------------------------------
    1.73 +
    1.74 +
    1.75 +
    1.76 +function addThis()
    1.77 +{
    1.78 +  statusitems[UBound] = status;
    1.79 +  actualvalues[UBound] = actual;
    1.80 +  expectedvalues[UBound] = expect;
    1.81 +  UBound++;
    1.82 +}
    1.83 +
    1.84 +
    1.85 +function test()
    1.86 +{
    1.87 +  enterFunc('test');
    1.88 +  printBugNumber(BUGNUMBER);
    1.89 +  printStatus(summary);
    1.90 +
    1.91 +  for (var i=0; i<UBound; i++)
    1.92 +  {
    1.93 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    1.94 +  }
    1.95 +
    1.96 +  exitFunc ('test');
    1.97 +}

mercurial