js/src/tests/js1_5/Regress/regress-57043.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * Date: 03 December 2000
michael@0 8 *
michael@0 9 *
michael@0 10 * SUMMARY: This test arose from Bugzilla bug 57043:
michael@0 11 * "Negative integers as object properties: strange behavior!"
michael@0 12 *
michael@0 13 * We check that object properties may be indexed by signed
michael@0 14 * numeric literals, as in assignments like obj[-1] = 'Hello'
michael@0 15 *
michael@0 16 * NOTE: it should not matter whether we provide the literal with
michael@0 17 * quotes around it or not; e.g. these should be equivalent:
michael@0 18 *
michael@0 19 * obj[-1] = 'Hello'
michael@0 20 * obj['-1'] = 'Hello'
michael@0 21 */
michael@0 22 //-----------------------------------------------------------------------------
michael@0 23 var BUGNUMBER = 57043;
michael@0 24 var summary = 'Indexing object properties by signed numerical literals -'
michael@0 25 var statprefix = 'Adding a property to test object with an index of ';
michael@0 26 var statsuffix = ', testing it now -';
michael@0 27 var propprefix = 'This is property ';
michael@0 28 var obj = new Object();
michael@0 29 var status = ''; var actual = ''; var expect = ''; var value = '';
michael@0 30
michael@0 31
michael@0 32 // various indices to try -
michael@0 33 var index =
michael@0 34 [-1073741825, -1073741824, -1073741823, -5000, -507, -3, -2, -1, -0, 0, 1, 2, 3, 1073741823, 1073741824, 1073741825];
michael@0 35
michael@0 36
michael@0 37 //-------------------------------------------------------------------------------------------------
michael@0 38 test();
michael@0 39 //-------------------------------------------------------------------------------------------------
michael@0 40
michael@0 41
michael@0 42 function test()
michael@0 43 {
michael@0 44 enterFunc ('test');
michael@0 45 printBugNumber(BUGNUMBER);
michael@0 46 printStatus (summary);
michael@0 47
michael@0 48 for (var j in index) {testProperty(index[j]);}
michael@0 49
michael@0 50 exitFunc ('test');
michael@0 51 }
michael@0 52
michael@0 53
michael@0 54 function testProperty(i)
michael@0 55 {
michael@0 56 status = getStatus(i);
michael@0 57
michael@0 58 // try to assign a property using the given index -
michael@0 59 obj[i] = value = (propprefix + i);
michael@0 60
michael@0 61 // try to read the property back via the index (as number) -
michael@0 62 expect = value;
michael@0 63 actual = obj[i];
michael@0 64 reportCompare(expect, actual, status);
michael@0 65
michael@0 66 // try to read the property back via the index as string -
michael@0 67 expect = value;
michael@0 68 actual = obj[String(i)];
michael@0 69 reportCompare(expect, actual, status);
michael@0 70 }
michael@0 71
michael@0 72 function positive(n) { return 1 / n > 0; }
michael@0 73
michael@0 74 function getStatus(i)
michael@0 75 {
michael@0 76 return statprefix +
michael@0 77 (positive(i) ? i : "-" + -i) +
michael@0 78 statsuffix;
michael@0 79 }

mercurial