js/src/tests/ecma_3/RegExp/regress-188206.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
     6 /*
     7  *
     8  * Date:    21 January 2003
     9  * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors
    10  *
    11  * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206
    12  * and http://bugzilla.mozilla.org/show_bug.cgi?id=85721#c48 etc.
    13  * and http://bugzilla.mozilla.org/show_bug.cgi?id=190685
    14  * and http://bugzilla.mozilla.org/show_bug.cgi?id=197451
    15  */
    16 //-----------------------------------------------------------------------------
    17 var UBound = 0;
    18 var BUGNUMBER = 188206;
    19 var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors';
    20 var TEST_PASSED = 'SyntaxError';
    21 var TEST_FAILED = 'Generated an error, but NOT a SyntaxError!';
    22 var TEST_FAILED_BADLY = 'Did not generate ANY error!!!';
    23 var CHECK_PASSED = 'Should not generate an error';
    24 var CHECK_FAILED = 'Generated an error!';
    25 var status = '';
    26 var statusitems = [];
    27 var actual = '';
    28 var actualvalues = [];
    29 var expect= '';
    30 var expectedvalues = [];
    33 /*
    34  * All the following are invalid uses of regexp quantifiers and
    35  * should generate SyntaxErrors. That's what we're testing for.
    36  *
    37  * To allow the test to compile and run, we have to hide the errors
    38  * inside eval strings, and check they are caught at run-time -
    39  *
    40  */
    41 status = inSection(1);
    42 testThis(' /a**/ ');
    44 status = inSection(2);
    45 testThis(' /a***/ ');
    47 status = inSection(3);
    48 testThis(' /a++/ ');
    50 status = inSection(4);
    51 testThis(' /a+++/ ');
    53 /*
    54  * The ? quantifier, unlike * or +, may appear twice in succession.
    55  * Thus we need at least three in a row to provoke a SyntaxError -
    56  */
    58 status = inSection(5);
    59 testThis(' /a???/ ');
    61 status = inSection(6);
    62 testThis(' /a????/ ');
    65 /*
    66  * Now do some weird things on the left side of the regexps -
    67  */
    68 status = inSection(9);
    69 testThis(' /+a/ ');
    71 status = inSection(10);
    72 testThis(' /++a/ ');
    74 status = inSection(11);
    75 testThis(' /?a/ ');
    77 status = inSection(12);
    78 testThis(' /??a/ ');
    81 /*
    82  * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl.
    83  *
    84  * Just as with the * and + quantifiers above, can't have two {DecmalDigits}
    85  * quantifiers in succession - it's a SyntaxError.
    86  */
    87 status = inSection(28);
    88 testThis(' /x{1}{1}/ ');
    90 status = inSection(29);
    91 testThis(' /x{1,}{1}/ ');
    93 status = inSection(30);
    94 testThis(' /x{1,2}{1}/ ');
    96 status = inSection(31);
    97 testThis(' /x{1}{1,}/ ');
    99 status = inSection(32);
   100 testThis(' /x{1,}{1,}/ ');
   102 status = inSection(33);
   103 testThis(' /x{1,2}{1,}/ ');
   105 status = inSection(34);
   106 testThis(' /x{1}{1,2}/ ');
   108 status = inSection(35);
   109 testThis(' /x{1,}{1,2}/ ');
   111 status = inSection(36);
   112 testThis(' /x{1,2}{1,2}/ ');
   116 //-----------------------------------------------------------------------------
   117 test();
   118 //-----------------------------------------------------------------------------
   122 /*
   123  * Invalid syntax should generate a SyntaxError
   124  */
   125 function testThis(sInvalidSyntax)
   126 {
   127   expect = TEST_PASSED;
   128   actual = TEST_FAILED_BADLY;
   130   try
   131   {
   132     eval(sInvalidSyntax);
   133   }
   134   catch(e)
   135   {
   136     if (e instanceof SyntaxError)
   137       actual = TEST_PASSED;
   138     else
   139       actual = TEST_FAILED;
   140   }
   142   statusitems[UBound] = status;
   143   expectedvalues[UBound] = expect;
   144   actualvalues[UBound] = actual;
   145   UBound++;
   146 }
   149 /*
   150  * Allowed syntax shouldn't generate any errors
   151  */
   152 function checkThis(sAllowedSyntax)
   153 {
   154   expect = CHECK_PASSED;
   155   actual = CHECK_PASSED;
   157   try
   158   {
   159     eval(sAllowedSyntax);
   160   }
   161   catch(e)
   162   {
   163     actual = CHECK_FAILED;
   164   }
   166   statusitems[UBound] = status;
   167   expectedvalues[UBound] = expect;
   168   actualvalues[UBound] = actual;
   169   UBound++;
   170 }
   173 function test()
   174 {
   175   enterFunc('test');
   176   printBugNumber(BUGNUMBER);
   177   printStatus(summary);
   179   for (var i=0; i<UBound; i++)
   180   {
   181     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   182   }
   184   exitFunc ('test');
   185 }

mercurial