michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Date: 03 December 2000 michael@0: * michael@0: * michael@0: * SUMMARY: This test arose from Bugzilla bug 57043: michael@0: * "Negative integers as object properties: strange behavior!" michael@0: * michael@0: * We check that object properties may be indexed by signed michael@0: * numeric literals, as in assignments like obj[-1] = 'Hello' michael@0: * michael@0: * NOTE: it should not matter whether we provide the literal with michael@0: * quotes around it or not; e.g. these should be equivalent: michael@0: * michael@0: * obj[-1] = 'Hello' michael@0: * obj['-1'] = 'Hello' michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 57043; michael@0: var summary = 'Indexing object properties by signed numerical literals -' michael@0: var statprefix = 'Adding a property to test object with an index of '; michael@0: var statsuffix = ', testing it now -'; michael@0: var propprefix = 'This is property '; michael@0: var obj = new Object(); michael@0: var status = ''; var actual = ''; var expect = ''; var value = ''; michael@0: michael@0: michael@0: // various indices to try - michael@0: var index = michael@0: [-1073741825, -1073741824, -1073741823, -5000, -507, -3, -2, -1, -0, 0, 1, 2, 3, 1073741823, 1073741824, 1073741825]; michael@0: michael@0: michael@0: //------------------------------------------------------------------------------------------------- michael@0: test(); michael@0: //------------------------------------------------------------------------------------------------- michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: for (var j in index) {testProperty(index[j]);} michael@0: michael@0: exitFunc ('test'); michael@0: } michael@0: michael@0: michael@0: function testProperty(i) michael@0: { michael@0: status = getStatus(i); michael@0: michael@0: // try to assign a property using the given index - michael@0: obj[i] = value = (propprefix + i); michael@0: michael@0: // try to read the property back via the index (as number) - michael@0: expect = value; michael@0: actual = obj[i]; michael@0: reportCompare(expect, actual, status); michael@0: michael@0: // try to read the property back via the index as string - michael@0: expect = value; michael@0: actual = obj[String(i)]; michael@0: reportCompare(expect, actual, status); michael@0: } michael@0: michael@0: function positive(n) { return 1 / n > 0; } michael@0: michael@0: function getStatus(i) michael@0: { michael@0: return statprefix + michael@0: (positive(i) ? i : "-" + -i) + michael@0: statsuffix; michael@0: }