js/src/tests/ecma_3/Function/regress-94506.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Function/regress-94506.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     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: 08 August 2001
    1.11 + *
    1.12 + * SUMMARY: When we invoke a function, the arguments object should take
    1.13 + *          a back seat to any local identifier named "arguments".
    1.14 + *
    1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=94506
    1.16 + */
    1.17 +//-----------------------------------------------------------------------------
    1.18 +var UBound = 0;
    1.19 +var BUGNUMBER = 94506;
    1.20 +var summary = 'Testing functions employing identifiers named "arguments"';
    1.21 +var status = '';
    1.22 +var statusitems = [];
    1.23 +var actual = '';
    1.24 +var actualvalues = [];
    1.25 +var expect= '';
    1.26 +var expectedvalues = [];
    1.27 +var TYPE_OBJECT = typeof new Object();
    1.28 +var arguments = 5555;
    1.29 +
    1.30 +
    1.31 +// use a parameter named "arguments"
    1.32 +function F1(arguments)
    1.33 +{
    1.34 +  return arguments;
    1.35 +}
    1.36 +
    1.37 +
    1.38 +// use a local variable named "arguments"
    1.39 +function F2()
    1.40 +{
    1.41 +  var arguments = 55;
    1.42 +  return arguments;
    1.43 +}
    1.44 +
    1.45 +
    1.46 +// same thing in a different order. CHANGES THE RESULT!
    1.47 +function F3()
    1.48 +{
    1.49 +  return arguments;
    1.50 +  var arguments = 555;
    1.51 +}
    1.52 +
    1.53 +
    1.54 +// use the global variable above named "arguments"
    1.55 +function F4()
    1.56 +{
    1.57 +  return arguments;
    1.58 +}
    1.59 +
    1.60 +
    1.61 +
    1.62 +/*
    1.63 + * In Sections 1 and 2, expect the local identifier, not the arguments object.
    1.64 + * In Sections 3 and 4, expect the arguments object, not the the identifier.
    1.65 + */
    1.66 +
    1.67 +status = 'Section 1 of test';
    1.68 +actual = F1(5);
    1.69 +expect = 5;
    1.70 +addThis();
    1.71 +
    1.72 +
    1.73 +status = 'Section 2 of test';
    1.74 +actual = F2();
    1.75 +expect = 55;
    1.76 +addThis();
    1.77 +
    1.78 +
    1.79 +status = 'Section 3 of test';
    1.80 +actual = typeof F3();
    1.81 +expect = TYPE_OBJECT;
    1.82 +addThis();
    1.83 +
    1.84 +
    1.85 +status = 'Section 4 of test';
    1.86 +actual = typeof F4();
    1.87 +expect = TYPE_OBJECT;
    1.88 +addThis();
    1.89 +
    1.90 +
    1.91 +// Let's try calling F1 without providing a parameter -
    1.92 +status = 'Section 5 of test';
    1.93 +actual = F1();
    1.94 +expect = undefined;
    1.95 +addThis();
    1.96 +
    1.97 +
    1.98 +// Let's try calling F1 with too many parameters -
    1.99 +status = 'Section 6 of test';
   1.100 +actual = F1(3,33,333);
   1.101 +expect = 3;
   1.102 +addThis();
   1.103 +
   1.104 +
   1.105 +
   1.106 +//-----------------------------------------------------------------------------
   1.107 +test();
   1.108 +//-----------------------------------------------------------------------------
   1.109 +
   1.110 +
   1.111 +function addThis()
   1.112 +{
   1.113 +  statusitems[UBound] = status;
   1.114 +  actualvalues[UBound] = actual;
   1.115 +  expectedvalues[UBound] = expect;
   1.116 +  UBound++;
   1.117 +}
   1.118 +
   1.119 +
   1.120 +function test()
   1.121 +{
   1.122 +  enterFunc ('test');
   1.123 +  printBugNumber(BUGNUMBER);
   1.124 +  printStatus (summary);
   1.125 +
   1.126 +  for (var i = 0; i < UBound; i++)
   1.127 +  {
   1.128 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.129 +  }
   1.130 +
   1.131 +  exitFunc ('test');
   1.132 +}

mercurial