array-001.js (1963B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 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: 24 September 2001 8 * 9 * SUMMARY: Truncating arrays that have decimal property names. 10 * From correspondence with Igor Bukanov <igor@icesoft.no>: 11 */ 12 //----------------------------------------------------------------------------- 13 var UBound = 0; 14 var BUGNUMBER = '(none)'; 15 var summary = 'Truncating arrays that have decimal property names'; 16 var BIG_INDEX = 4294967290; 17 var status = ''; 18 var statusitems = []; 19 var actual = ''; 20 var actualvalues = []; 21 var expect= ''; 22 var expectedvalues = []; 23 24 25 var arr = Array(BIG_INDEX); 26 arr[BIG_INDEX - 1] = 'a'; 27 arr[BIG_INDEX - 10000] = 'b'; 28 arr[BIG_INDEX - 0.5] = 'c'; // not an array index - but a valid property name 29 // Truncate the array - 30 arr.length = BIG_INDEX - 5000; 31 32 33 // Enumerate its properties with for..in 34 var s = ''; 35 for (var i in arr) 36 { 37 s += arr[i]; 38 } 39 40 41 /* 42 * We expect s == 'cb' or 'bc' (EcmaScript does not fix the order). 43 * Note 'c' is included: for..in includes ALL enumerable properties, 44 * not just array-index properties. The bug was: Rhino gave s == ''. 45 */ 46 status = inSection(1); 47 actual = sortThis(s); 48 expect = 'bc'; 49 addThis(); 50 51 52 53 //----------------------------------------------------------------------------- 54 test(); 55 //----------------------------------------------------------------------------- 56 57 58 59 function sortThis(str) 60 { 61 var chars = str.split(''); 62 chars = chars.sort(); 63 return chars.join(''); 64 } 65 66 67 function addThis() 68 { 69 statusitems[UBound] = status; 70 actualvalues[UBound] = actual; 71 expectedvalues[UBound] = expect; 72 UBound++; 73 } 74 75 76 function test() 77 { 78 printBugNumber(BUGNUMBER); 79 printStatus (summary); 80 81 for (var i=0; i<UBound; i++) 82 { 83 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 84 } 85 }