• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
17* All Rights Reserved.
18*
19* Contributor(s): igor@icesoft.no, pschwartau@netscape.com
20* Date: 24 September 2001
21*
22* SUMMARY: Truncating arrays that have decimal property names.
23* From correspondence with Igor Bukanov <igor@icesoft.no>:
24*/
25//-----------------------------------------------------------------------------
26var UBound = 0;
27var bug = '(none)';
28var summary = 'Truncating arrays that have decimal property names';
29var BIG_INDEX = 4294967290;
30var status = '';
31var statusitems = [];
32var actual = '';
33var actualvalues = [];
34var expect= '';
35var expectedvalues = [];
36
37
38var arr = Array(BIG_INDEX);
39arr[BIG_INDEX - 1] = 'a';
40arr[BIG_INDEX - 10000] = 'b';
41arr[BIG_INDEX - 0.5] = 'c';  // not an array index - but a valid property name
42// Truncate the array -
43arr.length = BIG_INDEX - 5000;
44
45
46// Enumerate its properties with for..in
47var s = '';
48for (var i in arr)
49{
50  s += arr[i];
51}
52
53
54/*
55 * We expect s == 'cb' or 'bc' (EcmaScript does not fix the order).
56 * Note 'c' is included: for..in includes ALL enumerable properties,
57 * not just array-index properties. The bug was: Rhino gave s == ''.
58 */
59status = inSection(1);
60actual = sortThis(s);
61expect = 'bc';
62addThis();
63
64
65
66//-----------------------------------------------------------------------------
67test();
68//-----------------------------------------------------------------------------
69
70
71
72function sortThis(str)
73{
74  var chars = str.split('');
75  chars = chars.sort();
76  return chars.join('');
77}
78
79
80function addThis()
81{
82  statusitems[UBound] = status;
83  actualvalues[UBound] = actual;
84  expectedvalues[UBound] = expect;
85  UBound++;
86}
87
88
89function test()
90{
91  enterFunc ('test');
92  printBugNumber (bug);
93  printStatus (summary);
94
95  for (var i=0; i<UBound; i++)
96  {
97    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
98  }
99
100  exitFunc ('test');
101}
102