OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Crankshaft changes the stack usage and messes up the binary search for the |
| 6 // stack depth that causes a stack overflow. The issue only arises without |
| 7 // regexp optimization, which can happen on pages that create a lot of regexps. |
| 8 // Flags: --nocrankshaft --noregexp-optimization |
| 9 |
| 10 // Should not crash with a stack overflow in the regexp compiler, even when the |
| 11 // JS has used most of the stack. |
| 12 function use_space_then_do_test(depth) { |
| 13 try { |
| 14 // The "+ depth" is to avoid the regexp compilation cache. |
| 15 var regexp_src = repeat(".(.)", 12) + depth; |
| 16 use_space(depth, regexp_src); |
| 17 return true; |
| 18 } catch (e) { |
| 19 assertFalse(("" + e).indexOf("tack") == -1); // Check for [Ss]tack. |
| 20 return false; |
| 21 } |
| 22 } |
| 23 |
| 24 function use_space(n, regexp_src) { |
| 25 if (--n == 0) { |
| 26 do_test(regexp_src); |
| 27 return; |
| 28 } |
| 29 use_space(n, regexp_src); |
| 30 } |
| 31 |
| 32 function repeat(str, n) { |
| 33 var answer = ""; |
| 34 while (n-- != 0) { |
| 35 answer += str; |
| 36 } |
| 37 return answer; |
| 38 } |
| 39 |
| 40 var subject = repeat("y", 200); |
| 41 |
| 42 function do_test(regexp_src) { |
| 43 var re = new RegExp(regexp_src); |
| 44 re.test(subject); |
| 45 } |
| 46 |
| 47 function try_different_stack_limits() { |
| 48 var lower = 100; |
| 49 var higher = 100000; |
| 50 while (lower < higher - 1) { |
| 51 var average = Math.floor((lower + higher) / 2); |
| 52 if (use_space_then_do_test(average)) { |
| 53 lower = average; |
| 54 } else { |
| 55 higher = average; |
| 56 } |
| 57 } |
| 58 for (var i = lower - 5; i < higher + 5; i++) { |
| 59 use_space_then_do_test(i); |
| 60 } |
| 61 } |
| 62 |
| 63 try_different_stack_limits(); |
OLD | NEW |