OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions | 5 // modification, are permitted provided that the following conditions |
6 // are met: | 6 // are met: |
7 // 1. Redistributions of source code must retain the above copyright | 7 // 1. Redistributions of source code must retain the above copyright |
8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
9 // 2. Redistributions in binary form must reproduce the above copyright | 9 // 2. Redistributions in binary form must reproduce the above copyright |
10 // notice, this list of conditions and the following disclaimer in the | 10 // notice, this list of conditions and the following disclaimer in the |
11 // documentation and/or other materials provided with the distribution. | 11 // documentation and/or other materials provided with the distribution. |
12 // | 12 // |
13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | 23 |
24 description('Test that if an arrity check causes a stack overflow, the exception
goes to the right catch'); | 24 // Flags: --turbo --allow-natives-syntax |
| 25 |
| 26 var stackOverflowIn20ArgFn = false, reached20ArgFn = false, |
| 27 gotRegexCatch = false, gotDateCatch = false; |
25 | 28 |
26 function funcWith20Args(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, | 29 function funcWith20Args(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, |
27 arg9, arg10, arg11, arg12, arg13, arg14, arg15, | 30 arg9, arg10, arg11, arg12, arg13, arg14, arg15, |
28 arg16, arg17, arg18, arg19, arg20) | 31 arg16, arg17, arg18, arg19, arg20) |
29 { | 32 { |
30 debug("ERROR: Shouldn't arrive in 20 arg function!"); | 33 reached20ArgFn = true; |
31 } | 34 } |
32 | 35 |
33 var gotRightCatch = false, gotWrongCatch1 = false, gotWrongCatch2 = false; | 36 %OptimizeFunctionOnNextCall(funcWith20Args); |
| 37 funcWith20Args(1, 2, 3, 4, 5, 6); |
| 38 reached20ArgFn = false; |
34 | 39 |
35 function test1() | 40 function mutual_recursion_1() |
36 { | 41 { |
37 try { | 42 try { |
38 test2(); | 43 mutual_recursion_2(); |
39 } catch (err) { | 44 } catch (err) { |
40 // Should get here because of stack overflow, | 45 // Should get here because of stack overflow, |
41 // now cause a stack overflow exception due to arrity processing | 46 // now cause a stack overflow exception due to arity processing |
42 try { | 47 try { |
43 var dummy = new RegExp('a|b|c'); | 48 var dummy = new RegExp('a|b|c'); |
44 } catch(err) { | 49 } catch(err) { |
45 // (1) It is dendent on the stack size if we arrive here, in (2) or | 50 // (1) It is dependent on the stack size if we arrive here, in (2) o
r |
46 // both. | 51 // both. |
47 gotWrongCatch1 = true; | 52 gotRegexCatch = true; |
48 } | 53 } |
49 | 54 |
50 try { | 55 try { |
51 funcWith20Args(1, 2, 3); | 56 funcWith20Args(1, 2, 3); |
52 } catch (err2) { | 57 } catch (err2) { |
53 gotRightCatch = true; | 58 stackOverflowIn20ArgFn = true; |
54 } | 59 } |
55 } | 60 } |
56 } | 61 } |
57 | 62 |
58 function test2() | 63 function mutual_recursion_2() |
59 { | 64 { |
60 try { | 65 try { |
61 var dummy = new Date(); | 66 var dummy = new Date(); |
62 } catch(err) { | 67 } catch(err) { |
63 // (2) It is dendent on the stack size if we arrive here, in (1) or | 68 // (2) It is dependent on the stack size if we arrive here, in (1) or |
64 // both. | 69 // both. |
65 gotWrongCatch2 = true; | 70 gotDateCatch = true; |
66 } | 71 } |
67 | 72 |
68 try { | 73 try { |
69 test1(); | 74 mutual_recursion_1(); |
70 } catch (err) { | 75 } catch (err) { |
71 // Should get here because of stack overflow, | 76 // Should get here because of stack overflow, |
72 // now cause a stack overflow exception due to arrity processing | 77 // now cause a stack overflow exception due to arity processing |
73 try { | 78 try { |
74 funcWith20Args(1, 2, 3, 4, 5, 6); | 79 funcWith20Args(1, 2, 3, 4, 5, 6); |
75 } catch (err2) { | 80 } catch (err2) { |
76 gotRightCatch = true; | 81 stackOverflowIn20ArgFn = true; |
77 } | 82 } |
78 } | 83 } |
79 } | 84 } |
80 | 85 |
81 test1(); | 86 %OptimizeFunctionOnNextCall(mutual_recursion_1); |
| 87 %OptimizeFunctionOnNextCall(mutual_recursion_2); |
82 | 88 |
83 shouldBeTrue("gotRightCatch"); | 89 mutual_recursion_1(); |
| 90 |
| 91 // assertTrue(gotDateCatch || gotRegexCatch); |
| 92 assertTrue(reached20ArgFn); |
| 93 assertTrue(!stackOverflowIn20ArgFn); |
OLD | NEW |