]>
Commit | Line | Data |
---|---|---|
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 | //------------------------------------------------------------------------------------------------- | |
36 | var bug = 57043; | |
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 = ''; | |
43 | ||
44 | ||
45 | // various indices to try - | |
46 | var index = Array(-5000, -507, -3, -2, -1, 0, 1, 2, 3); | |
47 | ||
48 | ||
49 | //------------------------------------------------------------------------------------------------- | |
50 | test(); | |
51 | //------------------------------------------------------------------------------------------------- | |
52 | ||
53 | ||
54 | function 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 | ||
66 | function 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 | ||
85 | function getStatus(i) | |
86 | { | |
87 | return (statprefix + i + statsuffix); | |
88 | } |