1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-119909.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 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: 14 Jan 2002 1.12 + * SUMMARY: Shouldn't crash on regexps with many nested parentheses 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=119909 1.14 + * 1.15 + */ 1.16 +//----------------------------------------------------------------------------- 1.17 +var BUGNUMBER = 119909; 1.18 +var summary = "Shouldn't crash on regexps with many nested parentheses"; 1.19 +var NO_BACKREFS = false; 1.20 +var DO_BACKREFS = true; 1.21 + 1.22 + 1.23 +//-------------------------------------------------- 1.24 +test(); 1.25 +//-------------------------------------------------- 1.26 + 1.27 + 1.28 +function test() 1.29 +{ 1.30 + enterFunc('test'); 1.31 + printBugNumber(BUGNUMBER); 1.32 + printStatus(summary); 1.33 + 1.34 + testThis(500, NO_BACKREFS, 'hello', 'goodbye'); 1.35 + testThis(500, DO_BACKREFS, 'hello', 'goodbye'); 1.36 + 1.37 + reportCompare('No Crash', 'No Crash', ''); 1.38 + 1.39 + exitFunc('test'); 1.40 +} 1.41 + 1.42 + 1.43 +/* 1.44 + * Creates a regexp pattern like (((((((((hello))))))))) 1.45 + * and tests str.search(), str.match(), str.replace() 1.46 + */ 1.47 +function testThis(numParens, doBackRefs, strOriginal, strReplace) 1.48 +{ 1.49 + var openParen = doBackRefs? '(' : '(?:'; 1.50 + var closeParen = ')'; 1.51 + var pattern = ''; 1.52 + 1.53 + for (var i=0; i<numParens; i++) {pattern += openParen;} 1.54 + pattern += strOriginal; 1.55 + for (i=0; i<numParens; i++) {pattern += closeParen;} 1.56 + var re = new RegExp(pattern); 1.57 + 1.58 + var res = strOriginal.search(re); 1.59 + res = strOriginal.match(re); 1.60 + res = strOriginal.replace(re, strReplace); 1.61 +}