Debian Codegraph @

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