js/src/tests/js1_5/Array/array-001.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     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 = [];
    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;
    33 // Enumerate its properties with for..in
    34 var s = '';
    35 for (var i in arr)
    36 {
    37   s += arr[i];
    38 }
    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();
    53 //-----------------------------------------------------------------------------
    54 test();
    55 //-----------------------------------------------------------------------------
    59 function sortThis(str)
    60 {
    61   var chars = str.split('');
    62   chars = chars.sort();
    63   return chars.join('');
    64 }
    67 function addThis()
    68 {
    69   statusitems[UBound] = status;
    70   actualvalues[UBound] = actual;
    71   expectedvalues[UBound] = expect;
    72   UBound++;
    73 }
    76 function test()
    77 {
    78   enterFunc ('test');
    79   printBugNumber(BUGNUMBER);
    80   printStatus (summary);
    82   for (var i=0; i<UBound; i++)
    83   {
    84     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    85   }
    87   exitFunc ('test');
    88 }

mercurial