]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Regress/regress-57043.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 03 December 2000
23 * SUMMARY: This test arose from Bugzilla bug 57043:
24 * "Negative integers as object properties: strange behavior!"
26 * We check that object properties may be indexed by signed
27 * numeric literals, as in assignments like obj[-1] = 'Hello'
29 * NOTE: it should not matter whether we provide the literal with
30 * quotes around it or not; e.g. these should be equivalent:
35 //-------------------------------------------------------------------------------------------------
37 var summary
= 'Indexing object properties by signed numerical literals -'
38 var statprefix
= 'Adding a property to test object with an index of ';
39 var statsuffix
= ', testing it now -';
40 var propprefix
= 'This is property ';
41 var obj
= new Object();
42 var status
= ''; var actual
= ''; var expect
= ''; var value
= '';
45 // various indices to try -
46 var index
= Array(-5000, -507, -3, -2, -1, 0, 1, 2, 3);
49 //-------------------------------------------------------------------------------------------------
51 //-------------------------------------------------------------------------------------------------
58 printStatus (summary
);
60 for (j
in index
) {testProperty(index
[j
]);}
66 function testProperty(i
)
68 status
= getStatus(i
);
70 // try to assign a property using the given index -
71 obj
[i
] = value
= (propprefix
+ i
);
73 // try to read the property back via the index (as number) -
76 reportCompare(expect
, actual
, status
);
78 // try to read the property back via the index as string -
80 actual
= obj
[String(i
)];
81 reportCompare(expect
, actual
, status
);
87 return (statprefix
+ i
+ statsuffix
);