Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-57043.js

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