js/src/tests/ecma_3/extensions/regress-188206-02.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/extensions/regress-188206-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     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 UBound = 0;
    1.11 +var BUGNUMBER = 188206;
    1.12 +var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors';
    1.13 +var CHECK_PASSED = 'Should not generate an error';
    1.14 +var CHECK_FAILED = 'Generated an error!';
    1.15 +var status = '';
    1.16 +var statusitems = [];
    1.17 +var actual = '';
    1.18 +var actualvalues = [];
    1.19 +var expect= '';
    1.20 +var expectedvalues = [];
    1.21 +
    1.22 +
    1.23 +/*
    1.24 + * Misusing the {DecmalDigits} quantifier - according to ECMA,
    1.25 + * but not according to Perl.
    1.26 + *
    1.27 + * ECMA-262 Edition 3 prohibits the use of unescaped braces in
    1.28 + * regexp patterns, unless they form part of a quantifier.
    1.29 + *
    1.30 + * Hovever, Perl does not prohibit this. If not used as part
    1.31 + * of a quantifer, Perl treats braces literally.
    1.32 + *
    1.33 + * We decided to follow Perl on this for backward compatibility.
    1.34 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=190685.
    1.35 + *
    1.36 + * Therefore NONE of the following ECMA violations should generate
    1.37 + * a SyntaxError. Note we use checkThis() instead of testThis().
    1.38 + */
    1.39 +status = inSection(13);
    1.40 +checkThis(' /a*{/ ');
    1.41 +
    1.42 +status = inSection(14);
    1.43 +checkThis(' /a{}/ ');
    1.44 +
    1.45 +status = inSection(15);
    1.46 +checkThis(' /{a/ ');
    1.47 +
    1.48 +status = inSection(16);
    1.49 +checkThis(' /}a/ ');
    1.50 +
    1.51 +status = inSection(17);
    1.52 +checkThis(' /x{abc}/ ');
    1.53 +
    1.54 +status = inSection(18);
    1.55 +checkThis(' /{{0}/ ');
    1.56 +
    1.57 +status = inSection(19);
    1.58 +checkThis(' /{{1}/ ');
    1.59 +
    1.60 +status = inSection(20);
    1.61 +checkThis(' /x{{0}/ ');
    1.62 +
    1.63 +status = inSection(21);
    1.64 +checkThis(' /x{{1}/ ');
    1.65 +
    1.66 +status = inSection(22);
    1.67 +checkThis(' /x{{0}}/ ');
    1.68 +
    1.69 +status = inSection(23);
    1.70 +checkThis(' /x{{1}}/ ');
    1.71 +
    1.72 +status = inSection(24);
    1.73 +checkThis(' /x{{0}}/ ');
    1.74 +
    1.75 +status = inSection(25);
    1.76 +checkThis(' /x{{1}}/ ');
    1.77 +
    1.78 +status = inSection(26);
    1.79 +checkThis(' /x{{0}}/ ');
    1.80 +
    1.81 +status = inSection(27);
    1.82 +checkThis(' /x{{1}}/ ');
    1.83 +
    1.84 +
    1.85 +//-----------------------------------------------------------------------------
    1.86 +test();
    1.87 +//-----------------------------------------------------------------------------
    1.88 +
    1.89 +
    1.90 +
    1.91 +/*
    1.92 + * Allowed syntax shouldn't generate any errors
    1.93 + */
    1.94 +function checkThis(sAllowedSyntax)
    1.95 +{
    1.96 +  expect = CHECK_PASSED;
    1.97 +  actual = CHECK_PASSED;
    1.98 +
    1.99 +  try
   1.100 +  {
   1.101 +    eval(sAllowedSyntax);
   1.102 +  }
   1.103 +  catch(e)
   1.104 +  {
   1.105 +    actual = CHECK_FAILED;
   1.106 +  }
   1.107 +
   1.108 +  statusitems[UBound] = status;
   1.109 +  expectedvalues[UBound] = expect;
   1.110 +  actualvalues[UBound] = actual;
   1.111 +  UBound++;
   1.112 +}
   1.113 +
   1.114 +
   1.115 +function test()
   1.116 +{
   1.117 +  enterFunc('test');
   1.118 +  printBugNumber(BUGNUMBER);
   1.119 +  printStatus(summary);
   1.120 +
   1.121 +  for (var i=0; i<UBound; i++)
   1.122 +  {
   1.123 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.124 +  }
   1.125 +
   1.126 +  exitFunc ('test');
   1.127 +}

mercurial