blob: 914a934d5e367784d64f512f83588ff03c8e7485 [file] [log] [blame]
description('Test that we do not overflow the stack while handling regular expressions');
// Base case.
shouldThrow('new RegExp(Array(50000).join("(") + "a" + Array(50000).join(")"))', '"SyntaxError: Invalid regular expression: too many nested disjunctions"');
{ // Verify that a deep JS stack does not help avoiding the error.
function recursiveCall(depth) {
if (!(depth % 10)) {
debug("Creating RegExp at depth " + depth);
shouldThrow('new RegExp(Array(50000).join("(") + "a" + Array(50000).join(")"))', '"SyntaxError: Invalid regular expression: too many nested disjunctions"');
}
if (depth < 100) {
recursiveCall(depth + 1);
}
}
recursiveCall(0);
}
{ // Have the deepest nested subpattern surrounded by other expressions.
var expression = "";
for (let i = 0; i < 50000; ++i) {
expression += "((a)(";
}
expression += "b";
for (let i = 0; i < 50000; ++i) {
expression += ")(c))";
}
shouldThrow('new RegExp(expression)', '"SyntaxError: Invalid regular expression: too many nested disjunctions"');
}