]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/js1_5/Regress/regress-57043.js
JavaScriptCore-521.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_5 / Regress / regress-57043.js
CommitLineData
b37bf2e1
A
1/*
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/
6*
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.
11*
12* The Original Code is mozilla.org code.
13*
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
17* Rights Reserved.
18*
19* Contributor(s): pschwartau@netscape.com
20* Date: 03 December 2000
21*
22*
23* SUMMARY: This test arose from Bugzilla bug 57043:
24* "Negative integers as object properties: strange behavior!"
25*
26* We check that object properties may be indexed by signed
27* numeric literals, as in assignments like obj[-1] = 'Hello'
28*
29* NOTE: it should not matter whether we provide the literal with
30* quotes around it or not; e.g. these should be equivalent:
31*
32* obj[-1] = 'Hello'
33* obj['-1'] = 'Hello'
34*/
35//-------------------------------------------------------------------------------------------------
36var bug = 57043;
37var summary = 'Indexing object properties by signed numerical literals -'
38var statprefix = 'Adding a property to test object with an index of ';
39var statsuffix = ', testing it now -';
40var propprefix = 'This is property ';
41var obj = new Object();
42var status = ''; var actual = ''; var expect = ''; var value = '';
43
44
45// various indices to try -
46var index = Array(-5000, -507, -3, -2, -1, 0, 1, 2, 3);
47
48
49//-------------------------------------------------------------------------------------------------
50test();
51//-------------------------------------------------------------------------------------------------
52
53
54function test()
55{
56 enterFunc ('test');
57 printBugNumber (bug);
58 printStatus (summary);
59
60 for (j in index) {testProperty(index[j]);}
61
62 exitFunc ('test');
63}
64
65
66function testProperty(i)
67{
68 status = getStatus(i);
69
70 // try to assign a property using the given index -
71 obj[i] = value = (propprefix + i);
72
73 // try to read the property back via the index (as number) -
74 expect = value;
75 actual = obj[i];
76 reportCompare(expect, actual, status);
77
78 // try to read the property back via the index as string -
79 expect = value;
80 actual = obj[String(i)];
81 reportCompare(expect, actual, status);
82}
83
84
85function getStatus(i)
86{
87 return (statprefix + i + statsuffix);
88}