js/src/tests/js1_5/Regress/regress-280769-4.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Regress/regress-280769-4.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     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 +var BUGNUMBER = 280769;
    1.11 +var summary = 'Do not overflow 64K length of char sequence in RegExp []';
    1.12 +var actual = 'No Crash';
    1.13 +var expect = 'No Crash';
    1.14 +
    1.15 +printBugNumber(BUGNUMBER);
    1.16 +printStatus (summary);
    1.17 +
    1.18 +
    1.19 +var N = 20 * 1000; // It should be that N*6  > 64K and N < 32K
    1.20 +
    1.21 +var prefixes = ["000", "00", "0"];
    1.22 +
    1.23 +function to_4_hex(i)
    1.24 +{
    1.25 +  var printed = i.toString(16);
    1.26 +  if (printed.length < 4) {
    1.27 +    printed= prefixes[printed.length - 1]+printed;
    1.28 +  }
    1.29 +  return printed;
    1.30 +
    1.31 +}
    1.32 +
    1.33 +var a = new Array(N);
    1.34 +for (var i = 0; i != N; ++i) {
    1.35 +  a[i] = to_4_hex(2*i);
    1.36 +}
    1.37 +
    1.38 +var str = '[\\u'+a.join('\\u')+']';
    1.39 +// str is [\u0000\u0002\u0004...\u<printed value of 2N>]
    1.40 +
    1.41 +var re = new RegExp(str);
    1.42 +
    1.43 +var string_to_match = String.fromCharCode(2 * (N - 1));
    1.44 +
    1.45 +var value = re.exec(string_to_match);
    1.46 +
    1.47 +var expect =  string_to_match;
    1.48 +var actual = value ? value[0] : value;
    1.49 +
    1.50 +reportCompare(expect, actual, summary);

mercurial