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: --allow-natives-syntax |
| 25 |
| 26 var stackOverflowIn20ArgFn = false, gotRegexCatch = false, gotDateCatch = false; |
25 | 27 |
26 function funcWith20Args(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, | 28 function funcWith20Args(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, |
27 arg9, arg10, arg11, arg12, arg13, arg14, arg15, | 29 arg9, arg10, arg11, arg12, arg13, arg14, arg15, |
28 arg16, arg17, arg18, arg19, arg20) | 30 arg16, arg17, arg18, arg19, arg20) |
29 { | 31 { |
30 debug("ERROR: Shouldn't arrive in 20 arg function!"); | 32 assertUnreachable("shouldn't arrive in non-inlined 20 arg function after sta
ck overflow"); |
31 } | 33 } |
32 | 34 |
33 var gotRightCatch = false, gotWrongCatch1 = false, gotWrongCatch2 = false; | 35 // If we should run with --turbo, then make sure {funcWith20Args} does |
| 36 // not get inlined. |
| 37 %NeverOptimizeFunction(funcWith20Args); |
34 | 38 |
35 function test1() | 39 function mutual_recursion_1() |
36 { | 40 { |
37 try { | 41 try { |
38 test2(); | 42 mutual_recursion_2(); |
39 } catch (err) { | 43 } catch (err) { |
40 // Should get here because of stack overflow, | 44 // Should get here because of stack overflow, |
41 // now cause a stack overflow exception due to arrity processing | 45 // now cause a stack overflow exception due to arity processing |
42 try { | 46 try { |
43 var dummy = new RegExp('a|b|c'); | 47 var dummy = new RegExp('a|b|c'); |
44 } catch(err) { | 48 } catch(err) { |
45 // (1) It is dendent on the stack size if we arrive here, in (2) or | 49 // (1) It is dependent on the stack size if we arrive here, in (2) o
r |
46 // both. | 50 // both. |
47 gotWrongCatch1 = true; | 51 gotRegexCatch = true; |
48 } | 52 } |
49 | 53 |
50 try { | 54 try { |
51 funcWith20Args(1, 2, 3); | 55 funcWith20Args(1, 2, 3); |
52 } catch (err2) { | 56 } catch (err2) { |
53 gotRightCatch = true; | 57 stackOverflowIn20ArgFn = true; |
54 } | 58 } |
55 } | 59 } |
56 } | 60 } |
57 | 61 |
58 function test2() | 62 function mutual_recursion_2() |
59 { | 63 { |
60 try { | 64 try { |
61 var dummy = new Date(); | 65 var dummy = new Date(); |
62 } catch(err) { | 66 } catch(err) { |
63 // (2) It is dendent on the stack size if we arrive here, in (1) or | 67 // (2) It is dependent on the stack size if we arrive here, in (1) or |
64 // both. | 68 // both. |
65 gotWrongCatch2 = true; | 69 gotDateCatch = true; |
66 } | 70 } |
67 | 71 |
68 try { | 72 try { |
69 test1(); | 73 mutual_recursion_1(); |
70 } catch (err) { | 74 } catch (err) { |
71 // Should get here because of stack overflow, | 75 // Should get here because of stack overflow, |
72 // now cause a stack overflow exception due to arrity processing | 76 // now cause a stack overflow exception due to arity processing |
73 try { | 77 try { |
74 funcWith20Args(1, 2, 3, 4, 5, 6); | 78 funcWith20Args(1, 2, 3, 4, 5, 6); |
75 } catch (err2) { | 79 } catch (err2) { |
76 gotRightCatch = true; | 80 stackOverflowIn20ArgFn = true; |
77 } | 81 } |
78 } | 82 } |
79 } | 83 } |
80 | 84 |
81 test1(); | 85 mutual_recursion_1(); |
82 | 86 |
83 shouldBeTrue("gotRightCatch"); | 87 assertTrue(stackOverflowIn20ArgFn); |
OLD | NEW |