js/src/tests/js1_5/Regress/regress-57043.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-57043.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     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: 03 December 2000
    1.11 + *
    1.12 + *
    1.13 + * SUMMARY:  This test arose from Bugzilla bug 57043:
    1.14 + * "Negative integers as object properties: strange behavior!"
    1.15 + *
    1.16 + * We check that object properties may be indexed by signed
    1.17 + * numeric literals, as in assignments like obj[-1] = 'Hello' 
    1.18 + *
    1.19 + * NOTE: it should not matter whether we provide the literal with
    1.20 + * quotes around it or not; e.g. these should be equivalent:
    1.21 + *
    1.22 + *                                    obj[-1]  = 'Hello'
    1.23 + *                                    obj['-1']  = 'Hello'
    1.24 + */
    1.25 +//-----------------------------------------------------------------------------
    1.26 +var BUGNUMBER = 57043;
    1.27 +var summary = 'Indexing object properties by signed numerical literals -'
    1.28 +  var statprefix = 'Adding a property to test object with an index of ';
    1.29 +var statsuffix =  ', testing it now -';
    1.30 +var propprefix = 'This is property ';
    1.31 +var obj = new Object();
    1.32 +var status = ''; var actual = ''; var expect = ''; var value = '';
    1.33 +
    1.34 +
    1.35 +//  various indices to try -
    1.36 +var index =
    1.37 +  [-1073741825, -1073741824, -1073741823, -5000, -507, -3, -2, -1, -0, 0, 1, 2, 3, 1073741823, 1073741824, 1073741825];
    1.38 +
    1.39 +
    1.40 +//------------------------------------------------------------------------------------------------- 
    1.41 +test();
    1.42 +//-------------------------------------------------------------------------------------------------
    1.43 +
    1.44 +
    1.45 +function test()
    1.46 +{
    1.47 +  enterFunc ('test');
    1.48 +  printBugNumber(BUGNUMBER);
    1.49 +  printStatus (summary);
    1.50 +
    1.51 +  for (var j in index) {testProperty(index[j]);}
    1.52 +
    1.53 +  exitFunc ('test');
    1.54 +}
    1.55 +
    1.56 +
    1.57 +function testProperty(i)
    1.58 +{
    1.59 +  status = getStatus(i);
    1.60 +
    1.61 +  // try to assign a property using the given index -
    1.62 +  obj[i] = value = (propprefix  +  i);  
    1.63 + 
    1.64 +  // try to read the property back via the index (as number) -
    1.65 +  expect = value;
    1.66 +  actual = obj[i];
    1.67 +  reportCompare(expect, actual, status); 
    1.68 +
    1.69 +  // try to read the property back via the index as string -
    1.70 +  expect = value;
    1.71 +  actual = obj[String(i)];
    1.72 +  reportCompare(expect, actual, status);
    1.73 +}
    1.74 +
    1.75 +function positive(n) { return 1 / n > 0; }
    1.76 +
    1.77 +function getStatus(i)
    1.78 +{
    1.79 +  return statprefix +
    1.80 +         (positive(i) ? i : "-" + -i) +
    1.81 +         statsuffix;
    1.82 +}

mercurial