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 (at) icesoft.no, pschwartau (at) netscape.com 20 * Date: 24 September 2001 21 * 22 * SUMMARY: Truncating arrays that have decimal property names. 23 * From correspondence with Igor Bukanov <igor (at) icesoft.no>: 24 */ 25 //----------------------------------------------------------------------------- 26 var UBound = 0; 27 var bug = '(none)'; 28 var summary = 'Truncating arrays that have decimal property names'; 29 var BIG_INDEX = 4294967290; 30 var status = ''; 31 var statusitems = []; 32 var actual = ''; 33 var actualvalues = []; 34 var expect= ''; 35 var expectedvalues = []; 36 37 38 var arr = Array(BIG_INDEX); 39 arr[BIG_INDEX - 1] = 'a'; 40 arr[BIG_INDEX - 10000] = 'b'; 41 arr[BIG_INDEX - 0.5] = 'c'; // not an array index - but a valid property name 42 // Truncate the array - 43 arr.length = BIG_INDEX - 5000; 44 45 46 // Enumerate its properties with for..in 47 var s = ''; 48 for (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 */ 59 status = inSection(1); 60 actual = sortThis(s); 61 expect = 'bc'; 62 addThis(); 63 64 65 66 //----------------------------------------------------------------------------- 67 test(); 68 //----------------------------------------------------------------------------- 69 70 71 72 function sortThis(str) 73 { 74 var chars = str.split(''); 75 chars = chars.sort(); 76 return chars.join(''); 77 } 78 79 80 function addThis() 81 { 82 statusitems[UBound] = status; 83 actualvalues[UBound] = actual; 84 expectedvalues[UBound] = expect; 85 UBound++; 86 } 87 88 89 function 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