1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Array/array-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * Date: 24 September 2001 1.11 + * 1.12 + * SUMMARY: Truncating arrays that have decimal property names. 1.13 + * From correspondence with Igor Bukanov <igor@icesoft.no>: 1.14 + */ 1.15 +//----------------------------------------------------------------------------- 1.16 +var UBound = 0; 1.17 +var BUGNUMBER = '(none)'; 1.18 +var summary = 'Truncating arrays that have decimal property names'; 1.19 +var BIG_INDEX = 4294967290; 1.20 +var status = ''; 1.21 +var statusitems = []; 1.22 +var actual = ''; 1.23 +var actualvalues = []; 1.24 +var expect= ''; 1.25 +var expectedvalues = []; 1.26 + 1.27 + 1.28 +var arr = Array(BIG_INDEX); 1.29 +arr[BIG_INDEX - 1] = 'a'; 1.30 +arr[BIG_INDEX - 10000] = 'b'; 1.31 +arr[BIG_INDEX - 0.5] = 'c'; // not an array index - but a valid property name 1.32 +// Truncate the array - 1.33 +arr.length = BIG_INDEX - 5000; 1.34 + 1.35 + 1.36 +// Enumerate its properties with for..in 1.37 +var s = ''; 1.38 +for (var i in arr) 1.39 +{ 1.40 + s += arr[i]; 1.41 +} 1.42 + 1.43 + 1.44 +/* 1.45 + * We expect s == 'cb' or 'bc' (EcmaScript does not fix the order). 1.46 + * Note 'c' is included: for..in includes ALL enumerable properties, 1.47 + * not just array-index properties. The bug was: Rhino gave s == ''. 1.48 + */ 1.49 +status = inSection(1); 1.50 +actual = sortThis(s); 1.51 +expect = 'bc'; 1.52 +addThis(); 1.53 + 1.54 + 1.55 + 1.56 +//----------------------------------------------------------------------------- 1.57 +test(); 1.58 +//----------------------------------------------------------------------------- 1.59 + 1.60 + 1.61 + 1.62 +function sortThis(str) 1.63 +{ 1.64 + var chars = str.split(''); 1.65 + chars = chars.sort(); 1.66 + return chars.join(''); 1.67 +} 1.68 + 1.69 + 1.70 +function addThis() 1.71 +{ 1.72 + statusitems[UBound] = status; 1.73 + actualvalues[UBound] = actual; 1.74 + expectedvalues[UBound] = expect; 1.75 + UBound++; 1.76 +} 1.77 + 1.78 + 1.79 +function test() 1.80 +{ 1.81 + enterFunc ('test'); 1.82 + printBugNumber(BUGNUMBER); 1.83 + printStatus (summary); 1.84 + 1.85 + for (var i=0; i<UBound; i++) 1.86 + { 1.87 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.88 + } 1.89 + 1.90 + exitFunc ('test'); 1.91 +}