tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

regress-178722.js (2456B)


      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 *
      8 * Date:    06 November 2002
      9 * SUMMARY: arr.sort() should not output |undefined| when |arr| is empty
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=178722
     11 *
     12 * ECMA-262 Ed.3: 15.4.4.11 Array.prototype.sort (comparefn)
     13 *
     14 * 1. Call the [[Get]] method of this object with argument "length".
     15 * 2. Call ToUint32(Result(1)).
     16 * 3. Perform an implementation-dependent sequence of calls to the [[Get]],
     17 *    [[Put]], and [[Delete]] methods of this object, etc. etc.
     18 * 4. Return this object.
     19 *
     20 *
     21 * Note that sort() is done in-place on |arr|. In other words, sort() is a
     22 * "destructive" method rather than a "functional" method. The return value
     23 * of |arr.sort()| and |arr| are the same object.
     24 *
     25 * If |arr| is an empty array, the return value of |arr.sort()| should be
     26 * an empty array, not the value |undefined| as was occurring in bug 178722.
     27 *
     28 */
     29 //-----------------------------------------------------------------------------
     30 var UBound = 0;
     31 var BUGNUMBER = 178722;
     32 var summary = 'arr.sort() should not output |undefined| when |arr| is empty';
     33 var status = '';
     34 var statusitems = [];
     35 var actual = '';
     36 var actualvalues = [];
     37 var expect= '';
     38 var expectedvalues = [];
     39 var arr;
     40 
     41 
     42 // create empty array or pseudo-array objects in various ways
     43 function f () {return arguments};
     44 var arr5 = f();
     45 arr5.__proto__ = Array.prototype;
     46 
     47 
     48 status = inSection(5);
     49 arr = arr5.sort();
     50 actual = arr instanceof Array && arr.length === 0 && arr === arr5;
     51 expect = true;
     52 addThis();
     53 
     54 
     55 // now do the same thing, with non-default sorting:
     56 function g() {return 1;}
     57 
     58 status = inSection('5a');
     59 arr = arr5.sort(g);
     60 actual = arr instanceof Array && arr.length === 0 && arr === arr5;
     61 expect = true;
     62 addThis();
     63 
     64 
     65 
     66 //-----------------------------------------------------------------------------
     67 test();
     68 //-----------------------------------------------------------------------------
     69 
     70 
     71 
     72 function addThis()
     73 {
     74  statusitems[UBound] = status;
     75  actualvalues[UBound] = actual;
     76  expectedvalues[UBound] = expect;
     77  UBound++;
     78 }
     79 
     80 
     81 function test()
     82 {
     83  printBugNumber(BUGNUMBER);
     84  printStatus(summary);
     85 
     86  for (var i=0; i<UBound; i++)
     87  {
     88    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
     89  }
     90 }