js/src/tests/ecma_3/Function/arguments-001.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/arguments-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     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: 07 May 2001
    1.11 + *
    1.12 + * SUMMARY:  Testing the arguments object
    1.13 + *
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=72884
    1.15 + */
    1.16 +//-----------------------------------------------------------------------------
    1.17 +var UBound = 0;
    1.18 +var BUGNUMBER = 72884;
    1.19 +var summary = 'Testing the arguments object';
    1.20 +var status = '';
    1.21 +var statusitems = [ ];
    1.22 +var actual = '';
    1.23 +var actualvalues = [ ];
    1.24 +var expect= '';
    1.25 +var expectedvalues = [ ];
    1.26 +var a = '';
    1.27 +
    1.28 +
    1.29 +status = inSection(1);
    1.30 +function f()
    1.31 +{
    1.32 +  delete arguments.length;
    1.33 +  return arguments;
    1.34 +}
    1.35 +
    1.36 +a = f();
    1.37 +actual = a instanceof Object;
    1.38 +expect = true;
    1.39 +addThis();
    1.40 +
    1.41 +actual = a instanceof Array;
    1.42 +expect = false;
    1.43 +addThis();
    1.44 +
    1.45 +actual = a.length;
    1.46 +expect = undefined;
    1.47 +addThis();
    1.48 +
    1.49 +
    1.50 +
    1.51 +status = inSection(2);
    1.52 +a = f(1,2,3);
    1.53 +actual = a instanceof Object;
    1.54 +expect = true;
    1.55 +addThis();
    1.56 +
    1.57 +actual = a instanceof Array;
    1.58 +expect = false;
    1.59 +addThis();
    1.60 +
    1.61 +actual = a.length;
    1.62 +expect = undefined;
    1.63 +addThis();
    1.64 +
    1.65 +actual = a[0];
    1.66 +expect = 1;
    1.67 +addThis();
    1.68 +
    1.69 +actual = a[1];
    1.70 +expect = 2;
    1.71 +addThis();
    1.72 +
    1.73 +actual = a[2];
    1.74 +expect = 3;
    1.75 +addThis();
    1.76 +
    1.77 +
    1.78 +
    1.79 +status = inSection(3);
    1.80 +/*
    1.81 + * Brendan:
    1.82 + *
    1.83 + * Note that only callee and length can be overridden, so deleting an indexed
    1.84 + * property and asking for it again causes it to be recreated by args_resolve:
    1.85 + *
    1.86 + * function g(){delete arguments[0]; return arguments[0]}
    1.87 + * g(42)     // should this print 42?
    1.88 + *
    1.89 + * I'm not positive this violates ECMA, which allows in chapter 16 for extensions
    1.90 + * including properties (does it allow for magically reappearing properties?).  The
    1.91 + * delete operator successfully deletes arguments[0] and results in true, but that
    1.92 + * is not distinguishable from the case where arguments[0] was delegated to
    1.93 + * Arguments.prototype[0], which was how the bad old code worked.
    1.94 + *
    1.95 + * I'll ponder this last detail...
    1.96 + *
    1.97 + * UPDATE: Per ECMA-262, delete on an arguments[i] should succeed
    1.98 + * and remove that property from the arguments object, leaving any get
    1.99 + * of it after the delete to evaluate to undefined.
   1.100 + */
   1.101 +function g()
   1.102 +{
   1.103 +  delete arguments[0];
   1.104 +  return arguments[0];
   1.105 +}
   1.106 +actual = g(42);
   1.107 +expect = undefined;  // not 42...
   1.108 +addThis();
   1.109 +
   1.110 +
   1.111 +
   1.112 +//-------------------------------------------------------------------------------------------------
   1.113 +test();
   1.114 +//-------------------------------------------------------------------------------------------------
   1.115 +
   1.116 +
   1.117 +function addThis()
   1.118 +{
   1.119 +  statusitems[UBound] = status;
   1.120 +  actualvalues[UBound] = actual;
   1.121 +  expectedvalues[UBound] = expect;
   1.122 +  UBound++;
   1.123 +}
   1.124 +
   1.125 +
   1.126 +function test()
   1.127 +{
   1.128 +  enterFunc ('test');
   1.129 +  printBugNumber(BUGNUMBER);
   1.130 +  printStatus (summary);
   1.131 +
   1.132 +  for (var i = 0; i < UBound; i++)
   1.133 +  {
   1.134 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.135 +  }
   1.136 +
   1.137 +  exitFunc ('test');
   1.138 +}

mercurial