tor-browser

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

regress-159334.js (2108B)


      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:    31 Oct 2002
      9 * SUMMARY: Testing script with at least 64K of different string literals
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=159334
     11 *
     12 * Testing that script engine can handle scripts with at least 64K of different
     13 * string literals. The following will evaluate, via eval(), a script like this:
     14 *
     15 *     f('0')
     16 *     f('1')
     17 *     ...
     18 *     f('N - 1')
     19 *
     20 * where N is 0xFFFE
     21 *
     22 */
     23 //-----------------------------------------------------------------------------
     24 var UBound = 0;
     25 var BUGNUMBER = 159334;
     26 var summary = 'Testing script with at least 64K of different string literals';
     27 var status = '';
     28 var statusitems = [];
     29 var actual = '';
     30 var actualvalues = [];
     31 var expect= '';
     32 var expectedvalues = [];
     33 
     34 
     35 var N = 0xFFFE;
     36 
     37 // Create big string for eval recursively to avoid N*N behavior
     38 // on string concatenation
     39 var long_eval = buildEval_r(0, N);
     40 
     41 // Run it
     42 var test_sum = 0;
     43 function f(str) { test_sum += Number(str); }
     44 eval(long_eval);
     45 
     46 status = inSection(1);
     47 actual = (test_sum == N * (N - 1) / 2);
     48 expect = true;
     49 addThis();
     50 
     51 
     52 
     53 //-----------------------------------------------------------------------------
     54 test();
     55 //-----------------------------------------------------------------------------
     56 
     57 
     58 
     59 function buildEval_r(beginLine, endLine)
     60 {
     61  var count = endLine - beginLine;
     62 
     63  if (count == 0)
     64    return "";
     65 
     66  if (count == 1)
     67    return "f('" + beginLine + "')\n";
     68 
     69  var middle = beginLine + (count >>> 1);
     70  return buildEval_r(beginLine, middle) + buildEval_r(middle, endLine);
     71 }
     72 
     73 
     74 function addThis()
     75 {
     76  statusitems[UBound] = status;
     77  actualvalues[UBound] = actual;
     78  expectedvalues[UBound] = expect;
     79  UBound++;
     80 }
     81 
     82 
     83 function test()
     84 {
     85  printBugNumber(BUGNUMBER);
     86  printStatus(summary);
     87 
     88  for (var i=0; i<UBound; i++)
     89  {
     90    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
     91  }
     92 }