See bug 18086 -- let's do that optimization in WREC. Here's what I think can be a layout test: // Check that an initial ^ will result in a faster match fail. var s = "a"; var i; for (i = 0; i < 20; i++) s = s + s; function test(string, regexp) { var start = new Date; for (i = 0; i < 100; i++) regexp.test(s); return new Date - start; } var result1 = test(s, /b/); var result2 = test(s, /^b/); alert(result1); alert(result2); if ((result1 - result2) / result1 > .75) testPassed("Congrats, your browser didn't hang!"); testFailed("/^b/ did not discover a match failure faster than /b/"); var successfullyParsed = true;
This optimization now exists in YARR.