js/src/tests/js1_5/String/regress-179068.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/String/regress-179068.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     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 + *
    1.11 + * Date:    09 November 2002
    1.12 + * SUMMARY: Test that interpreter can handle string literals exceeding 64K
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=179068
    1.14 + *
    1.15 + * Test that the interpreter can handle string literals exceeding 64K limit.
    1.16 + * For that the script passes to eval() "str ='LONG_STRING_LITERAL';" where
    1.17 + * LONG_STRING_LITERAL is a string with 200K chars.
    1.18 + *
    1.19 + *   Igor Bukanov explains the technique used below:
    1.20 + *
    1.21 + * > Philip Schwartau wrote:
    1.22 + * >...
    1.23 + * > Here is the heart of the testcase:
    1.24 + * >
    1.25 + * >   // Generate 200K long string
    1.26 + * >   var long_str = duplicate(LONG_STR_SEED, N);
    1.27 + * >   var str = "";
    1.28 + * >   eval("str='".concat(long_str, "';"));
    1.29 + * >   var test_is_ok = (str.length == LONG_STR_SEED.length * N);
    1.30 + * >
    1.31 + * >
    1.32 + * > The testcase creates two identical strings, |long_str| and |str|. It
    1.33 + * > uses eval() simply to assign the value of |long_str| to |str|. Why is
    1.34 + * > it necessary to have the variable |str|, then? Why not just create
    1.35 + * > |long_str| and test it? Wouldn't this be enough:
    1.36 + * >
    1.37 + * >   // Generate 200K long string
    1.38 + * >   var long_str = duplicate(LONG_STR_SEED, N);
    1.39 + * >   var test_is_ok = (long_str.length == LONG_STR_SEED.length * N);
    1.40 + * >
    1.41 + * > Or do we specifically need to test eval() to exercise the interpreter?
    1.42 + *
    1.43 + * The reason for eval is to test string literals like in 'a string literal
    1.44 + * with 100 000 characters...', Rhino deals fine with strings generated at
    1.45 + * run time where lengths > 64K. Without eval it would be necessary to have
    1.46 + * a test file excedding 64K which is not that polite for CVS and then a
    1.47 + * special treatment for the compiled mode in Rhino should be added.
    1.48 + *
    1.49 + *
    1.50 + * >
    1.51 + * > If so, is it important to use the concat() method in the assignment, as
    1.52 + * > you have done: |eval("str='".concat(long_str, "';"))|, or can we simply
    1.53 + * > do |eval("str = long_str;")| ?
    1.54 + *
    1.55 + * The concat is a replacement for eval("str='"+long_str+"';"), but as
    1.56 + * long_str is huge, this leads to constructing first a new string via
    1.57 + * "str='"+long_str and then another one via ("str='"+long_str) + "';"
    1.58 + * which takes time under JDK 1.1 on a something like StrongArm 200MHz.
    1.59 + * Calling concat makes less copies, that is why it is used in the
    1.60 + * duplicate function and this is faster then doing recursion like in the
    1.61 + * test case to test that 64K different string literals can be handled.
    1.62 + *
    1.63 + */
    1.64 +//-----------------------------------------------------------------------------
    1.65 +var UBound = 0;
    1.66 +var BUGNUMBER = 179068;
    1.67 +var summary = 'Test that interpreter can handle string literals exceeding 64K';
    1.68 +var status = '';
    1.69 +var statusitems = [];
    1.70 +var actual = '';
    1.71 +var actualvalues = [];
    1.72 +var expect= '';
    1.73 +var expectedvalues = [];
    1.74 +var LONG_STR_SEED = "0123456789";
    1.75 +var N = 20 * 1024;
    1.76 +var str = "";
    1.77 +
    1.78 +
    1.79 +// Generate 200K long string and assign it to |str| via eval()
    1.80 +var long_str = duplicate(LONG_STR_SEED, N);
    1.81 +eval("str='".concat(long_str, "';"));
    1.82 +
    1.83 +status = inSection(1);
    1.84 +actual = str.length == LONG_STR_SEED.length * N
    1.85 +  expect = true;
    1.86 +addThis();
    1.87 +
    1.88 +
    1.89 +
    1.90 +//-----------------------------------------------------------------------------
    1.91 +test();
    1.92 +//-----------------------------------------------------------------------------
    1.93 +
    1.94 +
    1.95 +
    1.96 +function duplicate(str, count)
    1.97 +{
    1.98 +  var tmp = new Array(count);
    1.99 +
   1.100 +  while (count != 0)
   1.101 +    tmp[--count] = str;
   1.102 +
   1.103 +  return String.prototype.concat.apply("", tmp);
   1.104 +}
   1.105 +
   1.106 +
   1.107 +function addThis()
   1.108 +{
   1.109 +  statusitems[UBound] = status;
   1.110 +  actualvalues[UBound] = actual;
   1.111 +  expectedvalues[UBound] = expect;
   1.112 +  UBound++;
   1.113 +}
   1.114 +
   1.115 +
   1.116 +function test()
   1.117 +{
   1.118 +  enterFunc('test');
   1.119 +  printBugNumber(BUGNUMBER);
   1.120 +  printStatus(summary);
   1.121 +
   1.122 +  for (var i=0; i<UBound; i++)
   1.123 +  {
   1.124 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.125 +  }
   1.126 +
   1.127 +  exitFunc ('test');
   1.128 +}

mercurial